diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-04-07 00:51:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-07 00:51:25 +0200 |
| commit | 84dca1503e5268bd8a30a46576cff7b7541154eb (patch) | |
| tree | b2d341dbd4ed3364939e1014132b91bb617cdd4e /tests/codegen | |
| parent | 0ea427025b6fc8ea38e4385c448c1f2f8d781782 (diff) | |
| parent | a7912cb421db4f4039048cdba2b7fc98ae295342 (diff) | |
| download | rust-84dca1503e5268bd8a30a46576cff7b7541154eb.tar.gz rust-84dca1503e5268bd8a30a46576cff7b7541154eb.zip | |
Rollup merge of #123411 - saethlin:ub-checks, r=Urgau,RalfJung
Put checks that detect UB under their own flag below debug_assertions Implementation of https://github.com/rust-lang/compiler-team/issues/725
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/ub-checks.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/codegen/ub-checks.rs b/tests/codegen/ub-checks.rs new file mode 100644 index 00000000000..de48d74e652 --- /dev/null +++ b/tests/codegen/ub-checks.rs @@ -0,0 +1,28 @@ +// With -Zub-checks=yes (enabled by default by -Cdebug-assertions=yes) we will produce a runtime +// check that the index to slice::get_unchecked is in-bounds of the slice. That is tested for by +// tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs +// +// This test ensures that such a runtime check is *not* emitted when debug-assertions are enabled, +// but ub-checks are explicitly disabled. + +//@ revisions: DEBUG NOCHECKS +//@ [DEBUG] compile-flags: +//@ [NOCHECKS] compile-flags: -Zub-checks=no +//@ compile-flags: -O -Cdebug-assertions=yes + +#![crate_type = "lib"] + +use std::ops::Range; + +// CHECK-LABEL: @slice_get_unchecked( +#[no_mangle] +pub unsafe fn slice_get_unchecked(x: &[i32], i: usize) -> &i32 { + // CHECK: icmp ult + // NOCHECKS: tail call void @llvm.assume + // DEBUG: br i1 + // DEBUG: call core::panicking::panic_nounwind + // DEBUG: unreachable + // CHECK: getelementptr inbounds + // CHECK: ret ptr + x.get_unchecked(i) +} |
