about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2025-01-11 22:30:30 +0000
committerTrevor Gross <t.gross35@gmail.com>2025-01-11 20:35:30 -0500
commit5c94cce6b2912d1d325d0d863195a6ea37e41503 (patch)
treefae38721a61a064165a9963bb47ac78f6c5c901d /library
parent721960c17244975f65f6b542e39a00d04807728e (diff)
downloadrust-5c94cce6b2912d1d325d0d863195a6ea37e41503.tar.gz
rust-5c94cce6b2912d1d325d0d863195a6ea37e41503.zip
Add a `release-checked` profile with debug and overflow assertions
A failing debug assertion or overflow without correctly wrapping or
saturating is a bug, but the `debug` profile that has these enabled does
not run enough test cases to hit edge cases that may trigger these. Add
a new `release-checked` profile that enables debug assertions and
overflow checks. This seems to only extend per-function test time by a
few seconds (or around a minute on longer extensive tests), so enable
this as the default on CI.

In order to ensure `no_panic` still gets checked, add a build-only step
to CI.
Diffstat (limited to 'library')
-rw-r--r--library/compiler-builtins/libm/.github/workflows/main.yml3
-rw-r--r--library/compiler-builtins/libm/Cargo.toml7
-rw-r--r--library/compiler-builtins/libm/build.rs6
-rwxr-xr-xlibrary/compiler-builtins/libm/ci/run.sh8
4 files changed, 19 insertions, 5 deletions
diff --git a/library/compiler-builtins/libm/.github/workflows/main.yml b/library/compiler-builtins/libm/.github/workflows/main.yml
index 320800f2ea7..98505ea35c5 100644
--- a/library/compiler-builtins/libm/.github/workflows/main.yml
+++ b/library/compiler-builtins/libm/.github/workflows/main.yml
@@ -238,7 +238,8 @@ jobs:
 
           LIBM_EXTENSIVE_TESTS="$CHANGED" cargo t \
             --features test-multiprecision,unstable \
-            --release -- extensive
+            --profile release-checked \
+            -- extensive
       - name: Print test logs if available
         run: if [ -f "target/test-log.txt" ]; then cat target/test-log.txt; fi
         shell: bash
diff --git a/library/compiler-builtins/libm/Cargo.toml b/library/compiler-builtins/libm/Cargo.toml
index dc362779e84..0e444b5834f 100644
--- a/library/compiler-builtins/libm/Cargo.toml
+++ b/library/compiler-builtins/libm/Cargo.toml
@@ -61,3 +61,10 @@ no-panic = "0.1.30"
 # This is needed for no-panic to correctly detect the lack of panics
 [profile.release]
 lto = "fat"
+
+# Release mode with debug assertions
+[profile.release-checked]
+inherits = "release"
+debug-assertions = true
+lto = "fat"
+overflow-checks = true
diff --git a/library/compiler-builtins/libm/build.rs b/library/compiler-builtins/libm/build.rs
index 9c9e0e72328..ca4a639a12a 100644
--- a/library/compiler-builtins/libm/build.rs
+++ b/library/compiler-builtins/libm/build.rs
@@ -13,8 +13,12 @@ fn main() {
     #[allow(unexpected_cfgs)]
     if !cfg!(feature = "checked") {
         let lvl = env::var("OPT_LEVEL").unwrap();
-        if lvl != "0" {
+        if lvl != "0" && !cfg!(debug_assertions) {
             println!("cargo:rustc-cfg=assert_no_panic");
+        } else if env::var("ENSURE_NO_PANIC").is_ok() {
+            // Give us a defensive way of ensureing that no-panic is checked  when we
+            // expect it to be.
+            panic!("`assert_no_panic `was not enabled");
         }
     }
 
diff --git a/library/compiler-builtins/libm/ci/run.sh b/library/compiler-builtins/libm/ci/run.sh
index 89c9c86315f..244a22a076d 100755
--- a/library/compiler-builtins/libm/ci/run.sh
+++ b/library/compiler-builtins/libm/ci/run.sh
@@ -81,8 +81,10 @@ else
     $cmd --features unstable-intrinsics --benches
     
     # Test the same in release mode, which also increases coverage.
-    $cmd --release
-    $cmd --release --features unstable-intrinsics
-    $cmd --release --features unstable-intrinsics --benches
+    $cmd --profile release-checked 
+    $cmd --profile release-checked --features unstable-intrinsics
+    $cmd --profile release-checked --features unstable-intrinsics --benches
+
+    ENSURE_NO_PANIC=1 cargo build --target "$target" --release
 fi