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

Different behavior for --cfg debug_assertions versus -C debug_assertions #116673

Open
WesleyRosenblum opened this issue Oct 12, 2023 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WesleyRosenblum
Copy link

The following two commands have different behavior:

  1. RUSTFLAGS="--cfg debug_assertions" cargo run --release
  2. RUSTFLAGS="-C debug_assertions" cargo run --release

1 does not enable integer overflow checks (and alignment checks), while 2 does. The rustc Codegen docs that mention "overflow checks are enabled if debug-assertions are enabled, disabled otherwise", do not apply to the --cfg debug_assertions version.

This can be tested using this small program:

fn subtract(input: u64) -> u64 {
    0 - input
}

pub fn main() {
    let result = subtract(5);
    debug_assert_ne!(result, 18446744073709551611);
}
$ RUSTFLAGS="--cfg debug_assertions" cargo run --release 
thread 'main' panicked at 'assertion failed: `(left != right)`
  left: `18446744073709551611`,
 right: `18446744073709551611`', src/main.rs:7:5

$ RUSTFLAGS="-C debug_assertions" cargo run --release 
thread 'main' panicked at 'attempt to subtract with overflow', src/main.rs:2:5

I'm not sure if this just needs a documentation update, or something more substantial like prohibiting usage of --cfg debug_assertions without also setting -C debug_assertions (à la rust-lang/compiler-team#610). Either way, it seems like a sharp edge that could trip people up.

@WesleyRosenblum WesleyRosenblum added the C-bug Category: This is a bug. label Oct 12, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 12, 2023
@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants