[cfe-commits] r161986 - in /cfe/trunk: lib/Parse/ParseStmt.cpp lib/Sema/SemaStmt.cpp test/CodeGen/ms-inline-asm.c test/Parser/ms-inline-asm.c
Chad Rosier
mcrosier at apple.com
Wed Aug 15 14:03:27 PDT 2012
Author: mcrosier
Date: Wed Aug 15 16:03:27 2012
New Revision: 161986
URL: http://llvm.org/viewvc/llvm-project?rev=161986&view=rev
Log:
[ms-inline asm] MSVC parses multiple __asm statements on a single line as one
statement. For example,
if (x)
__asm out dx, ax __asm out dx, ax
results in a single inline asm statement (i.e., both "out dx, ax" statements are
predicated on if(x)).
Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/CodeGen/ms-inline-asm.c
cfe/trunk/test/Parser/ms-inline-asm.c
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=161986&r1=161985&r2=161986&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Wed Aug 15 16:03:27 2012
@@ -1686,11 +1686,6 @@
if (Tok.is(tok::eof))
break;
- // The asm keyword is a statement separator, so multiple asm statements
- // are allowed on a single line.
- if (!InAsmComment && Tok.is(tok::kw_asm))
- break;
-
if (!InAsmComment && Tok.is(tok::semi)) {
// A semicolon in an asm is the start of a comment.
InAsmComment = true;
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=161986&r1=161985&r2=161986&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Aug 15 16:03:27 2012
@@ -2777,12 +2777,21 @@
unsigned NumAsmStrings = 0;
for (unsigned i = 0, e = AsmToks.size(); i != e; ++i) {
+ // Determine if this should be considered a new asm.
+ bool isNewAsm = i == 0 || AsmToks[i].isAtStartOfLine() ||
+ AsmToks[i].is(tok::kw_asm);
+
// Emit the previous asm string.
- if (i && AsmToks[i].isAtStartOfLine())
+ if (i && isNewAsm) {
AsmStrings[NumAsmStrings++] = Asm.c_str();
+ if (AsmToks[i].is(tok::kw_asm)) {
+ ++i; // Skip __asm
+ assert (i != e && "Expected another token.");
+ }
+ }
// Start a new asm string with the opcode.
- if (i == 0 || AsmToks[i].isAtStartOfLine()) {
+ if (isNewAsm) {
Asm = AsmToks[i].getIdentifierInfo()->getName().str();
continue;
}
@@ -2831,17 +2840,29 @@
// Build the unmodified MSAsmString.
static std::string buildMSAsmString(Sema &SemaRef,
- ArrayRef<Token> AsmToks) {
+ ArrayRef<Token> AsmToks) {
assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
SmallString<512> Asm;
SmallString<512> TokenBuf;
TokenBuf.resize(512);
+
for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) {
- bool StringInvalid = false;
- if (i && AsmToks[i].isAtStartOfLine())
- Asm += '\n';
- else if (i && AsmToks[i].hasLeadingSpace())
+ bool isNewAsm = i == 0 || AsmToks[i].isAtStartOfLine() ||
+ AsmToks[i].is(tok::kw_asm);
+
+ if (isNewAsm) {
+ if (i)
+ Asm += '\n';
+ if (AsmToks[i].is(tok::kw_asm)) {
+ i++; // Skip __asm
+ assert (i != e && "Expected another token");
+ }
+ }
+
+ if (i && AsmToks[i].hasLeadingSpace() && !isNewAsm)
Asm += ' ';
+
+ bool StringInvalid = false;
Asm += SemaRef.PP.getSpelling(AsmToks[i], TokenBuf, &StringInvalid);
assert (!StringInvalid && "Expected valid string!");
}
@@ -2876,7 +2897,7 @@
// FIXME: Count this while parsing.
unsigned NumAsmStrings = 0;
for (unsigned i = 0, e = AsmToks.size(); i != e; ++i)
- if (AsmToks[i].isAtStartOfLine())
+ if (i == 0 || AsmToks[i].isAtStartOfLine() || AsmToks[i].is(tok::kw_asm))
++NumAsmStrings;
PatchedAsmStrings.resize(NumAsmStrings ? NumAsmStrings : 1);
Modified: cfe/trunk/test/CodeGen/ms-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm.c?rev=161986&r1=161985&r2=161986&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ms-inline-asm.c (original)
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c Wed Aug 15 16:03:27 2012
@@ -20,9 +20,7 @@
void t3() {
// CHECK: @t3
-// CHECK: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
-// CHECK: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
-// CHECK: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
+// CHECK: call void asm sideeffect "nop\0Anop\0Anop", "~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
// CHECK: ret void
__asm nop __asm nop __asm nop
}
@@ -38,8 +36,7 @@
void t5(void) {
// CHECK: @t5
-// CHECK: call void asm sideeffect "mov ebx, eax", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
-// CHECK: call void asm sideeffect "mov ecx, ebx", "~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
+// CHECK: call void asm sideeffect "mov ebx, eax\0Amov ecx, ebx", "~{ebx},~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind ia_nsdialect
// CHECK: ret void
__asm mov ebx, eax __asm mov ecx, ebx
}
Modified: cfe/trunk/test/Parser/ms-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/ms-inline-asm.c?rev=161986&r1=161985&r2=161986&view=diff
==============================================================================
--- cfe/trunk/test/Parser/ms-inline-asm.c (original)
+++ cfe/trunk/test/Parser/ms-inline-asm.c Wed Aug 15 16:03:27 2012
@@ -28,10 +28,10 @@
}
}
void t8() {
- __asm nop __asm nop __asm nop // expected-warning {{MS-style inline assembly is not supported}} expected-warning {{MS-style inline assembly is not supported}} expected-warning {{MS-style inline assembly is not supported}}
+ __asm nop __asm nop __asm nop // expected-warning {{MS-style inline assembly is not supported}}
}
void t9() {
- __asm nop __asm nop ; __asm nop // expected-warning {{MS-style inline assembly is not supported}} expected-warning {{MS-style inline assembly is not supported}}
+ __asm nop __asm nop ; __asm nop // expected-warning {{MS-style inline assembly is not supported}}
}
int t_fail() { // expected-note {{to match this}}
__asm
More information about the cfe-commits
mailing list