Skip to content

Commit dbe9516

Browse files
committed
pre-commit: fix formatting for casts
The GNU predefined style is buggy for C-style casts (see llvm/llvm-project#20356). Adjust the corresponding parameter. Also run the pre-commit hook on C/C++ sources. Change-Id: I3615475ab16ae04afb1efc377420456166bd2090 TN: V916-015
1 parent c0f56d1 commit dbe9516

File tree

7 files changed

+130
-119
lines changed

7 files changed

+130
-119
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ repos:
55
- id: clang-format
66
types: [file]
77
files: \.(cc|c|h)$
8-
args: ["--style=gnu"]
8+
args: ["--style={BasedOnStyle: gnu, SpaceAfterCStyleCast: true}"]

tools/gnatcov/bfd_helpers.c

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@
2323
#include <bfd.h>
2424
#include <stdio.h>
2525

26-
#define CHECK(expr, call) do { if (!(expr)) { (*warn_cb)(call " failed", bfd_errmsg(bfd_get_error())); return; } } while (0)
26+
#define CHECK(expr, call) \
27+
do \
28+
{ \
29+
if (!(expr)) \
30+
{ \
31+
(*warn_cb) (call " failed", bfd_errmsg (bfd_get_error ())); \
32+
return; \
33+
} \
34+
} \
35+
while (0)
2736

2837
void
29-
_gnatcov_for_each_synthetic_symbol(char *fn, void (*cb)(const char *, long unsigned int), void (*warn_cb)(const char *, const char *))
38+
_gnatcov_for_each_synthetic_symbol (
39+
char *fn, void (*cb) (const char *, long unsigned int),
40+
void (*warn_cb) (const char *, const char *))
3041
{
3142
bfd *abfd;
3243
asymbol **dyn_syms = NULL, *synthsyms = NULL;
@@ -36,49 +47,54 @@ _gnatcov_for_each_synthetic_symbol(char *fn, void (*cb)(const char *, long unsig
3647
int j;
3748
symbol_info si;
3849

39-
abfd = bfd_openr(fn, "default");
40-
CHECK(abfd != NULL, "bfd_openr");
50+
abfd = bfd_openr (fn, "default");
51+
CHECK (abfd != NULL, "bfd_openr");
4152

42-
bfd_check_format(abfd, bfd_object);
53+
bfd_check_format (abfd, bfd_object);
4354

44-
storage = bfd_get_dynamic_symtab_upper_bound(abfd);
45-
CHECK(storage >= 0, "bfd_get_dynamic_symtab_upper_bound");
55+
storage = bfd_get_dynamic_symtab_upper_bound (abfd);
56+
CHECK (storage >= 0, "bfd_get_dynamic_symtab_upper_bound");
4657

4758
if (storage == 0)
4859
/* No dynamic symbols, nothing to do. */
4960
return;
5061

51-
dyn_syms = (asymbol **) bfd_alloc(abfd, storage);
52-
CHECK(dyn_syms != NULL, "bfd_alloc");
62+
dyn_syms = (asymbol **) bfd_alloc (abfd, storage);
63+
CHECK (dyn_syms != NULL, "bfd_alloc");
5364

54-
dyn_count = bfd_canonicalize_dynamic_symtab(abfd, dyn_syms);
65+
dyn_count = bfd_canonicalize_dynamic_symtab (abfd, dyn_syms);
5566
if (dyn_count <= 0)
5667
/* No dynamic symbols, nothing to do. */
5768
return;
5869

59-
synth_count = bfd_get_synthetic_symtab
60-
(abfd, /*static_count*/ 0, /*static_syms*/ NULL,
61-
dyn_count, dyn_syms, &synthsyms);
70+
synth_count = bfd_get_synthetic_symtab (abfd, /*static_count*/ 0,
71+
/*static_syms*/ NULL, dyn_count,
72+
dyn_syms, &synthsyms);
6273

6374
/* Note: synth_count is either -1 or >0, never 0. There is no way
6475
distinguish an error condition from the mere absence of synthetic
6576
symbols. */
6677

67-
for (j = 0; j < synth_count; j++) {
68-
bfd_symbol_info(&synthsyms[j], &si);
69-
(*cb) (si.name, si.value);
70-
}
78+
for (j = 0; j < synth_count; j++)
79+
{
80+
bfd_symbol_info (&synthsyms[j], &si);
81+
(*cb) (si.name, si.value);
82+
}
7183

72-
bfd_close(abfd);
84+
bfd_close (abfd);
7385
}
7486

7587
#ifdef BFD_HELPERS_TEST
76-
void print_cb(const char *name, unsigned long int val) {
77-
printf("%016lx %s\n", val, name);
88+
void
89+
print_cb (const char *name, unsigned long int val)
90+
{
91+
printf ("%016lx %s\n", val, name);
7892
}
7993

80-
int main(int argc, char **argv) {
81-
bfd_init();
82-
_gnatcov_for_each_synthetic_symbol(argv[1], print_cb);
94+
int
95+
main (int argc, char **argv)
96+
{
97+
bfd_init ();
98+
_gnatcov_for_each_synthetic_symbol (argv[1], print_cb);
8399
}
84100
#endif

tools/gnatcov/clang-wrapper.cc

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ clang_getBody (CXCursor C)
110110
switch (D->getKind ())
111111
{
112112
case Decl::FunctionTemplate:
113-
return MakeCXCursorWithNull (
114-
cast<FunctionTemplateDecl> (D)->getTemplatedDecl ()->getBody (),
115-
C);
113+
return MakeCXCursorWithNull (cast<FunctionTemplateDecl> (D)
114+
->getTemplatedDecl ()
115+
->getBody (),
116+
C);
116117
case Decl::Function:
117118
case Decl::CXXMethod:
118119
case Decl::CXXConstructor:
@@ -133,29 +134,29 @@ clang_getBody (CXCursor C)
133134
if (const Stmt *S = cxcursor::getCursorStmt (C))
134135
switch (S->getStmtClass ())
135136
{
136-
case Stmt::WhileStmtClass:
137-
return MakeCXCursorWithNull (cast<WhileStmt> (S)->getBody (), C);
138-
case Stmt::ForStmtClass:
139-
return MakeCXCursorWithNull (cast<ForStmt> (S)->getBody (), C);
140-
case Stmt::CXXForRangeStmtClass:
141-
return MakeCXCursorWithNull
142-
(cast<CXXForRangeStmt> (S)->getBody (), C);
143-
case Stmt::DoStmtClass:
144-
return MakeCXCursorWithNull (cast<DoStmt> (S)->getBody (), C);
145-
case Stmt::SwitchStmtClass:
146-
return MakeCXCursorWithNull (cast<SwitchStmt> (S)->getBody (), C);
147-
default:
148-
return clang_getNullCursor ();
137+
case Stmt::WhileStmtClass:
138+
return MakeCXCursorWithNull (cast<WhileStmt> (S)->getBody (), C);
139+
case Stmt::ForStmtClass:
140+
return MakeCXCursorWithNull (cast<ForStmt> (S)->getBody (), C);
141+
case Stmt::CXXForRangeStmtClass:
142+
return MakeCXCursorWithNull (cast<CXXForRangeStmt> (S)->getBody (),
143+
C);
144+
case Stmt::DoStmtClass:
145+
return MakeCXCursorWithNull (cast<DoStmt> (S)->getBody (), C);
146+
case Stmt::SwitchStmtClass:
147+
return MakeCXCursorWithNull (cast<SwitchStmt> (S)->getBody (), C);
148+
default:
149+
return clang_getNullCursor ();
149150
}
150151
}
151152
else if (clang_isExpression (C.kind))
152153
if (const Expr *E = cxcursor::getCursorExpr (C))
153154
switch (E->getStmtClass ())
154155
{
155-
case Expr::LambdaExprClass:
156-
return MakeCXCursorWithNull (cast<LambdaExpr> (E)->getBody (), C);
157-
default:
158-
return clang_getNullCursor ();
156+
case Expr::LambdaExprClass:
157+
return MakeCXCursorWithNull (cast<LambdaExpr> (E)->getBody (), C);
158+
default:
159+
return clang_getNullCursor ();
159160
}
160161
return clang_getNullCursor ();
161162
}
@@ -184,8 +185,7 @@ clang_getForRangeExpr (CXCursor C)
184185
const Stmt *stmt;
185186
const CXXForRangeStmt *for_stmt;
186187

187-
if (clang_isStatement (C.kind)
188-
&& (stmt = cxcursor::getCursorStmt (C))
188+
if (clang_isStatement (C.kind) && (stmt = cxcursor::getCursorStmt (C))
189189
&& stmt->getStmtClass () == Stmt::CXXForRangeStmtClass)
190190
{
191191
for_stmt = cast<CXXForRangeStmt> (stmt);
@@ -216,8 +216,7 @@ clang_getCondVar (CXCursor C)
216216
const WhileStmt *while_stmt;
217217
const VarDecl *decl;
218218

219-
if (clang_isStatement (C.kind)
220-
&& (stmt = cxcursor::getCursorStmt (C))
219+
if (clang_isStatement (C.kind) && (stmt = cxcursor::getCursorStmt (C))
221220
&& stmt->getStmtClass () == Stmt::WhileStmtClass)
222221
{
223222
while_stmt = cast<WhileStmt> (stmt);
@@ -233,8 +232,7 @@ clang_getVarInitExpr (CXCursor C)
233232
const Decl *decl;
234233
const VarDecl *var_decl;
235234

236-
if (clang_isDeclaration (C.kind)
237-
&& (decl = cxcursor::getCursorDecl (C))
235+
if (clang_isDeclaration (C.kind) && (decl = cxcursor::getCursorDecl (C))
238236
&& decl->getKind () == Decl::Kind::Var)
239237
{
240238
var_decl = cast<VarDecl> (decl);
@@ -401,24 +399,23 @@ clang_unwrap (CXCursor C)
401399
if (const Stmt *S = cxcursor::getCursorStmt (C))
402400
switch (S->getStmtClass ())
403401
{
404-
case Stmt::ParenExprClass:
405-
return clang_unwrap
406-
(MakeCXCursorWithNull (cast<ParenExpr> (S)->getSubExpr (), C));
407-
case Expr::ConstantExprClass:
408-
case Expr::ExprWithCleanupsClass:
409-
return clang_unwrap
410-
(MakeCXCursorWithNull (cast<FullExpr> (S)->getSubExpr (), C));
411-
case Expr::ImplicitCastExprClass:
412-
case Expr::CStyleCastExprClass:
413-
case Expr::CXXFunctionalCastExprClass:
414-
case Expr::CXXStaticCastExprClass:
415-
case Expr::CXXDynamicCastExprClass:
416-
case Expr::CXXReinterpretCastExprClass:
417-
case Expr::CXXConstCastExprClass:
418-
case Expr::CXXAddrspaceCastExprClass:
419-
return clang_unwrap
420-
(MakeCXCursorWithNull (cast<CastExpr> (S)->getSubExpr (), C));
421-
402+
case Stmt::ParenExprClass:
403+
return clang_unwrap (
404+
MakeCXCursorWithNull (cast<ParenExpr> (S)->getSubExpr (), C));
405+
case Expr::ConstantExprClass:
406+
case Expr::ExprWithCleanupsClass:
407+
return clang_unwrap (
408+
MakeCXCursorWithNull (cast<FullExpr> (S)->getSubExpr (), C));
409+
case Expr::ImplicitCastExprClass:
410+
case Expr::CStyleCastExprClass:
411+
case Expr::CXXFunctionalCastExprClass:
412+
case Expr::CXXStaticCastExprClass:
413+
case Expr::CXXDynamicCastExprClass:
414+
case Expr::CXXReinterpretCastExprClass:
415+
case Expr::CXXConstCastExprClass:
416+
case Expr::CXXAddrspaceCastExprClass:
417+
return clang_unwrap (
418+
MakeCXCursorWithNull (cast<CastExpr> (S)->getSubExpr (), C));
422419
}
423420
return C;
424421
}
@@ -480,13 +477,14 @@ clang_CXRewriter_insertTextAfterToken (CXRewriter Rew, CXSourceLocation Loc,
480477
extern "C" unsigned
481478
clang_isMacroLocation (CXSourceLocation Loc)
482479
{
483-
const clang::SourceLocation SLoc =
484-
clang::cxloc::translateSourceLocation (Loc);
480+
const clang::SourceLocation SLoc
481+
= clang::cxloc::translateSourceLocation (Loc);
485482
return SLoc.isMacroID () ? 1 : 0;
486483
}
487484

488485
extern "C" unsigned
489-
clang_isMacroArgExpansion (CXSourceLocation Loc, CXSourceLocation *StartLoc, CXTranslationUnit TU)
486+
clang_isMacroArgExpansion (CXSourceLocation Loc, CXSourceLocation *StartLoc,
487+
CXTranslationUnit TU)
490488
{
491489
const SourceManager &SM = cxtu::getASTUnit (TU)->getSourceManager ();
492490
const SourceLocation SLoc = translateSourceLocation (Loc);
@@ -509,8 +507,8 @@ clang_getImmediateMacroCallerLoc (CXSourceLocation Loc, CXTranslationUnit TU)
509507
ASTContext &astContext = astUnit->getASTContext ();
510508
SourceLocation SLoc = translateSourceLocation (Loc);
511509
if (SLoc.isMacroID ())
512-
return cxloc::translateSourceLocation
513-
(astContext, SM.getImmediateMacroCallerLoc (SLoc));
510+
return cxloc::translateSourceLocation (
511+
astContext, SM.getImmediateMacroCallerLoc (SLoc));
514512
return Loc;
515513
}
516514

@@ -521,20 +519,20 @@ clang_getImmediateExpansionLoc (CXSourceLocation Loc, CXTranslationUnit TU)
521519
ASTUnit *astUnit = cxtu::getASTUnit (TU);
522520
ASTContext &astContext = astUnit->getASTContext ();
523521
SourceLocation SLoc = translateSourceLocation (Loc);
524-
return cxloc::translateSourceLocation
525-
(astContext, SM.getImmediateExpansionRange (SLoc).getBegin ());
522+
return cxloc::translateSourceLocation (
523+
astContext, SM.getImmediateExpansionRange (SLoc).getBegin ());
526524
}
527525

528526
extern "C" CXString
529-
clang_getImmediateMacroNameForDiagnostics (CXSourceLocation Loc, CXTranslationUnit TU)
527+
clang_getImmediateMacroNameForDiagnostics (CXSourceLocation Loc,
528+
CXTranslationUnit TU)
530529
{
531530
SourceLocation SLoc = translateSourceLocation (Loc);
532531
SourceManager &SM = cxtu::getASTUnit (TU)->getSourceManager ();
533532
ASTUnit *astUnit = cxtu::getASTUnit (TU);
534533
ASTContext &astContext = astUnit->getASTContext ();
535-
return createDup
536-
(Lexer::getImmediateMacroNameForDiagnostics
537-
(SLoc, SM, astContext.getLangOpts ()));
534+
return createDup (Lexer::getImmediateMacroNameForDiagnostics (
535+
SLoc, SM, astContext.getLangOpts ()));
538536
}
539537

540538
extern "C" CXSourceLocation
@@ -544,8 +542,8 @@ clang_getExpansionEnd (CXTranslationUnit TU, CXSourceLocation Loc)
544542
SourceManager &SM = cxtu::getASTUnit (TU)->getSourceManager ();
545543
ASTUnit *astUnit = cxtu::getASTUnit (TU);
546544
ASTContext &astContext = astUnit->getASTContext ();
547-
return cxloc::translateSourceLocation
548-
(astContext, SM.getExpansionRange (SLoc).getEnd ());
545+
return cxloc::translateSourceLocation (
546+
astContext, SM.getExpansionRange (SLoc).getEnd ());
549547
}
550548

551549
extern "C" CXTranslationUnit
@@ -557,6 +555,6 @@ clang_getCursorTU (CXCursor C)
557555
extern "C" void
558556
clang_printLocation (CXTranslationUnit TU, CXSourceLocation Loc)
559557
{
560-
const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
561-
clang::cxloc::translateSourceLocation (Loc).dump(SM);
558+
const SourceManager &SM = cxtu::getASTUnit (TU)->getSourceManager ();
559+
clang::cxloc::translateSourceLocation (Loc).dump (SM);
562560
}

tools/gnatcov/libopcodes_bind/dis_stream.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
* *
1818
****************************************************************************/
1919

20-
#include <stdio.h>
2120
#include <stdarg.h>
21+
#include <stdio.h>
2222
#include <stdlib.h>
2323

2424
#include "dis_stream.h"
2525

2626
struct disassembler_stream
2727
{
28-
char *buff;
29-
unsigned int size;
30-
unsigned int idx;
28+
char *buff;
29+
unsigned int size;
30+
unsigned int idx;
3131
};
3232

3333
/* Printf-like function to add content to the DS stream according to FORMAT.
@@ -53,7 +53,7 @@ stream_printf (disassembler_stream *ds, const char *format, ...)
5353
int res;
5454

5555
va_start (ap, format);
56-
res = common_printf(ds, format, ap);
56+
res = common_printf (ds, format, ap);
5757
va_end (ap);
5858

5959
return res;
@@ -63,14 +63,14 @@ stream_printf (disassembler_stream *ds, const char *format, ...)
6363
desired. */
6464
int
6565
stream_styled_printf (disassembler_stream *ds,
66-
enum disassembler_style style ATTRIBUTE_UNUSED,
67-
const char *format, ...)
66+
enum disassembler_style style ATTRIBUTE_UNUSED,
67+
const char *format, ...)
6868
{
6969
va_list ap;
7070
int res;
7171

7272
va_start (ap, format);
73-
res = common_printf(ds, format, ap);
73+
res = common_printf (ds, format, ap);
7474
va_end (ap);
7575

7676
return res;

tools/gnatcov/libopcodes_bind/dis_stream.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* *
1818
****************************************************************************/
1919

20-
2120
#ifndef DIS_STREAM_H_
2221
#define DIS_STREAM_H_
2322

@@ -38,8 +37,8 @@ extern void delete_stream (disassembler_stream *const ds);
3837
extern int stream_printf (disassembler_stream *ptr, const char *format, ...);
3938

4039
extern int stream_styled_printf (disassembler_stream *ptr,
41-
enum disassembler_style style,
42-
const char *format, ...);
40+
enum disassembler_style style,
41+
const char *format, ...);
4342

4443
extern void clear_stream (disassembler_stream *const ds);
4544

0 commit comments

Comments
 (0)