about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHans Kratz <hans@appfour.com>2021-08-05 05:28:40 +0000
committerHans Kratz <hans@appfour.com>2021-08-06 14:03:53 +0200
commit2f7095389d70d3a677d3eb61821e26affe4f92ce (patch)
treec489759d71787ca6d6c530c60d16e3920a0aea4f
parent49ca3d9796030fc0a85089460e9f825ceecc08ed (diff)
downloadrust-2f7095389d70d3a677d3eb61821e26affe4f92ce.tar.gz
rust-2f7095389d70d3a677d3eb61821e26affe4f92ce.zip
Add options for enabling overflow checks in rustc and std.
The options are `overflow-checks` and `overflow-checks-std`
defaulting to false.
-rw-r--r--src/bootstrap/CHANGELOG.md1
-rw-r--r--src/bootstrap/builder.rs8
-rw-r--r--src/bootstrap/config.rs10
-rwxr-xr-xsrc/bootstrap/configure.py1
4 files changed, 20 insertions, 0 deletions
diff --git a/src/bootstrap/CHANGELOG.md b/src/bootstrap/CHANGELOG.md
index 8437a10426b..2f99e36aef2 100644
--- a/src/bootstrap/CHANGELOG.md
+++ b/src/bootstrap/CHANGELOG.md
@@ -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
 
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index f2d841cb335..34708fb0816 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -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
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index fdddc1dbbaf..dd536cb7b02 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -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,
@@ -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>,
@@ -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;
@@ -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;
@@ -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);
 
         config.rust_debug_logging = debug_logging.unwrap_or(config.rust_debug_assertions);
 
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index a1941efb562..fd148d14478 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -75,6 +75,7 @@ o("optimize-llvm", "llvm.optimize", "build optimized LLVM")
 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")