]> granicus.if.org Git - clang/commitdiff
clang-format: Fix formatting of inline asm.
authorDaniel Jasper <djasper@google.com>
Mon, 12 Jan 2015 10:14:56 +0000 (10:14 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 12 Jan 2015 10:14:56 +0000 (10:14 +0000)
Specifically, adjust the leading "__asm {" and trailing "}" while still
leaving the assembly inside it alone.

This fixes llvm.org/PR22190.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225623 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 02d49a0e1e25ea20df6dafdb44924a4417fb2b3d..01c8acf0e662e02182c20b3fd8e7a410ba6ba90f 100644 (file)
@@ -660,15 +660,15 @@ void UnwrappedLineParser::parseStructuralElement() {
     }
     break;
   case tok::kw_asm:
-    FormatTok->Finalized = true;
     nextToken();
     if (FormatTok->is(tok::l_brace)) {
+      nextToken();
       while (FormatTok && FormatTok->isNot(tok::eof)) {
-        FormatTok->Finalized = true;
         if (FormatTok->is(tok::r_brace)) {
           nextToken();
           break;
         }
+        FormatTok->Finalized = true;
         nextToken();
       }
     }
index 3b3f5fb74cab6d72d890d79a2b76d9163d0504ff..a49a35c1defb2cf5bee129e42b889ba7427115e4 100644 (file)
@@ -2191,11 +2191,11 @@ TEST_F(FormatTest, FormatsInlineASM) {
       "    : \"a\"(value));");
   EXPECT_EQ(
       "void NS_InvokeByIndex(void *that, unsigned int methodIndex) {\n"
-      "    __asm {\n"
+      "  __asm {\n"
       "        mov     edx,[that] // vtable in edx\n"
       "        mov     eax,methodIndex\n"
       "        call    [edx][eax*4] // stdcall\n"
-      "    }\n"
+      "  }\n"
       "}",
       format("void NS_InvokeByIndex(void *that,   unsigned int methodIndex) {\n"
              "    __asm {\n"
@@ -2204,6 +2204,10 @@ TEST_F(FormatTest, FormatsInlineASM) {
              "        call    [edx][eax*4] // stdcall\n"
              "    }\n"
              "}"));
+  verifyFormat("void function() {\n"
+               "  // comment\n"
+               "  asm(\"\");\n"
+               "}");
 }
 
 TEST_F(FormatTest, FormatTryCatch) {