]> granicus.if.org Git - clang/commitdiff
clang-format: Don't butcher __asm blocks.
authorDaniel Jasper <djasper@google.com>
Tue, 26 Aug 2014 23:15:12 +0000 (23:15 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 26 Aug 2014 23:15:12 +0000 (23:15 +0000)
Instead completely cop out of formatting them for now.

This fixes llvm.org/PR20618.

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

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

index 7e55e04c7f78eb44c7f09cde5ee36e89aee3f8ef..aad3faa1965bc2b1b0d0c1d8bbdd0887e202713f 100644 (file)
@@ -658,6 +658,21 @@ void UnwrappedLineParser::parseStructuralElement() {
       break;
     }
     break;
+  case tok::kw_asm:
+    FormatTok->Finalized = true;
+    nextToken();
+    if (FormatTok->is(tok::l_brace)) {
+      FormatTok->Finalized = true;
+      while (FormatTok) {
+        FormatTok->Finalized = true;
+        if (FormatTok->is(tok::r_brace)) {
+          nextToken();
+          break;
+        }
+        nextToken();
+      }
+    }
+    break;
   case tok::kw_namespace:
     parseNamespace();
     return;
index 411282a69da9563662de577c3012f172f73ccb82..bf69d8b55ed62ba1dd4de0aaa9c179124df7b8e5 100644 (file)
@@ -2070,6 +2070,21 @@ TEST_F(FormatTest, FormatsInlineASM) {
       "    \"xchgq\\t%%rbx, %%rsi\\n\\t\"\n"
       "    : \"=a\"(*rEAX), \"=S\"(*rEBX), \"=c\"(*rECX), \"=d\"(*rEDX)\n"
       "    : \"a\"(value));");
+  EXPECT_EQ(
+      "void NS_InvokeByIndex(void *that, unsigned int methodIndex) {\n"
+      "    __asm {\n"
+      "        mov     edx,[that] // vtable in edx\n"
+      "        mov     eax,methodIndex\n"
+      "        call    [edx][eax*4] // stdcall\n"
+      "    }\n"
+      "}",
+      format("void NS_InvokeByIndex(void *that,   unsigned int methodIndex) {\n"
+             "    __asm {\n"
+             "        mov     edx,[that] // vtable in edx\n"
+             "        mov     eax,methodIndex\n"
+             "        call    [edx][eax*4] // stdcall\n"
+             "    }\n"
+             "}"));
 }
 
 TEST_F(FormatTest, FormatTryCatch) {