[clang] 0c495ce - [clang-format] Handle function decls with MS calling conventions (#143083)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 6 20:43:40 PDT 2025
Author: Owen Pan
Date: 2025-06-06T20:43:35-07:00
New Revision: 0c495ce9c4237f0f090b672efd94839e52cb5f18
URL: https://github.com/llvm/llvm-project/commit/0c495ce9c4237f0f090b672efd94839e52cb5f18
DIFF: https://github.com/llvm/llvm-project/commit/0c495ce9c4237f0f090b672efd94839e52cb5f18.diff
LOG: [clang-format] Handle function decls with MS calling conventions (#143083)
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
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);
More information about the cfe-commits
mailing list