]> granicus.if.org Git - clang/commitdiff
Add InlineAsmDiagnosticHandler for bitcode input
authorSteven Wu <stevenwu@apple.com>
Thu, 12 Feb 2015 02:06:55 +0000 (02:06 +0000)
committerSteven Wu <stevenwu@apple.com>
Thu, 12 Feb 2015 02:06:55 +0000 (02:06 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228898 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenAction.cpp
test/CodeGen/asm-errors.c

index 499b97d7846ed147d4414839b0d77c37059239a9..b5ed12aee318922111921a7a726c333fa8daf4f7 100644 (file)
@@ -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);
index 438c82ba74db9d4cd2d3db8f6f8ae20ee019143d..05751a8e690a285dd9d8015ee9f1c45cd83b7e93 100644 (file)
@@ -3,6 +3,12 @@
 // RUN: true
 // UN: not %clang_cc1 -triple i386-apple-darwin10 -emit-obj %s -o /dev/null > %t 2>&1
 // UN: FileCheck %s < %t
+// RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm-bc %s -o %t.bc
+// RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-obj %t.bc -o /dev/null 2>&1 | \
+// RUN:   FileCheck --check-prefix=CRASH-REPORT %s
+// CRASH-REPORT: <inline asm>:
+// CRASH-REPORT: error: invalid instruction mnemonic 'abc'
+// CRASH-REPORT-NOT: note: diagnostic msg:
 
 int test1(int X) {
 // CHECK: error: invalid instruction mnemonic 'abc'