| Issue |
243121
|
| Summary |
UBSan finds null-reference-bind in PassBuilder.cpp
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
jmorse
|
Ahoy,
Observe tests such as llvm/test/Transforms/PreISelIntrinsicLowering/emupac.ll [0] on main at the moment. They use an aarch64 triple, but do not have a `REQUIRES: aarch64-registered-target` line present, which causes our downstream x86-target-only builds to fail to create a `TargetMachine` when the test runs. Previously this just resulted in a warning; but recently UBSan has begun complaining immediately afterwards:
```
WARNING: failed to create target machine for 'aarch64-unknown-linux-gnu': unable to get target for 'aarch64-unknown-linux-gnu', see --version and --triple.
llvm\lib\Passes\PassRegistry.def:143:1: runtime error: reference binding to null pointer of type 'const TargetMachine'
```
Digging into how opt creates passes and `TargetMachine`'s, it looks like a null `TargetMachine` can result from being asked for an unavailable target, and is normal. Then some code generated in PassBuilder.cpp via the MODULE_PASS macro synthesises this line:
```
if (Name == "pre-isel-intrinsic-lowering") { MPM.addPass(PreISelIntrinsicLoweringPass(*TM)); return Error::success(); }
```
Which unconditionally dereferences a null TM to bind it to a reference during pass creation, and thus causes UBSan to complain. No actual null dereference occurs at runtime.
I'm not sure what to do about this: I'm not familiar with the pass manager (new or old) and what the expectations are, plus the harm to users is probably zero. The only risk is that someone hits a crash from a null `TargetMachine` and loses the warning about it in stderr noise.
[0] https://github.com/llvm/llvm-project/blob/75bb30ddbf3bf3b9f01cf1c46fe6d9749f377d9d/llvm/test/Transforms/PreISelIntrinsicLowering/emupac.ll
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs