From 1491dc20b1bcd099d760422cdfc52d2112a9ed24 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 26 Feb 2023 01:32:03 +0100 Subject: [PATCH] Fix regression with LLVM 13+: Return non-zero exit code for inline asm errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on Luís' #4302. --- CHANGELOG.md | 1 + driver/codegenerator.cpp | 16 ++++++++++++++-- tests/driver/asm_error_gh4293.d | 8 ++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/driver/asm_error_gh4293.d diff --git a/CHANGELOG.md b/CHANGELOG.md index ada125c8ed1..17063238b13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Supports LLVM 9.0 - 15.0. #### Bug fixes +- Fix regression with LLVM 13+: return non-zero exit code for inline assembly errors. (#4293) # 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/driver/asm_error_gh4293.d b/tests/driver/asm_error_gh4293.d new file mode 100644 index 00000000000..701e17b1ba0 --- /dev/null +++ b/tests/driver/asm_error_gh4293.d @@ -0,0 +1,8 @@ +// Make sure an inline assembly error causes a non-zero exit code. + +// RUN: not %ldc -c %s + +void main() +{ + asm { "someGarbage"; } +}