| Issue |
244299
|
| Summary |
[fuzzer-found][instrumentor] Instrumentor emits verifier-invalid IR for four unrelated constructs
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
PiesAvalon
|
We found this crash using a fuzzer we are developing to test LLVM optimization passes.
On LLVM 23.1.6 (stock release build), all four inputs below pass
`opt -passes=verify`, and each one makes
`opt -passes=module(instrumentor) -verify-each -disable-output repro.ll`
abort with `LLVM ERROR: Broken module found after pass "InstrumentorPass"`.
They share the final `assert(!verifyModule(M, &errs()))` in
`llvm/lib/Transforms/IPO/Instrumentor.cpp:534`, but the underlying cause is
different in each case: the pass rewrites a construct without checking the
legality rule that construct has. I have kept them together because the fix is
the same kind (a guard in `InstrumentorImpl` before instrumenting) and they
will likely be triaged by the same person, but each needs its own check.
---
## 1. `common` global shadow gets a non-zero initializer
```llvm
@i2 = common global i838608 0
```
```
'common' global must have a zero initializer!
ptr @__instrumentor_shadow.i2
```
In `GlobalVarIO::setAddress` the shadow global is created with
`GV.getLinkage()` and a store of the original value. For `common` linkage the
initializer must stay zero. Guard: skip `GV.hasCommonLinkage()`, or give the
shadow internal linkage.
## 2. Instrumentation moves the musttail call out of its tail position
```llvm
define tailcc [16 x i64] @caller() {
%res = musttail call tailcc [16 x i64] null()
ret [16 x i64] %res
}
```
```
musttail call must precede a ret
%res = musttail call tailcc [16 x i64] null()
```
Instrumentation is inserted between the `musttail` call and its `ret`. Guard:
do not instrument `musttail` call sites (same treatment `experimental_deoptimize`
needs below).
## 3. `llvm.threadlocal.address` gets a non-global operand
```llvm
@var = external thread_local global i32
define ptr @should_pass() {
%p0 = call ptr @llvm.threadlocal.address.p0(ptr @var)
ret ptr %p0
}
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```
```
llvm.threadlocal.address first argument must be a GlobalValue
```
The pass rewrites the operand of the intrinsic into a temporary value. Guard:
leave arguments of `llvm.threadlocal.address` (and the same family:
`llvm.localescape`, `llvm.localrecover`, `llvm.gcroot`,
`llvm.stackprotector`) untouched.
## 4. `swifterror` argument no longer has the required operand order
```llvm
define swiftcc void @g(ptr swifterror %error) {
entry:
ret void
}
```
```
swifterror value should be the second operand when used by stores
ptr %error
store ptr %error, ptr %4, align 8
```
The pass introduces a store of the `swifterror` value with the value as the
first operand. Guard: skip `swifterror` arguments, or keep value/pointer order.
---
## Note
`Instrumentor.cpp` has no checks for `Naked` functions, `musttail`,
`swifterror`, appending linkage, target-extension types or scalable types. The
four above are the smallest cases I have; I can file the others separately if
that is easier to triage.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs