Skip to content

Commit 7c3f0f8

Browse files
committed
Fix Microsoft calling convensions preventing function names from being marked TT_StartOfName
1 parent 49386f4 commit 7c3f0f8

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

clang/lib/Format/FormatToken.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ namespace format {
114114
TYPE(LineComment) \
115115
TYPE(MacroBlockBegin) \
116116
TYPE(MacroBlockEnd) \
117+
TYPE(MicrosoftCallingConvention) \
117118
TYPE(ModulePartitionColon) \
118119
TYPE(NamespaceLBrace) \
119120
TYPE(NamespaceMacro) \

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,14 @@ class AnnotatingParser {
18021802
if (Style.isTableGen() && !parseTableGenValue())
18031803
return false;
18041804
break;
1805+
case tok::kw___cdecl:
1806+
case tok::kw___stdcall:
1807+
case tok::kw___fastcall:
1808+
case tok::kw___thiscall:
1809+
case tok::kw___regcall:
1810+
case tok::kw___vectorcall:
1811+
Tok->setType(TT_MicrosoftCallingConvention);
1812+
break;
18051813
default:
18061814
break;
18071815
}
@@ -2611,6 +2619,13 @@ class AnnotatingParser {
26112619
// Skip "const" as it does not have an influence on whether this is a name.
26122620
FormatToken *PreviousNotConst = Tok.getPreviousNonComment();
26132621

2622+
// Skip Microsoft calling conventions, as they come before the function
2623+
// name, but after the return type
2624+
while (PreviousNotConst &&
2625+
PreviousNotConst->is(TT_MicrosoftCallingConvention)) {
2626+
PreviousNotConst = PreviousNotConst->getPreviousNonComment();
2627+
}
2628+
26142629
// For javascript const can be like "let" or "var"
26152630
if (!Style.isJavaScript())
26162631
while (PreviousNotConst && PreviousNotConst->is(tok::kw_const))

clang/unittests/Format/FormatTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17504,6 +17504,12 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
1750417504
verifyFormat("A::A() : a(1) {}", SpaceFuncDecl);
1750517505
verifyFormat("void f () __attribute__((asdf));", SpaceFuncDecl);
1750617506
verifyFormat("void __attribute__((asdf)) f ();", SpaceFuncDecl);
17507+
verifyFormat("void __stdcall f ();", SpaceFuncDecl);
17508+
verifyFormat("void __cdecl f ();", SpaceFuncDecl);
17509+
verifyFormat("void __fastcall f ();", SpaceFuncDecl);
17510+
verifyFormat("void __stdcall f() {}", SpaceFuncDecl);
17511+
verifyFormat("void __cdecl f() {}", SpaceFuncDecl);
17512+
verifyFormat("void __fastcall f() {}", SpaceFuncDecl);
1750717513
verifyFormat("#define A(x) x", SpaceFuncDecl);
1750817514
verifyFormat("#define A (x) x", SpaceFuncDecl);
1750917515
verifyFormat("#if defined(x)\n"
@@ -17540,6 +17546,12 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
1754017546
verifyFormat("A::A () : a(1) {}", SpaceFuncDef);
1754117547
verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
1754217548
verifyFormat("void __attribute__((asdf)) f();", SpaceFuncDef);
17549+
verifyFormat("void __stdcall f();", SpaceFuncDef);
17550+
verifyFormat("void __cdecl f();", SpaceFuncDef);
17551+
verifyFormat("void __fastcall f();", SpaceFuncDef);
17552+
verifyFormat("void __stdcall f () {}", SpaceFuncDef);
17553+
verifyFormat("void __cdecl f () {}", SpaceFuncDef);
17554+
verifyFormat("void __fastcall f () {}", SpaceFuncDef);
1754317555
verifyFormat("#define A(x) x", SpaceFuncDef);
1754417556
verifyFormat("#define A (x) x", SpaceFuncDef);
1754517557
verifyFormat("#if defined(x)\n"

0 commit comments

Comments
 (0)