Skip to content

Commit c67c6e1

Browse files
committed
Fix regression with LLVM 13+: some errors in inline assembly don't stop compilation
Based on Luís' ldc-developers#4302; fixes ldc-developers#4293.
1 parent d89c00c commit c67c6e1

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Supports LLVM 9.0 - 15.0.
99

1010
#### Bug fixes
11+
- Fix regression with LLVM 13+: some errors in inline assembly don't stop compilation. (#4293, #4331)
1112

1213
# LDC 1.31.0 (2022-02-11)
1314

driver/codegenerator.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,13 @@ bool inlineAsmDiagnostic(IRState *irs, const llvm::SMDiagnostic &d,
161161
#if LDC_LLVM_VER < 1300
162162
void inlineAsmDiagnosticHandler(const llvm::SMDiagnostic &d, void *context,
163163
unsigned locCookie) {
164-
if (d.getKind() == llvm::SourceMgr::DK_Error)
164+
if (d.getKind() == llvm::SourceMgr::DK_Error) {
165165
++global.errors;
166+
} else if (global.params.warnings == DIAGNOSTICerror &&
167+
d.getKind() == llvm::SourceMgr::DK_Warning) {
168+
++global.warnings;
169+
}
170+
166171
inlineAsmDiagnostic(static_cast<IRState *>(context), d, locCookie);
167172
}
168173
#else
@@ -176,8 +181,15 @@ struct InlineAsmDiagnosticHandler : public llvm::DiagnosticHandler {
176181
return false;
177182

178183
const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
179-
if (DISM.getKind() == llvm::SourceMgr::DK_Error)
184+
if (DISM.getKind() == llvm::SourceMgr::DK_Error ||
185+
DISM.getSeverity() == llvm::DS_Error) {
180186
++global.errors;
187+
} else if (global.params.warnings == DIAGNOSTICerror &&
188+
(DISM.getKind() == llvm::SourceMgr::DK_Warning ||
189+
DISM.getSeverity() == llvm::DS_Warning)) {
190+
++global.warnings;
191+
}
192+
181193
return inlineAsmDiagnostic(irs, DISM.getSMDiag(), DISM.getLocCookie());
182194
}
183195
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Make sure an invalid asm instruction causes a non-zero exit code.
2+
3+
// RUN: not %ldc -c %s 2> %t.stderr
4+
// RUN: FileCheck %s < %t.stderr
5+
6+
void main()
7+
{
8+
asm { "some_garbage"; }
9+
}
10+
11+
// CHECK: asm_error_gh4293.d(8):1:2: error: invalid instruction mnemonic 'some_garbage'

0 commit comments

Comments
 (0)