diff --git a/CHANGELOG.md b/CHANGELOG.md index ada125c8ed1..7abf8e95252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Supports LLVM 9.0 - 15.0. #### Bug fixes +- Fix regression with LLVM 13+: some errors in inline assembly don't stop compilation. (#4293, #4331) # LDC 1.31.0 (2022-02-11) diff --git a/driver/codegenerator.cpp b/driver/codegenerator.cpp index e92c71866f5..32f6004cc8c 100644 --- a/driver/codegenerator.cpp +++ b/driver/codegenerator.cpp @@ -161,8 +161,13 @@ bool inlineAsmDiagnostic(IRState *irs, const llvm::SMDiagnostic &d, #if LDC_LLVM_VER < 1300 void inlineAsmDiagnosticHandler(const llvm::SMDiagnostic &d, void *context, unsigned locCookie) { - if (d.getKind() == llvm::SourceMgr::DK_Error) + if (d.getKind() == llvm::SourceMgr::DK_Error) { ++global.errors; + } else if (global.params.warnings == DIAGNOSTICerror && + d.getKind() == llvm::SourceMgr::DK_Warning) { + ++global.warnings; + } + inlineAsmDiagnostic(static_cast(context), d, locCookie); } #else @@ -176,8 +181,15 @@ struct InlineAsmDiagnosticHandler : public llvm::DiagnosticHandler { return false; const auto &DISM = llvm::cast(DI); - if (DISM.getKind() == llvm::SourceMgr::DK_Error) + if (DISM.getKind() == llvm::SourceMgr::DK_Error || + DISM.getSeverity() == llvm::DS_Error) { ++global.errors; + } else if (global.params.warnings == DIAGNOSTICerror && + (DISM.getKind() == llvm::SourceMgr::DK_Warning || + DISM.getSeverity() == llvm::DS_Warning)) { + ++global.warnings; + } + return inlineAsmDiagnostic(irs, DISM.getSMDiag(), DISM.getLocCookie()); } }; diff --git a/tests/fail_compilation/asm_error_gh4293.d b/tests/fail_compilation/asm_error_gh4293.d new file mode 100644 index 00000000000..58a3b955a05 --- /dev/null +++ b/tests/fail_compilation/asm_error_gh4293.d @@ -0,0 +1,11 @@ +// Make sure an invalid asm instruction causes a non-zero exit code. + +// RUN: not %ldc -c %s 2> %t.stderr +// RUN: FileCheck %s < %t.stderr + +void main() +{ + asm { "some_garbage"; } +} + +// CHECK: asm_error_gh4293.d(8):1:2: error: invalid instruction mnemonic 'some_garbage'