From 15b385f8547e6d7236b39e66a8d3a53df5b3f454 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Thu, 12 Feb 2015 02:06:55 +0000 Subject: Add InlineAsmDiagnosticHandler for bitcode input Summary: This patch installs an InlineAsmDiagnosticsHandler to avoid the crash report when the input is bitcode and the bitcode contains invalid inline assembly. The handler will simply print the same error message that will print from the backend. Add CHECK in test-case Reviewers: echristo, rafael Reviewed By: rafael Subscribers: rafael, cfe-commits Differential Revision: http://reviews.llvm.org/D7568 llvm-svn: 228898 --- clang/lib/CodeGen/CodeGenAction.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenAction.cpp') diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 499b97d7846..b5ed12aee31 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -667,6 +667,12 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return std::move(Result); } +static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, + void *Context, + unsigned LocCookie) { + SM.print(nullptr, llvm::errs()); +} + void CodeGenAction::ExecuteAction() { // If this is an IR file, we have to treat it specially. if (getCurrentFileKind() == IK_LLVM_IR) { @@ -715,6 +721,8 @@ void CodeGenAction::ExecuteAction() { TheModule->setTargetTriple(TargetOpts.Triple); } + LLVMContext &Ctx = TheModule->getContext(); + Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler); EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(), TargetOpts, CI.getLangOpts(), CI.getTarget().getTargetDescription(), TheModule.get(), BA, OS); -- cgit v1.2.3