]> granicus.if.org Git - clang/commitdiff
Support fuzzy parsing MS line-oriented __asm's that originate from a macro (a case...
authorSteve Naroff <snaroff@apple.com>
Fri, 8 Feb 2008 03:36:19 +0000 (03:36 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 8 Feb 2008 03:36:19 +0000 (03:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46878 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseStmt.cpp
test/Sema/ms-fuzzy-asm.c [new file with mode: 0644]

index 7da47e84f2b771289291686adbdf9d5c78fff89d..4be3f1e40a9b1f4020dabaf8f337fee84cae4609 100644 (file)
@@ -921,11 +921,22 @@ Parser::StmtResult Parser::FuzzyParseMicrosoftAsmStatement() {
     // From the MS website: If used without braces, the __asm keyword means
     // that the rest of the line is an assembly-language statement.
     SourceManager &SrcMgr = PP.getSourceManager();
-    unsigned lineNo = SrcMgr.getLineNumber(Tok.getLocation());
-    do {
-      ConsumeAnyToken();
-    } while ((SrcMgr.getLineNumber(Tok.getLocation()) == lineNo) && 
-             Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof));
+    SourceLocation TokLoc = Tok.getLocation();
+    if (TokLoc.isFileID()) {
+      unsigned lineNo = SrcMgr.getLineNumber(TokLoc);
+      do {
+        ConsumeAnyToken();
+        TokLoc = Tok.getLocation();
+      } while (TokLoc.isFileID() && (SrcMgr.getLineNumber(TokLoc) == lineNo) && 
+               Tok.isNot(tok::r_brace) && Tok.isNot(tok::semi) && 
+               Tok.isNot(tok::eof));
+    } else { // The asm tokens come from a macro expansion.
+      do {
+        ConsumeAnyToken();
+        TokLoc = Tok.getLocation();
+      } while (TokLoc.isMacroID() && Tok.isNot(tok::r_brace) && 
+               Tok.isNot(tok::semi) && Tok.isNot(tok::eof));
+    }
   }
   return false;
 }
diff --git a/test/Sema/ms-fuzzy-asm.c b/test/Sema/ms-fuzzy-asm.c
new file mode 100644 (file)
index 0000000..7c24985
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang %s -verify -fms-extensions
+
+#define M __asm int 0x2c
+#define M2 int
+
+void t1(void) { M }
+void t2(void) { __asm int 0x2c }
+// FIXME? We don't support fuzzy parsing line-oriented __asm's where the body is partially defined in a macro.
+void t3(void) { __asm M2 0x2c } // expected-error{{expected ';' after expression}} expected-warning{{expression result unused}}
+