Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the new LLVM Pass Manager is enabled, -Z verify-llvm-ir=yes is ignored if -C no-prepopulate-passes is also given #95874

Closed
luqmana opened this issue Apr 10, 2022 · 0 comments · Fixed by #95893
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug.

Comments

@luqmana
Copy link
Member

luqmana commented Apr 10, 2022

While investigating the issue fixed in #95864 I came across some surprising behaviour. In trying to figure out whether rustc was generating invalid IR or it was some subsequent LLVM pass, I realized that -Z verify-llvm-ir was essentially ignored with -C no-prepopulate-passes in the new LLVM Pass Manager. This lead me to (incorrectly) assume that the IR rustc generated was valid when it got to LLVM.

It looks like a subtle change in behaviour due to the way the new Pass Manager is constructed in LLVMRustOptimizeWithNewPassManager.

@luqmana luqmana added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. labels Apr 10, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 12, 2022
…s, r=nikic

Respect -Z verify-llvm-ir and other flags that add extra passes when combined with -C no-prepopulate-passes in the new LLVM Pass Manager.

As part of the switch to the new LLVM Pass Manager the behaviour of flags such as `-Z verify-llvm-ir` (e.g. sanitizer, instrumentation) was modified when combined with `-C no-prepopulate-passes`. With the old PM, rustc was the one manually constructing the pipeline and respected those flags but in the new pass manager, those flags are used to build a list of callbacks that get invoked at certain extension points in the pipeline. Unfortunately, `-C no-prepopulate-passes` would skip building the pipeline altogether meaning we'd never add the corresponding passes. The fix here is to just manually invoke those callbacks as needed.

Fixes rust-lang#95874

Demonstrating the current vs fixed behaviour using the bug in rust-lang#95864
```console
$ rustc +nightly asm-miscompile.rs --edition 2021 --emit=llvm-ir -C no-prepopulate-passes -Z verify-llvm-ir
$ echo $?
0
$ rustc +stage1 asm-miscompile.rs --edition 2021 --emit=llvm-ir -C no-prepopulate-passes -Z verify-llvm-ir
Basic Block in function '_ZN14asm_miscompile3foo28_$u7b$$u7b$closure$u7d$$u7d$17h360e2f7eee1275c5E' does not have terminator!
label %bb1
LLVM ERROR: Broken module found, compilation aborted!
```
@bors bors closed this as completed in b8f4cb6 Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug.
Projects
None yet
1 participant