| Issue |
238195
|
| Summary |
[CodeGen][AsmPrinter] Segfault in AsmPrinter::emitFunctionHeader when the !func_sanitize proxy global has been removed by the -O2 pipeline (LangRef example)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zjy-dev
|
The LangRef `!func_sanitize` example uses the form `!{i32 <sig>, ptr @__llvm_rtti_proxy}`. Only metadata
references `@__llvm_rtti_proxy`, so the -O2 pipeline (GlobalDCE) deletes it, and the operand becomes
`null` (`!{i32 846595819, null}`). The module still passes the verifier. However, `AsmPrinter::emitFunctionHeader`
then segfaults, on every target we tried (x86_64, aarch64).
```llvm
target triple = "x86_64-unknown-linux-gnu"
@_ZTIFvvE = external constant ptr
@__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE
define void @_Z3funv() !func_sanitize !0 {
ret void
}
!0 = !{i32 846595819, ptr @__llvm_rtti_proxy}
```
Compile flag: `clang --target=x86_64-unknown-linux-gnu -O2 -c trigger.ll` (or `opt -O2` followed by `llc`)
```
== llc trigger.ll # unoptimized: fine
rc=0
== opt -O2 trigger.ll
define void @_Z3funv() local_unnamed_addr #0 !func_sanitize !0 {
!0 = distinct !{i32 846595819, null} # proxy removed, operand is null
== llc trigger.O2.ll
2. Running pass 'X86 Assembly Printer' on function '@_Z3funv'
3 llc llvm::AsmPrinter::emitFunctionHeader() + 2016
rc=139 # SIGSEGV
== clang -O2 -c trigger.ll
3. Running pass 'X86 Assembly Printer' on function '@_Z3funv'
rc=139
```
`llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1094-1100` calls `mdconst::extract<Constant>(MD->getOperand(1))`
without checking for null. The IR Verifier also does not check the operands of `!func_sanitize`.
Clang currently emits `!{i32 sig, i32 hash}`, which is not affected. Hand-written IR that follows LangRef, or any
producer that uses the documented `ptr` form, crashes at -O1 and above. The crash also reproduces with `llc` trunk
on Compiler Explorer (exit code 139, same pass).
**Suggested fix:** make the Verifier reject malformed `!func_sanitize` (2 operands, constant, non-null), or make
AsmPrinter use `mdconst::dyn_extract_or_null` and skip or diagnose. Also update the LangRef example (for example,
put the proxy in `@llvm.compiler.used`, or use the `i32` hash form that clang emits).
Environment: LLVM 23.1.2 (llvmorg-23.1.2), x86_64-unknown-linux-gnu / aarch64-linux-gnu.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs