]> granicus.if.org Git - clang/commitdiff
[clang-format] Do not treat asm clobber [ as ObjCExpr, refined
authorKrasimir Georgiev <krasimir@google.com>
Thu, 22 Nov 2018 14:49:55 +0000 (14:49 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Thu, 22 Nov 2018 14:49:55 +0000 (14:49 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index fbc7691af4520a52b15223bab57d8dcab81cbaa5..a04f2e672b45a64b9cbdce50c2ffc8cc07c62c56 100644 (file)
@@ -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) ||
index 1ac9dc7550ae6df4305f7912f38b3ee54a57307c..c05fceb4766c6cdbaec60f82a7690efc20b0dc12 100644 (file)
@@ -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"