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

Put checks that detect UB under their own flag below debug_assertions #123411

Merged
merged 1 commit into from
Apr 7, 2024

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Apr 3, 2024

Implementation of rust-lang/compiler-team#725

Tracking issue: #123499

@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 Apr 3, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 3, 2024

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

Comment on lines 17 to 21
// CHECK-NEXT: start:
// CHECK-NEXT: icmp ult
// CHECK-NEXT: tail call void @llvm.assume
// CHECK-NEXT: getelementptr inbounds
// CHECK-NEXT: ret ptr
Copy link
Member Author

@saethlin saethlin Apr 3, 2024

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.

Copy link
Member

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:

//@ 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?

src/tools/miri/src/lib.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

RalfJung commented Apr 3, 2024

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 3, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 3, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@saethlin
Copy link
Member Author

saethlin commented Apr 3, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 3, 2024
@@ -1236,6 +1236,10 @@ fn default_configuration(sess: &Session) -> Cfg {
ins_none!(sym::overflow_checks);
}

if sess.ub_checks() {
ins_none!(sym::ub_checks);
Copy link
Member

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.

Copy link
Member

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)?

Copy link
Member

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.

Copy link
Member

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

@RalfJung
Copy link
Member

RalfJung commented Apr 4, 2024

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 cfg flag.

r? compiler

@@ -1236,6 +1236,10 @@ fn default_configuration(sess: &Session) -> Cfg {
ins_none!(sym::overflow_checks);
}

if sess.ub_checks() {
ins_none!(sym::ub_checks);
Copy link
Member

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:

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,

// 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!

Copy link
Member Author

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?

Copy link
Member

@Urgau Urgau Apr 5, 2024

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.

Copy link
Member

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.

Copy link
Member Author

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.

@saethlin saethlin force-pushed the ub-checks branch 2 times, most recently from 420414f to 6edde24 Compare April 5, 2024 18:25
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Apr 5, 2024

Some changes occurred in tests/ui/check-cfg

cc @Urgau

@rustbot
Copy link
Collaborator

rustbot commented Apr 5, 2024

Some changes occurred in src/doc/unstable-book/src/compiler-flags/check-cfg.md

cc @Urgau

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 5, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 6, 2024
…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)
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 6, 2024
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)
@bors
Copy link
Contributor

bors commented Apr 6, 2024

☔ The latest upstream changes (presumably #123540) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 6, 2024

Some changes occurred in cfg and check-cfg configuration

cc @Urgau

@saethlin
Copy link
Member Author

saethlin commented Apr 6, 2024

@bors r=Urgau,RalfJung

@bors
Copy link
Contributor

bors commented Apr 6, 2024

📌 Commit a7912cb has been approved by Urgau,RalfJung

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 6, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Apr 6, 2024
Put checks that detect UB under their own flag below debug_assertions

Implementation of rust-lang/compiler-team#725
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 6, 2024
…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
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 7, 2024
…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
@bors bors merged commit 84dca15 into rust-lang:master Apr 7, 2024
11 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 7, 2024
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
@saethlin saethlin deleted the ub-checks branch April 7, 2024 02:14
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.

Put "checks that detect UB" under their own flag below debug_assertions
8 participants