Skip to content

Commit

Permalink
Fix regression with LLVM 13+: some errors in inline assembly don't st…
Browse files Browse the repository at this point in the history
…op compilation

Based on Luís' ldc-developers#4302; fixes ldc-developers#4293.
  • Loading branch information
kinke committed Feb 26, 2023
1 parent d89c00c commit bad2ca9
Show file tree
Hide file tree
Showing 3 changed files with 26 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+: some errors in inline assembly don't stop compilation. (#4293, #4331)

# 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
11 changes: 11 additions & 0 deletions tests/fail_compilation/asm_error_gh4293.d
Original file line number Diff line number Diff line change
@@ -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: error:

0 comments on commit bad2ca9

Please sign in to comment.