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

Add -Zlint-llvm-ir #128970

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Add -Zlint-llvm-ir #128970

merged 1 commit into from
Aug 29, 2024

Conversation

DianQK
Copy link
Member

@DianQK DianQK commented Aug 11, 2024

This flag is similar to -Zverify-llvm-ir and allows us to lint the generated IR.

r? compiler

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 11, 2024
@DianQK
Copy link
Member Author

DianQK commented Aug 11, 2024

I can now use ./x build --stage 2 to find a (maybe) problem:

Unusual: noalias argument aliases another argument
  invoke void %6(ptr noundef align 1 %0, ptr noalias noundef readonly align 8 dereferenceable(16) %0)
          to label %15 unwind label %10, !dbg !15
rustc-LLVM ERROR: Linter found errors, aborting. (enabled by --lint-abort-on-error)

@matthiaskrgr
Copy link
Member

🤔 I though this can already be done, stabley, with -Cpasses=lint ?

@DianQK
Copy link
Member Author

DianQK commented Aug 12, 2024

🤔 I though this can already be done, stabley, with -Cpasses=lint ?

I want to run lint the LLVM IR that rustc generates. Of course, I can use it together with -Cno-prepopulate-passes.

@@ -652,6 +652,10 @@ impl Session {
self.opts.unstable_opts.verify_llvm_ir || option_env!("RUSTC_VERIFY_LLVM_IR").is_some()
}

pub fn lint_llvm_ir(&self) -> bool {
self.opts.unstable_opts.lint_llvm_ir || option_env!("RUSTC_LINT_LLVM_IR").is_some()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This env var isn't set anywhere.

@fmease
Copy link
Member

fmease commented Aug 29, 2024

Sorry for the delay. My understanding is limited unfortunately, I can't tell the difference between -Cpasses=lint and -Zlint-llvm-ir (apart from the --lint-abort-on-error)
r? @nikic

@rustbot rustbot assigned nikic and unassigned fmease Aug 29, 2024
@DianQK
Copy link
Member Author

DianQK commented Aug 29, 2024

Sorry for the delay. My understanding is limited unfortunately, I can't tell the difference between -Cpasses=lint and -Zlint-llvm-ir (apart from the --lint-abort-on-error)

The main difference is that with the -Zlint-llvm-ir flag, the lint will be executed before optimization, allowing us to lint the IR generated by rustc, similar to using the -Cverify-llvm-ir flag.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with adding the flag. It may be more convenient to use in a larger compilation where -C no-prepopulate-passes may be undesirable.

@@ -90,6 +91,9 @@ unsafe fn configure_llvm(sess: &Session) {
if sess.opts.unstable_opts.print_llvm_passes {
add("-debug-pass=Structure", false);
}
if llvm_version >= (19, 0, 0) && sess.opts.unstable_opts.lint_llvm_ir {
add("-lint-abort-on-error", false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should hardcode this option. You can add it via -Cllvm-args=-lint-abort-on-error if desired.

@nikic
Copy link
Contributor

nikic commented Aug 29, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Aug 29, 2024

📌 Commit 9589eb9 has been approved by nikic

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 29, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 29, 2024
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#123940 (debug-fmt-detail option)
 - rust-lang#128166 (Improved `checked_isqrt` and `isqrt` methods)
 - rust-lang#128970 (Add `-Zlint-llvm-ir`)
 - rust-lang#129316 (riscv64imac: allow shadow call stack sanitizer)
 - rust-lang#129690 (Add `needs-unwind` compiletest directive to `libtest-thread-limit` and replace some `Path` with `path` in `run-make`)
 - rust-lang#129732 (Add `unreachable_pub`, round 3)
 - rust-lang#129743 (Fix rustdoc clippy lints)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 29, 2024
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#123940 (debug-fmt-detail option)
 - rust-lang#128166 (Improved `checked_isqrt` and `isqrt` methods)
 - rust-lang#128970 (Add `-Zlint-llvm-ir`)
 - rust-lang#129316 (riscv64imac: allow shadow call stack sanitizer)
 - rust-lang#129690 (Add `needs-unwind` compiletest directive to `libtest-thread-limit` and replace some `Path` with `path` in `run-make`)
 - rust-lang#129732 (Add `unreachable_pub`, round 3)
 - rust-lang#129743 (Fix rustdoc clippy lints)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d5c40d0 into rust-lang:master Aug 29, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 29, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 29, 2024
Rollup merge of rust-lang#128970 - DianQK:lint-llvm-ir, r=nikic

Add `-Zlint-llvm-ir`

This flag is similar to `-Zverify-llvm-ir` and allows us to lint the generated IR.

r? compiler
@DianQK DianQK deleted the lint-llvm-ir branch August 29, 2024 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants