Skip to content

Fix regression with LLVM 13+: some errors in inline assembly don't stop compilation #4331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: