[all-commits] [llvm/llvm-project] 96aca7: [LTO] Improve diagnostics handling when parsing mo...

Fangrui Song via All-commits all-commits at lists.llvm.org
Mon Dec 18 09:47:13 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 96aca7c51701f9b3c5dd8567fcddf29492008e6d
      https://github.com/llvm/llvm-project/commit/96aca7c51701f9b3c5dd8567fcddf29492008e6d
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-12-18 (Mon, 18 Dec 2023)

  Changed paths:
    M clang/lib/CodeGen/CodeGenAction.cpp
    M clang/test/CodeGen/invalid_global_asm.c
    M lld/test/MachO/lto-module-asm-err.ll
    M llvm/include/llvm/IR/DiagnosticHandler.h
    M llvm/lib/Object/ModuleSymbolTable.cpp

  Log Message:
  -----------
  [LTO] Improve diagnostics handling when parsing module-level inline assembly (#75726)

Non-LTO compiles set the buffer name to "<inline asm>"
(`AsmPrinter::addInlineAsmDiagBuffer`) and pass diagnostics to
`ClangDiagnosticHandler` (through the `MCContext` handler in
`MachineModuleInfoWrapperPass::doInitialization`) to ensure that
the exit code is 1 in the presence of errors. In contrast, LTO compiles
spuriously succeed even if error messages are printed.

```
% cat a.c
void _start() {}
asm("unknown instruction");
% clang -c a.c
<inline asm>:1:1: error: invalid instruction mnemonic 'unknown'
    1 | unknown instruction
      | ^
1 error generated.
% clang -c -flto a.c; echo $?  # -flto=thin is the same
error: invalid instruction mnemonic 'unknown'
unknown instruction
^~~~~~~
error: invalid instruction mnemonic 'unknown'
unknown instruction
^~~~~~~
0
```

`CollectAsmSymbols` parses inline assembly and is transitively called by
both `ModuleSummaryIndexAnalysis::run` and `WriteBitcodeToFile`, leading
to duplicate diagnostics.

This patch updates `CollectAsmSymbols` to be similar to non-LTO
compiles.
```
% clang -c -flto=thin a.c; echo $?
<inline asm>:1:1: error: invalid instruction mnemonic 'unknown'
    1 | unknown instruction
      | ^
1 errors generated.
1
```

The `HasErrors` check does not prevent duplicate warnings but assembler
warnings are very uncommon.




More information about the All-commits mailing list