-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang-format] Fix Microsoft calling convensions preventing function names from being marked TT_StartOfName #143047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…g marked TT_StartOfName
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang-format Author: Ben Dunkin (bdunkin) ChangesThis fixes the Attribution Note - I have been authorized to contribute this change on behalf of my company: ArenaNet LLC Full diff: https://github.com/llvm/llvm-project/pull/143047.diff 3 Files Affected:
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 94014aee3221f..ef1c129b29b0c 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -114,6 +114,7 @@ namespace format {
TYPE(LineComment) \
TYPE(MacroBlockBegin) \
TYPE(MacroBlockEnd) \
+ TYPE(MicrosoftCallingConvention) \
TYPE(ModulePartitionColon) \
TYPE(NamespaceLBrace) \
TYPE(NamespaceMacro) \
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index da279d07b5918..4e23478058499 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1802,6 +1802,14 @@ class AnnotatingParser {
if (Style.isTableGen() && !parseTableGenValue())
return false;
break;
+ case tok::kw___cdecl:
+ case tok::kw___stdcall:
+ case tok::kw___fastcall:
+ case tok::kw___thiscall:
+ case tok::kw___regcall:
+ case tok::kw___vectorcall:
+ Tok->setType(TT_MicrosoftCallingConvention);
+ break;
default:
break;
}
@@ -2611,6 +2619,13 @@ class AnnotatingParser {
// Skip "const" as it does not have an influence on whether this is a name.
FormatToken *PreviousNotConst = Tok.getPreviousNonComment();
+ // Skip Microsoft calling conventions, as they come before the function
+ // name, but after the return type
+ while (PreviousNotConst &&
+ PreviousNotConst->is(TT_MicrosoftCallingConvention)) {
+ PreviousNotConst = PreviousNotConst->getPreviousNonComment();
+ }
+
// For javascript const can be like "let" or "var"
if (!Style.isJavaScript())
while (PreviousNotConst && PreviousNotConst->is(tok::kw_const))
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index c0633ba3c29b3..0f96b0f92cdb2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -17504,6 +17504,12 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
verifyFormat("A::A() : a(1) {}", SpaceFuncDecl);
verifyFormat("void f () __attribute__((asdf));", SpaceFuncDecl);
verifyFormat("void __attribute__((asdf)) f ();", SpaceFuncDecl);
+ verifyFormat("void __stdcall f ();", SpaceFuncDecl);
+ verifyFormat("void __cdecl f ();", SpaceFuncDecl);
+ verifyFormat("void __fastcall f ();", SpaceFuncDecl);
+ verifyFormat("void __stdcall f() {}", SpaceFuncDecl);
+ verifyFormat("void __cdecl f() {}", SpaceFuncDecl);
+ verifyFormat("void __fastcall f() {}", SpaceFuncDecl);
verifyFormat("#define A(x) x", SpaceFuncDecl);
verifyFormat("#define A (x) x", SpaceFuncDecl);
verifyFormat("#if defined(x)\n"
@@ -17540,6 +17546,12 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
verifyFormat("A::A () : a(1) {}", SpaceFuncDef);
verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
verifyFormat("void __attribute__((asdf)) f();", SpaceFuncDef);
+ verifyFormat("void __stdcall f();", SpaceFuncDef);
+ verifyFormat("void __cdecl f();", SpaceFuncDef);
+ verifyFormat("void __fastcall f();", SpaceFuncDef);
+ verifyFormat("void __stdcall f () {}", SpaceFuncDef);
+ verifyFormat("void __cdecl f () {}", SpaceFuncDef);
+ verifyFormat("void __fastcall f () {}", SpaceFuncDef);
verifyFormat("#define A(x) x", SpaceFuncDef);
verifyFormat("#define A (x) x", SpaceFuncDef);
verifyFormat("#if defined(x)\n"
|
|
|
|
See #143083, which annotates the above as: |
|
Ah ok, I understand how your change is a better fix. I will close this PR as yours also fixes things. I have some more fixes coming for this same option, so I will follow your lead on getting the token type of the opening parenthesis correct. |
This fixes the
SpaceBeforeParensOptions.AfterFunctionDeclarationNameandSpaceBeforeParensOptions.AfterFunctionDefinitionNameoptions not adding spaces when the function has an explicit Microsoft calling convention.Attribution Note - I have been authorized to contribute this change on behalf of my company: ArenaNet LLC