From 733e42df1c2061f59742727e3b0905cf03b8b6e5 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Wed, 6 Apr 2016 19:58:07 +0000 Subject: [PATCH] Restore slightly less dodgy diagnostic handler for inline asm Turns out it was there mostly to prevent Clang asking people to report a bug. This time we report something to Clang's real diagnostics handler so that it exits with something approximating a real error and tidies up after itself. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265592 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenAction.cpp | 25 +++++++++++++++++++++++++ test/CodeGen/asm-errors.c | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 658c2b8c77..9bdbacd63f 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -756,6 +756,28 @@ 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()); + + auto Diags = static_cast(Context); + unsigned DiagID; + switch (SM.getKind()) { + case llvm::SourceMgr::DK_Error: + DiagID = diag::err_fe_inline_asm; + break; + case llvm::SourceMgr::DK_Warning: + DiagID = diag::warn_fe_inline_asm; + break; + case llvm::SourceMgr::DK_Note: + DiagID = diag::note_fe_inline_asm; + break; + } + + Diags->Report(DiagID).AddString("cannot compile inline asm"); +} + void CodeGenAction::ExecuteAction() { // If this is an IR file, we have to treat it specially. if (getCurrentFileKind() == IK_LLVM_IR) { @@ -804,6 +826,9 @@ void CodeGenAction::ExecuteAction() { TheModule->setTargetTriple(TargetOpts.Triple); } + LLVMContext &Ctx = TheModule->getContext(); + Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler, + &CI.getDiagnostics()); EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(), TargetOpts, CI.getLangOpts(), CI.getTarget().getDataLayout(), TheModule.get(), BA, OS); diff --git a/test/CodeGen/asm-errors.c b/test/CodeGen/asm-errors.c index 7edce64f20..a959896df1 100644 --- a/test/CodeGen/asm-errors.c +++ b/test/CodeGen/asm-errors.c @@ -2,11 +2,11 @@ // RUN: not %clang_cc1 -triple i386-apple-darwin10 -emit-obj %s -o /dev/null > %t 2>&1 // RUN: FileCheck %s < %t -// RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm-bc %s -o %t.bc -// RUN: not %clang_cc1 -triple i386-apple-darwin10 -emit-obj %t.bc -o /dev/null 2>&1 | \ +// RUN: not %clang -target i386-apple-darwin10 -fembed-bitcode -c %s -o /dev/null 2>&1 | \ // RUN: FileCheck --check-prefix=CRASH-REPORT %s // CRASH-REPORT: : // CRASH-REPORT: error: invalid instruction mnemonic 'abc' +// CRASH-REPORT: error: cannot compile inline asm // CRASH-REPORT-NOT: note: diagnostic msg: int test1(int X) { -- 2.40.0