[all-commits] [llvm/llvm-project] 8ffda2: MCContext::reportError: don't call report_fatal_error

Fangrui Song via All-commits all-commits at lists.llvm.org
Sun Dec 20 23:23:29 PST 2020


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8ffda237a6699780bc657a97ae178a3ea078957c
      https://github.com/llvm/llvm-project/commit/8ffda237a6699780bc657a97ae178a3ea078957c
  Author: Fangrui Song <i at maskray.me>
  Date:   2020-12-20 (Sun, 20 Dec 2020)

  Changed paths:
    M llvm/lib/MC/MCContext.cpp
    M llvm/test/CodeGen/AMDGPU/GlobalISel/lds-zero-initializer.ll
    M llvm/test/CodeGen/AMDGPU/lds-initializer.ll
    M llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
    M llvm/test/CodeGen/XCore/section-name.ll

  Log Message:
  -----------
  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.




More information about the All-commits mailing list