aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCContext.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2020-12-20 23:23:12 -0800
committerFangrui Song <i@maskray.me>2020-12-20 23:23:12 -0800
commit8ffda237a6699780bc657a97ae178a3ea078957c (patch)
treeed1eac6a1bdf8224c509017d8e8c44ac0724a141 /llvm/lib/MC/MCContext.cpp
parente2303a448e2fcc1d96d66e9ee9f0cfc009b69a3f (diff)
downloadllvm-8ffda237a6699780bc657a97ae178a3ea078957c.zip
llvm-8ffda237a6699780bc657a97ae178a3ea078957c.tar.gz
llvm-8ffda237a6699780bc657a97ae178a3ea078957c.tar.bz2
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.
Diffstat (limited to 'llvm/lib/MC/MCContext.cpp')
-rw-r--r--llvm/lib/MC/MCContext.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index fe84283..d054c93 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -825,13 +825,13 @@ void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
// If we have a source manager use it. Otherwise, try using the inline source
// manager.
- // If that fails, use the generic report_fatal_error().
+ // If that fails, construct a temporary SourceMgr.
if (SrcMgr)
SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
else if (InlineSrcMgr)
InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
else
- report_fatal_error(Msg, false);
+ SourceMgr().PrintMessage(Loc, SourceMgr::DK_Error, Msg);
}
void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {