Skip to content

Add config.toml options for enabling overflow checks in rustc and std #87784

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bootstrap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- `llvm-libunwind` now accepts `in-tree` (formerly true), `system` or `no` (formerly false) [#77703](https://github.com/rust-lang/rust/pull/77703)
- The options `infodir`, `localstatedir`, and `gpg-password-file` are no longer allowed in config.toml. Previously, they were ignored without warning. Note that `infodir` and `localstatedir` are still accepted by `./configure`, with a warning. [#82451](https://github.com/rust-lang/rust/pull/82451)
- Add options for enabling overflow checks, one for std (`overflow-checks-std`) and one for everything else (`overflow-checks`). Both default to false.

### Non-breaking changes

Expand Down
8 changes: 8 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,14 @@ impl<'a> Builder<'a> {
self.config.rust_debug_assertions.to_string()
},
);
cargo.env(
profile_var("OVERFLOW_CHECKS"),
if mode == Mode::Std {
self.config.rust_overflow_checks_std.to_string()
} else {
self.config.rust_overflow_checks.to_string()
},
);

// `dsymutil` adds time to builds on Apple platforms for no clear benefit, and also makes
// it more difficult for debuggers to find debug info. The compiler currently defaults to
Expand Down
10 changes: 10 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub struct Config {
pub rust_codegen_units_std: Option<u32>,
pub rust_debug_assertions: bool,
pub rust_debug_assertions_std: bool,
pub rust_overflow_checks: bool,
pub rust_overflow_checks_std: bool,
pub rust_debug_logging: bool,
pub rust_debuginfo_level_rustc: u32,
pub rust_debuginfo_level_std: u32,
Expand Down Expand Up @@ -473,6 +475,8 @@ struct Rust {
codegen_units_std: Option<u32>,
debug_assertions: Option<bool>,
debug_assertions_std: Option<bool>,
overflow_checks: Option<bool>,
overflow_checks_std: Option<bool>,
debug_logging: Option<bool>,
debuginfo_level: Option<u32>,
debuginfo_level_rustc: Option<u32>,
Expand Down Expand Up @@ -710,6 +714,8 @@ impl Config {
let mut debug = None;
let mut debug_assertions = None;
let mut debug_assertions_std = None;
let mut overflow_checks = None;
let mut overflow_checks_std = None;
let mut debug_logging = None;
let mut debuginfo_level = None;
let mut debuginfo_level_rustc = None;
Expand Down Expand Up @@ -831,6 +837,8 @@ impl Config {
debug = rust.debug;
debug_assertions = rust.debug_assertions;
debug_assertions_std = rust.debug_assertions_std;
overflow_checks = rust.overflow_checks;
overflow_checks_std = rust.overflow_checks_std;
debug_logging = rust.debug_logging;
debuginfo_level = rust.debuginfo_level;
debuginfo_level_rustc = rust.debuginfo_level_rustc;
Expand Down Expand Up @@ -968,6 +976,8 @@ impl Config {
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
config.rust_debug_assertions_std =
debug_assertions_std.unwrap_or(config.rust_debug_assertions);
config.rust_overflow_checks = overflow_checks.unwrap_or(default);
config.rust_overflow_checks_std = overflow_checks_std.unwrap_or(default);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be .unwrap_or(rust_overflow_checks)? Otherwise overflow_checks = true won't actually enable it for the standard library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just noticed that too while working on #89776. It would be more in line with how rust_debug_assertions and rust_debug_assertions_std behave.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will put that and the stuff missing from config.toml.example and configure.py into a followup PR.


config.rust_debug_logging = debug_logging.unwrap_or(config.rust_debug_assertions);

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def v(*args):
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
o("overflow-checks", "rust.overflow-checks", "build with overflow checks")
o("llvm-release-debuginfo", "llvm.release-debuginfo", "build LLVM with debugger metadata")
v("debuginfo-level", "rust.debuginfo-level", "debuginfo level for Rust code")
v("debuginfo-level-rustc", "rust.debuginfo-level-rustc", "debuginfo level for the compiler")
Expand Down