Skip to content

Commit 28e2dbb

Browse files
committed
[clang-format] Do not treat the asm clobber [ as ObjCExpr
Summary: The opening square of an inline asm clobber was being annotated as an ObjCExpr. This caused, amongst other things, the ObjCGuesser to guess header files containing that pattern as ObjC files. Reviewers: benhamilton Reviewed By: benhamilton Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54111 llvm-svn: 346756
1 parent 077a42c commit 28e2dbb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,9 @@ class AnnotatingParser {
404404
Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
405405
!CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
406406
(!Parent ||
407-
Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
408-
tok::kw_return, tok::kw_throw) ||
407+
(Parent->is(tok::colon) && Parent->isNot(TT_InlineASMColon)) ||
408+
Parent->isOneOf(tok::l_square, tok::l_paren, tok::kw_return,
409+
tok::kw_throw) ||
409410
Parent->isUnaryOperator() ||
410411
// FIXME(bug 36976): ObjC return types shouldn't use TT_CastRParen.
411412
Parent->isOneOf(TT_ObjCForIn, TT_CastRParen) ||

clang/unittests/Format/FormatTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12755,6 +12755,21 @@ TEST_F(FormatTest, GuessLanguageWithCaret) {
1275512755
guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
1275612756
}
1275712757

12758+
TEST_F(FormatTest, GuessedLanguageWithInlineAsmClobbers) {
12759+
EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h",
12760+
"void f() {\n"
12761+
" asm (\"mov %[e], %[d]\"\n"
12762+
" : [d] \"=rm\" (d)\n"
12763+
" [e] \"rm\" (*e));\n"
12764+
"}"));
12765+
EXPECT_EQ(FormatStyle::LK_Cpp,
12766+
guessLanguage("foo.h", "void f() {\n"
12767+
" asm volatile (\"mov %[e], %[d]\"\n"
12768+
" : [d] \"=rm\" (d)\n"
12769+
" [e] \"rm\" (*e));\n"
12770+
"}"));
12771+
}
12772+
1275812773
TEST_F(FormatTest, GuessLanguageWithChildLines) {
1275912774
EXPECT_EQ(FormatStyle::LK_Cpp,
1276012775
guessLanguage("foo.h", "#define FOO ({ std::string s; })"));

0 commit comments

Comments
 (0)