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
+}
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
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits