summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseStmt.cpp
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2013-10-30 14:29:28 +0000
committerAlp Toker <alp@nuanti.com>2013-10-30 14:29:28 +0000
commit45cf31f7d390f1e7a39d27e10e2f8877487312ee (patch)
tree7612c502bfb7b63be686cfb092dbc515e5d3245d /clang/lib/Parse/ParseStmt.cpp
parent16fc75421688428ce6c84cccdaba87c694484045 (diff)
downloadbcm5719-llvm-45cf31f7d390f1e7a39d27e10e2f8877487312ee.tar.gz
bcm5719-llvm-45cf31f7d390f1e7a39d27e10e2f8877487312ee.zip
Recover instead of crashing on MS assembly when no target is loaded
It's possible to embed the frontend in applications that haven't initialized backend targets so we need to handle this condition gracefully. llvm-svn: 193685
Diffstat (limited to 'clang/lib/Parse/ParseStmt.cpp')
-rw-r--r--clang/lib/Parse/ParseStmt.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index caf0011dba9..2ff83cb5b46 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2104,9 +2104,15 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
if (UnsupportedArch)
Diag(AsmLoc, diag::err_msasm_unsupported_arch) << TheTriple.getArchName();
+ std::string Error;
+ const std::string &TT = TheTriple.getTriple();
+ const llvm::Target *TheTarget = llvm::TargetRegistry::lookupTarget(TT, Error);
+ if (!TheTarget)
+ Diag(AsmLoc, diag::err_msasm_unable_to_create_target) << Error;
+
// If we don't support assembly, or the assembly is empty, we don't
// need to instantiate the AsmParser, etc.
- if (UnsupportedArch || AsmToks.empty()) {
+ if (UnsupportedArch || !TheTarget || AsmToks.empty()) {
return Actions.ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, StringRef(),
/*NumOutputs*/ 0, /*NumInputs*/ 0,
ConstraintRefs, ClobberRefs, Exprs, EndLoc);
@@ -2118,11 +2124,6 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
if (buildMSAsmString(PP, AsmLoc, AsmToks, TokOffsets, AsmString))
return StmtError();
- // Find the target and create the target specific parser.
- std::string Error;
- const std::string &TT = TheTriple.getTriple();
- const llvm::Target *TheTarget = llvm::TargetRegistry::lookupTarget(TT, Error);
-
OwningPtr<llvm::MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
OwningPtr<llvm::MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TT));
// Get the instruction descriptor.
OpenPOWER on IntegriCloud