Skip to content

Conversation

@owenca
Copy link
Contributor

@owenca owenca commented Jun 6, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2025

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/143083.diff

2 Files Affected:

  • (modified) clang/lib/Format/TokenAnnotator.cpp (+9-1)
  • (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 37ab40ca97bff..aed1672afac66 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1769,7 +1769,15 @@ class AnnotatingParser {
                        Keywords.kw___has_include_next)) {
         parseHasInclude();
       }
-      if (Style.isCSharp()) {
+      if (IsCpp) {
+        if (Next && Next->is(tok::l_paren) && Prev &&
+            Prev->isOneOf(tok::kw___cdecl, tok::kw___stdcall,
+                          tok::kw___fastcall, tok::kw___thiscall,
+                          tok::kw___regcall, tok::kw___vectorcall)) {
+          Tok->setFinalizedType(TT_FunctionDeclarationName);
+          Next->setFinalizedType(TT_FunctionDeclarationLParen);
+        }
+      } else if (Style.isCSharp()) {
         if (Tok->is(Keywords.kw_where) && Next && Next->isNot(tok::l_paren)) {
           Tok->setType(TT_CSharpGenericTypeConstraint);
           parseCSharpGenericTypeConstraint();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 9d62ff8d39a77..d64e34de1fcf4 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2273,6 +2273,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
   EXPECT_TOKEN(Tokens[16], tok::l_paren, TT_FunctionDeclarationLParen);
   EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow);
 
+  Tokens = annotate("void __stdcall f();");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_FunctionDeclarationLParen);
+
   Tokens = annotate("int iso_time(time_t);");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);

@owenca owenca merged commit 0c495ce into llvm:main Jun 7, 2025
9 checks passed
@owenca owenca deleted the ms-calling-conventions branch June 7, 2025 03:43
@llvm llvm deleted a comment from llvm-ci Jun 7, 2025
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants