diff options
author | Krasimir Georgiev <krasimir@google.com> | 2018-11-13 15:38:12 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2018-11-13 15:38:12 +0000 |
commit | 28e2dbb14d49b8476516a1ba45f5dcda841a8765 (patch) | |
tree | 5e464fd0bcbe78da8a2534ca581cb1cd73b50686 /clang | |
parent | 077a42ca9f6980334a3a5d171c6176f560f48e26 (diff) | |
download | bcm5719-llvm-28e2dbb14d49b8476516a1ba45f5dcda841a8765.tar.gz bcm5719-llvm-28e2dbb14d49b8476516a1ba45f5dcda841a8765.zip |
[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
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index fe614300c22..705ee1582cf 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -404,8 +404,9 @@ private: Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) && !CurrentToken->isOneOf(tok::l_brace, tok::r_square) && (!Parent || - Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren, - tok::kw_return, tok::kw_throw) || + (Parent->is(tok::colon) && Parent->isNot(TT_InlineASMColon)) || + Parent->isOneOf(tok::l_square, tok::l_paren, tok::kw_return, + tok::kw_throw) || Parent->isUnaryOperator() || // FIXME(bug 36976): ObjC return types shouldn't use TT_CastRParen. Parent->isOneOf(TT_ObjCForIn, TT_CastRParen) || diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 2714a513bcb..1ac9dc7550a 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12755,6 +12755,21 @@ TEST_F(FormatTest, GuessLanguageWithCaret) { guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);")); } +TEST_F(FormatTest, GuessedLanguageWithInlineAsmClobbers) { + EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", + "void f() {\n" + " asm (\"mov %[e], %[d]\"\n" + " : [d] \"=rm\" (d)\n" + " [e] \"rm\" (*e));\n" + "}")); + EXPECT_EQ(FormatStyle::LK_Cpp, + guessLanguage("foo.h", "void f() {\n" + " asm volatile (\"mov %[e], %[d]\"\n" + " : [d] \"=rm\" (d)\n" + " [e] \"rm\" (*e));\n" + "}")); +} + TEST_F(FormatTest, GuessLanguageWithChildLines) { EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "#define FOO ({ std::string s; })")); |