[PATCH] D18652: [Inline asm] Correctly parse GCC-style asm line following MS-style asm line

Denis Zobnin via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 31 09:15:58 PDT 2016


d.zobnin.bugzilla created this revision.
d.zobnin.bugzilla added a reviewer: echristo.
d.zobnin.bugzilla added a subscriber: cfe-commits.

Clang fails to compile the following code:

void f() {
  __asm mov ebx, ecx
  __asm__("movl %ecx, %edx");
}

reporting unexpected token "__asm__" at start of statement.
Quit parsing MS-style assembly if the following statement has GCC style to handle such code.

http://reviews.llvm.org/D18652

Files:
  lib/Parse/ParseStmtAsm.cpp
  test/CodeGen/inline-asm-mixed-style.c

Index: lib/Parse/ParseStmtAsm.cpp
===================================================================
--- lib/Parse/ParseStmtAsm.cpp
+++ lib/Parse/ParseStmtAsm.cpp
@@ -417,9 +417,10 @@
         // If this is a single-line __asm, we're done, except if the next
         // line begins with an __asm too, in which case we finish a comment
         // if needed and then keep processing the next line as a single
-        // line __asm.
+        // line __asm. Also break if the next __asm is followed by an '(' -
+        // GCC-style asm.
         bool isAsm = Tok.is(tok::kw_asm);
-        if (SingleLineMode && !isAsm)
+        if (SingleLineMode && (!isAsm || NextToken().is(tok::l_paren)))
           break;
         // We're no longer in a comment.
         InAsmComment = false;
Index: test/CodeGen/inline-asm-mixed-style.c
===================================================================
--- test/CodeGen/inline-asm-mixed-style.c
+++ test/CodeGen/inline-asm-mixed-style.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fasm-blocks -fsyntax-only -verify %s
+// expected-no-diagnostics
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fasm-blocks -emit-llvm -S %s -o - | FileCheck %s
+
+void f() {
+  __asm mov eax, ebx
+  __asm mov ebx, ecx
+  __asm__("movl %ecx, %edx");
+
+  // CHECK: movl    %ebx, %eax
+  // CHECK: movl    %ecx, %ebx
+  // CHECK: movl    %ecx, %edx
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18652.52222.patch
Type: text/x-patch
Size: 1402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160331/4aa0750f/attachment.bin>


More information about the cfe-commits mailing list