Skip to content

Commit

Permalink
Fix regression with LLVM 13+: Return non-zero exit code for inline as…
Browse files Browse the repository at this point in the history
…m errors

Based on Luís' ldc-developers#4302.
  • Loading branch information
kinke committed Feb 26, 2023
1 parent d89c00c commit 1491dc2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 14 additions & 2 deletions driver/codegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRState *>(context), d, locCookie);
}
#else
Expand All @@ -176,8 +181,15 @@ struct InlineAsmDiagnosticHandler : public llvm::DiagnosticHandler {
return false;

const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(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());
}
};
Expand Down
8 changes: 8 additions & 0 deletions tests/driver/asm_error_gh4293.d
Original file line number Diff line number Diff line change
@@ -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"; }
}

0 comments on commit 1491dc2

Please sign in to comment.