Skip to content

Commit 8ffda23

Browse files
committed
MCContext::reportError: don't call report_fatal_error
Errors from MCAssembler, MCObjectStreamer and *ObjectWriter typically cause a crash: ``` % cat c.c int bar; extern int foo __attribute__((alias("bar"))); % clang -c -fcommon c.c fatal error: error in backend: Common symbol 'bar' cannot be used in assignment expr PLEASE submit a bug report to ... Stack dump: ... ``` `LLVMTargetMachine::addPassesToEmitFile` constructs `MachineModuleInfoWrapperPass` which creates a MCContext without SourceMgr. `MCContext::reportError` calls `report_fatal_error` which gets captured by Clang `LLVMErrorHandler` and gets translated to the output above. Since `MCContext::reportError` errors indicate user errors, such a crashing style error is inappropriate. So this patch changes `report_fatal_error` to `SourceMgr().PrintMessage`. ``` % clang -c -fcommon c.c <unknown>:0: error: Common symbol 'bar' cannot be used in assignment expr ``` Ideally we should at least recover the original filename (the line information is generally lost). That requires general improvement to MC diagnostics, because currently in many cases SMLoc information is lost.
1 parent e2303a4 commit 8ffda23

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

llvm/lib/MC/MCContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,13 +825,13 @@ void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
825825

826826
// If we have a source manager use it. Otherwise, try using the inline source
827827
// manager.
828-
// If that fails, use the generic report_fatal_error().
828+
// If that fails, construct a temporary SourceMgr.
829829
if (SrcMgr)
830830
SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
831831
else if (InlineSrcMgr)
832832
InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
833833
else
834-
report_fatal_error(Msg, false);
834+
SourceMgr().PrintMessage(Loc, SourceMgr::DK_Error, Msg);
835835
}
836836

837837
void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
; RUN: not --crash llc -global-isel -march=amdgcn -mcpu=tonga < %S/../lds-zero-initializer.ll 2>&1 | FileCheck %s
1+
; RUN: not llc -global-isel -march=amdgcn -mcpu=tonga < %S/../lds-zero-initializer.ll 2>&1 | FileCheck %s
22

3-
; CHECK: error: <unknown>:0:0: in function load_zeroinit_lds_global void (i32 addrspace(1)*, i1): unsupported initializer for address space
3+
; CHECK: <unknown>:0: error: lds: unsupported initializer for address space

llvm/test/CodeGen/AMDGPU/lds-initializer.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: not --crash llc -march=amdgcn -mcpu=tahiti < %s 2>&1 | FileCheck %s
2-
; RUN: not --crash llc -march=amdgcn -mcpu=tonga < %s 2>&1 | FileCheck %s
1+
; RUN: llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
2+
; RUN: llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
33

44
; CHECK: lds: unsupported initializer for address space
55

llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: not --crash llc -march=amdgcn -mcpu=tahiti < %s 2>&1 | FileCheck %s
2-
; RUN: not --crash llc -march=amdgcn -mcpu=tonga < %s 2>&1 | FileCheck %s
1+
; RUN: llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
2+
; RUN: llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
33

44
; CHECK: lds: unsupported initializer for address space
55

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
; RUN: not --crash llc < %s -march=xcore 2>&1 | FileCheck %s
1+
; RUN: llc < %s -march=xcore -o /dev/null 2>&1 | FileCheck %s
22

33
@bar = internal global i32 zeroinitializer
44

55
define void @".dp.bss"() {
66
ret void
77
}
88

9-
; CHECK: LLVM ERROR: invalid symbol redefinition
9+
; CHECK: <unknown>:0: error: invalid symbol redefinition

0 commit comments

Comments
 (0)