-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Put checks that detect UB under their own flag below debug_assertions #123411
Conversation
The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
tests/codegen/ub-checks.rs
Outdated
// CHECK-NEXT: start: | ||
// CHECK-NEXT: icmp ult | ||
// CHECK-NEXT: tail call void @llvm.assume | ||
// CHECK-NEXT: getelementptr inbounds | ||
// CHECK-NEXT: ret ptr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scottmcm Can you offer some advice on the right way to write this test? I'm not sure how exact I should be matching against the IR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use revisions to put tests for the presence and the absence in the same file? For inspiration, maybe look at this file, where it checks the different codegen for OPT0 and OPT3 -- you could do the same kind of thing for UB-checks on and off:
rust/tests/codegen/intrinsics/typed_swap.rs
Lines 1 to 4 in 0accf4e
//@ revisions: OPT0 OPT3 | |
//@ [OPT0] compile-flags: -Copt-level=0 | |
//@ [OPT3] compile-flags: -Copt-level=3 | |
//@ compile-flags: -C no-prepopulate-passes |
And if the NOUBCHECK-NOT
negative check is right next to the YESUBCHECK
positive check for the same thing, it's way more likely that the negative test is actually doing something meaningful.
Maybe you can also check things like that the assume optimizes out when the ub-check is on, because it ends up unneeded as the dominating branch checks the same thing?
@rustbot author |
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
@rustbot ready |
compiler/rustc_session/src/config.rs
Outdated
@@ -1236,6 +1236,10 @@ fn default_configuration(sess: &Session) -> Cfg { | |||
ins_none!(sym::overflow_checks); | |||
} | |||
|
|||
if sess.ub_checks() { | |||
ins_none!(sym::ub_checks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for cfg!(ub_checks)
I assume. There's no test for that though that I can see?
Also I wonder if we need to feature-gate this. Some cfg
have been feature-gated in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need some way to prevent use on stable, yeah. In the MCP you mention that cfg(overflow_checks)
isn't stabilized; can we use the same mechanism (possibly even the same feature gate)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, that's tracked here: #111466.
Same feature gate seems strange though, then we'll have to split it up if we want to stabilize cfg(overflow_checks)
before -Cub-checks
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair, different feature gate then
LGTM except for the missing test, but I'll hand over to a compiler person as some of this is a bit outside my comfort zone -- in particular regarding the new r? compiler |
compiler/rustc_session/src/config.rs
Outdated
@@ -1236,6 +1236,10 @@ fn default_configuration(sess: &Session) -> Cfg { | |||
ins_none!(sym::overflow_checks); | |||
} | |||
|
|||
if sess.ub_checks() { | |||
ins_none!(sym::ub_checks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing it's counter-part below in CheckCfg::fill_well_known
:
rust/compiler/rustc_session/src/config.rs
Line 1392 in 6cf853c
pub fn fill_well_known(&mut self, current_target: &Target) { |
Something like this should do it:
ins!(sym::ub_checks, no_values);
Please also follow the guidelines,
rust/compiler/rustc_session/src/config.rs
Lines 1415 to 1426 in 6cf853c
// Symbols are inserted in alphabetical order as much as possible. | |
// The exceptions are where control flow forces things out of order. | |
// | |
// NOTE: This should be kept in sync with `default_configuration`. | |
// Note that symbols inserted conditionally in `default_configuration` | |
// are inserted unconditionally here. | |
// | |
// When adding a new config here you should also update | |
// `tests/ui/check-cfg/well-known-values.rs`. | |
// | |
// Don't forget to update `src/doc/unstable-book/src/compiler-flags/check-cfg.md` | |
// in the unstable book as well! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like you told me that the previous state here is buggy. Why did the tests pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't currently sanity check that default_configuration
and CheckCfg::fill_well_known
are synced; we should probably do that, but it's non-trivial.
We rely on them being (manually) synced.
We also don't currently automatically enable check-cfg in compiletest, that's why CI doesn't fail. (I will send a PR to enable it by default)
Btw I don't see the cfg added in tests/ui/check-cfg/well-known-values.rs
nor do I see the documentation being updated at src/doc/unstable-book/src/compiler-flags/check-cfg.md
.
You will also need to bless the tests/ui/check-cfg/
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. All the check-cfg changes look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for maintaining check-cfg. It's a great feature.
420414f
to
6edde24
Compare
This comment has been minimized.
This comment has been minimized.
Some changes occurred in tests/ui/check-cfg cc @Urgau |
Some changes occurred in src/doc/unstable-book/src/compiler-flags/check-cfg.md cc @Urgau |
…ements, r=wesleywiser Improve cfg and check-cfg configuration This PR improves cfg and check-cfg configuration by: 1. Extracting both logic under a common module (to improve the connection between the two) 2. Adding more documentation, in particular some steps when adding a new cfg I also added my-self as mention in our triagebot conf for the new module. Inspired by rust-lang#123411 (comment)
Rollup merge of rust-lang#123519 - Urgau:session-cfg-check-cfg-improvements, r=wesleywiser Improve cfg and check-cfg configuration This PR improves cfg and check-cfg configuration by: 1. Extracting both logic under a common module (to improve the connection between the two) 2. Adding more documentation, in particular some steps when adding a new cfg I also added my-self as mention in our triagebot conf for the new module. Inspired by rust-lang#123411 (comment)
☔ The latest upstream changes (presumably #123540) made this pull request unmergeable. Please resolve the merge conflicts. |
Some changes occurred in cfg and check-cfg configuration cc @Urgau |
@bors r=Urgau,RalfJung |
Put checks that detect UB under their own flag below debug_assertions Implementation of rust-lang/compiler-team#725
…llaumeGomez Rollup of 4 pull requests Successful merges: - rust-lang#119224 (Drop panic hook after running tests) - rust-lang#123411 (Put checks that detect UB under their own flag below debug_assertions) - rust-lang#123446 (Fix incorrect 'llvm_target' value used on watchOS target) - rust-lang#123516 (Do not ICE on field access check on expr with `ty::Error`) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#119224 (Drop panic hook after running tests) - rust-lang#123411 (Put checks that detect UB under their own flag below debug_assertions) - rust-lang#123516 (Do not ICE on field access check on expr with `ty::Error`) - rust-lang#123522 (Stabilize const Atomic*::into_inner) - rust-lang#123559 (Add a debug asserts call to match_projection_projections to ensure invariant) - rust-lang#123563 (Rewrite `version` test run-make as an UI test) Failed merges: - rust-lang#123569 (Move some tests) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#123411 - saethlin:ub-checks, r=Urgau,RalfJung Put checks that detect UB under their own flag below debug_assertions Implementation of rust-lang/compiler-team#725
Implementation of rust-lang/compiler-team#725
Tracking issue: #123499