aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Wilson <bob.wilson@apple.com>2012-09-24 19:57:59 +0000
committerBob Wilson <bob.wilson@apple.com>2012-09-24 19:57:59 +0000
commitb0f6b9c94077446ceb29167add2e87fb99733a55 (patch)
treefed1197ee2c9cf0608838f2673284fb1b0f0bcd0
parent40d39e39e46eb36635c9735381ca5c4f916d30cd (diff)
Replace an assertion with an error for empty __asm statements.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164551 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td1
-rw-r--r--lib/Sema/SemaStmtAsm.cpp16
-rw-r--r--test/Sema/ms-inline-asm.c5
3 files changed, 18 insertions, 4 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 86d00c2c7e..3cd3d4303e 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5097,6 +5097,7 @@ let CategoryName = "Inline Assembly Issue" in {
"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<
diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp
index da4120af22..c0bcf2c15e 100644
--- a/lib/Sema/SemaStmtAsm.cpp
+++ b/lib/Sema/SemaStmtAsm.cpp
@@ -415,8 +415,10 @@ static void buildMSAsmPieces(std::vector<std::string> &AsmStrings,
}
// 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 @@ static void buildMSAsmStrings(Sema &SemaRef, ArrayRef<Token> AsmToks,
}
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 @@ static void buildMSAsmStrings(Sema &SemaRef, ArrayRef<Token> AsmToks,
}
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 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
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);
diff --git a/test/Sema/ms-inline-asm.c b/test/Sema/ms-inline-asm.c
new file mode 100644
index 0000000000..4c9dfd0b59
--- /dev/null
+++ b/test/Sema/ms-inline-asm.c
@@ -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}}
+}