From: Krasimir Georgiev Date: Thu, 22 Nov 2018 14:49:55 +0000 (+0000) Subject: [clang-format] Do not treat asm clobber [ as ObjCExpr, refined X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33b30eb6d622918dcdc0425730a712f0460db522;p=clang [clang-format] Do not treat asm clobber [ as ObjCExpr, refined Summary: r346756 refined clang-format to not treat the `[` in `asm (...: [] ..)` as an ObjCExpr. However that's not enough, as we might have a comma-separated list of such clobbers as in the newly added test. This updates the detection to instead look at the Line's first token being `asm` and not mark `[`-s as ObjCExprs in this case. Reviewers: djasper, benhamilton Reviewed By: djasper, benhamilton Subscribers: benhamilton, cfe-commits Differential Revision: https://reviews.llvm.org/D54795 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347465 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index fbc7691af4..a04f2e672b 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -399,14 +399,15 @@ private: bool IsCpp11AttributeSpecifier = isCpp11AttributeSpecifier(*Left) || Contexts.back().InCpp11AttributeSpecifier; + bool InsideInlineASM = Line.startsWith(tok::kw_asm); bool StartsObjCMethodExpr = - !CppArrayTemplates && Style.isCpp() && !IsCpp11AttributeSpecifier && - Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) && + !InsideInlineASM && !CppArrayTemplates && Style.isCpp() && + !IsCpp11AttributeSpecifier && Contexts.back().CanBeExpression && + Left->isNot(TT_LambdaLSquare) && !CurrentToken->isOneOf(tok::l_brace, tok::r_square) && (!Parent || - (Parent->is(tok::colon) && Parent->isNot(TT_InlineASMColon)) || - Parent->isOneOf(tok::l_square, tok::l_paren, tok::kw_return, - tok::kw_throw) || + Parent->isOneOf(tok::colon, 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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1ac9dc7550..c05fceb476 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -12762,6 +12762,30 @@ TEST_F(FormatTest, GuessedLanguageWithInlineAsmClobbers) { " : [d] \"=rm\" (d)\n" " [e] \"rm\" (*e));\n" "}")); + 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 (\"mov %[e], %[d]\"\n" + " : [d] \"=rm\" (d)\n" + " [e] \"rm\" (*e));\n" + "}")); + 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 (\"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"