[cfe-commits] r46878 - in /cfe/trunk: Parse/ParseStmt.cpp test/Sema/ms-fuzzy-asm.c

Steve Naroff snaroff at apple.com
Thu Feb 7 19:36:19 PST 2008


Author: snaroff
Date: Thu Feb  7 21:36:19 2008
New Revision: 46878

URL: http://llvm.org/viewvc/llvm-project?rev=46878&view=rev
Log:

Support fuzzy parsing MS line-oriented __asm's that originate from a macro (a case where we can't obtain source line info). As the test case indicates, we don't currently support line-oriented asm statements that mix file/macro body tokens.

Added:
    cfe/trunk/test/Sema/ms-fuzzy-asm.c
Modified:
    cfe/trunk/Parse/ParseStmt.cpp

Modified: cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseStmt.cpp?rev=46878&r1=46877&r2=46878&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/Parse/ParseStmt.cpp Thu Feb  7 21:36:19 2008
@@ -921,11 +921,22 @@
     // 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;
 }

Added: cfe/trunk/test/Sema/ms-fuzzy-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms-fuzzy-asm.c?rev=46878&view=auto

==============================================================================
--- cfe/trunk/test/Sema/ms-fuzzy-asm.c (added)
+++ cfe/trunk/test/Sema/ms-fuzzy-asm.c Thu Feb  7 21:36:19 2008
@@ -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}}
+





More information about the cfe-commits mailing list