[cfe-commits] r164551 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmtAsm.cpp test/Sema/ms-inline-asm.c

Bob Wilson bob.wilson at apple.com
Mon Sep 24 12:57:59 PDT 2012


Author: bwilson
Date: Mon Sep 24 14:57:59 2012
New Revision: 164551

URL: http://llvm.org/viewvc/llvm-project?rev=164551&view=rev
Log:
Replace an assertion with an error for empty __asm statements.

Added:
    cfe/trunk/test/Sema/ms-inline-asm.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=164551&r1=164550&r2=164551&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 24 14:57:59 2012
@@ -5097,6 +5097,7 @@
     "unsupported inline asm: input with type "
     "%diff{$ matching output with type $|}0,1">;
   def err_asm_unknown_register_name : Error<"unknown register name '%0' in asm">;
+  def err_asm_empty : Error<"__asm used with no assembly instructions">;
   def warn_asm_label_on_auto_decl : Warning<
     "ignored asm label '%0' on automatic variable">;
   def err_invalid_asm_cast_lvalue : Error<

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=164551&r1=164550&r2=164551&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Mon Sep 24 14:57:59 2012
@@ -415,8 +415,10 @@
 }
 
 // Build the individual assembly instruction(s) and place them in the AsmStrings
-// vector.  These strings are fed to the AsmParser.
-static void buildMSAsmStrings(Sema &SemaRef, ArrayRef<Token> AsmToks,
+// vector.  These strings are fed to the AsmParser.  Returns true on error.
+static bool buildMSAsmStrings(Sema &SemaRef,
+                              SourceLocation AsmLoc,
+                              ArrayRef<Token> AsmToks,
                               std::vector<std::string> &AsmStrings,
                      std::vector<std::pair<unsigned,unsigned> > &AsmTokRanges) {
   assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
@@ -437,7 +439,10 @@
       }
       if (AsmToks[i].is(tok::kw_asm)) {
         i++; // Skip __asm
-        assert(i != e && "Expected another token");
+        if (i == e) {
+          SemaRef.Diag(AsmLoc, diag::err_asm_empty);
+          return true;
+        }
       }
     }
 
@@ -449,6 +454,8 @@
   }
   AsmStrings.push_back(Asm.str());
   AsmTokRanges.push_back(std::make_pair(startTok, AsmToks.size()-1));
+
+  return false;
 }
 
 #define DEF_SIMPLE_MSASM(STR)                                                \
@@ -482,7 +489,8 @@
 
   std::vector<std::string> AsmStrings;
   std::vector<std::pair<unsigned,unsigned> > AsmTokRanges;
-  buildMSAsmStrings(*this, AsmToks, AsmStrings, AsmTokRanges);
+  if (buildMSAsmStrings(*this, AsmLoc, AsmToks, AsmStrings, AsmTokRanges))
+    return StmtError();
 
   std::vector<std::vector<StringRef> > Pieces(AsmStrings.size());
   buildMSAsmPieces(AsmStrings, Pieces);

Added: cfe/trunk/test/Sema/ms-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms-inline-asm.c?rev=164551&view=auto
==============================================================================
--- cfe/trunk/test/Sema/ms-inline-asm.c (added)
+++ cfe/trunk/test/Sema/ms-inline-asm.c Mon Sep 24 14:57:59 2012
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fms-extensions -fenable-experimental-ms-inline-asm -verify -fsyntax-only
+
+void t1(void) { 
+ __asm __asm // expected-warning {{MS-style inline assembly is not supported}} expected-error {{__asm used with no assembly instructions}}
+}





More information about the cfe-commits mailing list