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
diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp
index da4120a..c0bcf2c 100644
--- a/lib/Sema/SemaStmtAsm.cpp
+++ b/lib/Sema/SemaStmtAsm.cpp
@@ -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);