From 5e6da720f621308a0f44e7c6bbd13a9fad68b240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 22 Feb 2024 06:15:55 +0000 Subject: [PATCH 1/8] Account for RPITIT in E0310 explicit lifetime constraint suggestion When given ```rust trait Original { fn f() -> impl Fn(); } trait Erased { fn f(&self) -> Box; } impl Erased for T { fn f(&self) -> Box { Box::new(::f()) } } ``` avoid suggestion to restrict the `Trait::{opaque}` type in a `where` clause: ``` error[E0310]: the associated type `::{opaque#0}` may not live long enough --> $DIR/missing-static-bound-from-impl.rs:11:9 | LL | Box::new(::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | the associated type `::{opaque#0}` must be valid for the static lifetime... | ...so that the type `impl Fn()` will meet its required lifetime bounds ``` CC #119773. --- .../rustc_infer/src/infer/error_reporting/mod.rs | 8 ++++++++ .../impl-trait/in-trait/async-and-ret-ref.stderr | 2 -- .../in-trait/missing-static-bound-from-impl.rs | 16 ++++++++++++++++ .../missing-static-bound-from-impl.stderr | 12 ++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs create mode 100644 tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 505d56cf4917..470b97b77783 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2434,6 +2434,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let suggestion = if has_lifetimes { format!(" + {lt_name}") } else { format!(": {lt_name}") }; suggs.push((sp, suggestion)) + } else if let GenericKind::Alias(ref p) = bound_kind + && let ty::Projection = p.kind(self.tcx) + && let DefKind::AssocTy = self.tcx.def_kind(p.def_id) + && let Some(ty::ImplTraitInTraitData::Trait { .. }) = + self.tcx.opt_rpitit_info(p.def_id) + { + // The lifetime found in the `impl` is longer than the one on the RPITIT. + // Do not suggest `::{opaque}: 'static`. } else if let Some(generics) = self.tcx.hir().get_generics(suggestion_scope) { let pred = format!("{bound_kind}: {lt_name}"); let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred); diff --git a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr index 79a86b0a3aed..15aa3cf54bbe 100644 --- a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr +++ b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr @@ -6,8 +6,6 @@ LL | async fn foo() -> &'static impl T; | | | the associated type `::{opaque#0}` must be valid for the static lifetime... | ...so that the reference type `&'static impl T` does not outlive the data it points at - | - = help: consider adding an explicit lifetime bound `::{opaque#0}: 'static`... error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs new file mode 100644 index 000000000000..a36799c3ebd4 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs @@ -0,0 +1,16 @@ +trait Original { + fn f() -> impl Fn(); +} + +trait Erased { + fn f(&self) -> Box; +} + +impl Erased for T { + fn f(&self) -> Box { + Box::new(::f()) + //~^ ERROR the associated type `::{opaque#0}` may not live long enough + } +} + +fn main () {} diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr new file mode 100644 index 000000000000..5ec0ee38347a --- /dev/null +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr @@ -0,0 +1,12 @@ +error[E0310]: the associated type `::{opaque#0}` may not live long enough + --> $DIR/missing-static-bound-from-impl.rs:11:9 + | +LL | Box::new(::f()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the associated type `::{opaque#0}` must be valid for the static lifetime... + | ...so that the type `impl Fn()` will meet its required lifetime bounds + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0310`. From 62cb9d1a978a760dad4f56951922b8b533c98d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 23 Feb 2024 19:07:42 +0100 Subject: [PATCH 2/8] delay cloning of iterator items --- .../src/traits/coherence.rs | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 3619d02438da..ac0685994eab 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -320,22 +320,25 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>( let mut errors = fulfill_cx.select_where_possible(infcx); errors.pop().map(|err| err.obligation) } else { - obligations.iter().cloned().find(|obligation| { - // We use `evaluate_root_obligation` to correctly track intercrate - // ambiguity clauses. We cannot use this in the new solver. - let evaluation_result = selcx.evaluate_root_obligation(obligation); + obligations + .iter() + .find(|obligation| { + // We use `evaluate_root_obligation` to correctly track intercrate + // ambiguity clauses. We cannot use this in the new solver. + let evaluation_result = selcx.evaluate_root_obligation(obligation); - match evaluation_result { - Ok(result) => !result.may_apply(), - // If overflow occurs, we need to conservatively treat the goal as possibly holding, - // since there can be instantiations of this goal that don't overflow and result in - // success. This isn't much of a problem in the old solver, since we treat overflow - // fatally (this still can be encountered: ), - // but in the new solver, this is very important for correctness, since overflow - // *must* be treated as ambiguity for completeness. - Err(_overflow) => false, - } - }) + match evaluation_result { + Ok(result) => !result.may_apply(), + // If overflow occurs, we need to conservatively treat the goal as possibly holding, + // since there can be instantiations of this goal that don't overflow and result in + // success. This isn't much of a problem in the old solver, since we treat overflow + // fatally (this still can be encountered: ), + // but in the new solver, this is very important for correctness, since overflow + // *must* be treated as ambiguity for completeness. + Err(_overflow) => false, + } + }) + .cloned() } } From 8e0dd993d63d179402b0f5330aadfe589069b387 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 23 Feb 2024 19:22:27 +0100 Subject: [PATCH 3/8] check that simd_insert/extract indices are in-bounds --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 53 ++++++++++++------- compiler/rustc_codegen_ssa/messages.ftl | 6 +-- compiler/rustc_codegen_ssa/src/errors.rs | 12 +---- ...-out-of-bounds.rs => not-out-of-bounds.rs} | 15 +++--- ...bounds.stderr => not-out-of-bounds.stderr} | 42 +++++++++------ 5 files changed, 73 insertions(+), 55 deletions(-) rename tests/ui/simd/{shuffle-not-out-of-bounds.rs => not-out-of-bounds.rs} (88%) rename tests/ui/simd/{shuffle-not-out-of-bounds.stderr => not-out-of-bounds.stderr} (71%) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 23e6f054a7c1..1eac2157cac3 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -1079,7 +1079,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( .map(|(arg_idx, val)| { let idx = val.unwrap_leaf().try_to_i32().unwrap(); if idx >= i32::try_from(total_len).unwrap() { - bx.sess().dcx().emit_err(InvalidMonomorphization::ShuffleIndexOutOfBounds { + bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds { span, name, arg_idx: arg_idx as u64, @@ -1138,24 +1138,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>( let val = bx.const_get_elt(vector, i as u64); match bx.const_to_opt_u128(val, true) { None => { - bx.sess().dcx().emit_err( - InvalidMonomorphization::ShuffleIndexNotConstant { - span, - name, - arg_idx, - }, - ); - None + bug!("typeck should have already ensured that these are const") } Some(idx) if idx >= total_len => { - bx.sess().dcx().emit_err( - InvalidMonomorphization::ShuffleIndexOutOfBounds { - span, - name, - arg_idx, - total_len, - }, - ); + bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds { + span, + name, + arg_idx, + total_len, + }); None } Some(idx) => Some(bx.const_i32(idx as i32)), @@ -1184,10 +1175,22 @@ fn generic_simd_intrinsic<'ll, 'tcx>( out_ty: arg_tys[2] } ); + let idx = bx + .const_to_opt_u128(args[1].immediate(), false) + .expect("typeck should have ensure that this is a const"); + if idx >= in_len.into() { + bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds { + span, + name, + arg_idx: 1, + total_len: in_len.into(), + }); + return Ok(bx.const_null(llret_ty)); + } return Ok(bx.insert_element( args[0].immediate(), args[2].immediate(), - args[1].immediate(), + bx.const_i32(idx as i32), )); } if name == sym::simd_extract { @@ -1195,7 +1198,19 @@ fn generic_simd_intrinsic<'ll, 'tcx>( ret_ty == in_elem, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty } ); - return Ok(bx.extract_element(args[0].immediate(), args[1].immediate())); + let idx = bx + .const_to_opt_u128(args[1].immediate(), false) + .expect("typeck should have ensure that this is a const"); + if idx >= in_len.into() { + bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds { + span, + name, + arg_idx: 1, + total_len: in_len.into(), + }); + return Ok(bx.const_null(llret_ty)); + } + return Ok(bx.extract_element(args[0].immediate(), bx.const_i32(idx as i32))); } if name == sym::simd_select { diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index fa7719d89716..5ba66d1be432 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -106,14 +106,12 @@ codegen_ssa_invalid_monomorphization_return_type = invalid monomorphization of ` codegen_ssa_invalid_monomorphization_second_argument_length = invalid monomorphization of `{$name}` intrinsic: expected second argument with length {$in_len} (same as input type `{$in_ty}`), found `{$arg_ty}` with length {$out_len} -codegen_ssa_invalid_monomorphization_shuffle_index_not_constant = invalid monomorphization of `{$name}` intrinsic: shuffle index #{$arg_idx} is not a constant - -codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds = invalid monomorphization of `{$name}` intrinsic: shuffle index #{$arg_idx} is out of bounds (limit {$total_len}) - codegen_ssa_invalid_monomorphization_simd_argument = invalid monomorphization of `{$name}` intrinsic: expected SIMD argument type, found non-SIMD `{$ty}` codegen_ssa_invalid_monomorphization_simd_first = invalid monomorphization of `{$name}` intrinsic: expected SIMD first type, found non-SIMD `{$ty}` +codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds = invalid monomorphization of `{$name}` intrinsic: SIMD index #{$arg_idx} is out of bounds (limit {$total_len}) + codegen_ssa_invalid_monomorphization_simd_input = invalid monomorphization of `{$name}` intrinsic: expected SIMD input type, found non-SIMD `{$ty}` codegen_ssa_invalid_monomorphization_simd_return = invalid monomorphization of `{$name}` intrinsic: expected SIMD return type, found non-SIMD `{$ty}` diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index e42a8bd9ed98..a7ac502b2483 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -797,16 +797,8 @@ pub enum InvalidMonomorphization<'tcx> { out_ty: Ty<'tcx>, }, - #[diag(codegen_ssa_invalid_monomorphization_shuffle_index_not_constant, code = E0511)] - ShuffleIndexNotConstant { - #[primary_span] - span: Span, - name: Symbol, - arg_idx: u64, - }, - - #[diag(codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds, code = E0511)] - ShuffleIndexOutOfBounds { + #[diag(codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds, code = E0511)] + SimdIndexOutOfBounds { #[primary_span] span: Span, name: Symbol, diff --git a/tests/ui/simd/shuffle-not-out-of-bounds.rs b/tests/ui/simd/not-out-of-bounds.rs similarity index 88% rename from tests/ui/simd/shuffle-not-out-of-bounds.rs rename to tests/ui/simd/not-out-of-bounds.rs index 158e9956435d..36d7a5865bc5 100644 --- a/tests/ui/simd/shuffle-not-out-of-bounds.rs +++ b/tests/ui/simd/not-out-of-bounds.rs @@ -1,6 +1,6 @@ //@ build-fail #![allow(non_camel_case_types)] -#![feature(repr_simd, platform_intrinsics)] +#![feature(repr_simd, core_intrinsics)] // Test for #73542 to verify out-of-bounds shuffle vectors do not compile. @@ -28,9 +28,7 @@ struct u8x32([u8; 32]); #[derive(Copy, Clone)] struct u8x64([u8; 64]); -extern "platform-intrinsic" { - pub fn simd_shuffle(x: T, y: T, idx: I) -> U; -} +use std::intrinsics::simd::*; // Test vectors by lane size. Since LLVM does not distinguish between a shuffle // over two f32s and a shuffle over two u64s, or any other such combination, @@ -70,13 +68,16 @@ fn main() { test_shuffle_lanes!(32, u8x32, simd_shuffle); test_shuffle_lanes!(64, u8x64, simd_shuffle); - extern "platform-intrinsic" { - fn simd_shuffle(a: T, b: T, i: I) -> U; - } let v = u8x2([0, 0]); const I: [u32; 2] = [4, 4]; unsafe { let _: u8x2 = simd_shuffle(v, v, I); //~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic } + + // also check insert/extract + unsafe { + simd_insert(v, 2, 0); //~ ERROR invalid monomorphization of `simd_insert` intrinsic + let _val: u8 = simd_extract(v, 2); //~ ERROR invalid monomorphization of `simd_extract` intrinsic + } } diff --git a/tests/ui/simd/shuffle-not-out-of-bounds.stderr b/tests/ui/simd/not-out-of-bounds.stderr similarity index 71% rename from tests/ui/simd/shuffle-not-out-of-bounds.stderr rename to tests/ui/simd/not-out-of-bounds.stderr index 59e5ab858664..5682935c1f1a 100644 --- a/tests/ui/simd/shuffle-not-out-of-bounds.stderr +++ b/tests/ui/simd/not-out-of-bounds.stderr @@ -1,5 +1,5 @@ -error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 4) - --> $DIR/shuffle-not-out-of-bounds.rs:51:21 +error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: SIMD index #0 is out of bounds (limit 4) + --> $DIR/not-out-of-bounds.rs:49:21 | LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ @@ -9,8 +9,8 @@ LL | test_shuffle_lanes!(2, u8x2, simd_shuffle); | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 8) - --> $DIR/shuffle-not-out-of-bounds.rs:51:21 +error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: SIMD index #0 is out of bounds (limit 8) + --> $DIR/not-out-of-bounds.rs:49:21 | LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ @@ -20,8 +20,8 @@ LL | test_shuffle_lanes!(4, u8x4, simd_shuffle); | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 16) - --> $DIR/shuffle-not-out-of-bounds.rs:51:21 +error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: SIMD index #0 is out of bounds (limit 16) + --> $DIR/not-out-of-bounds.rs:49:21 | LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ @@ -31,8 +31,8 @@ LL | test_shuffle_lanes!(8, u8x8, simd_shuffle); | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 32) - --> $DIR/shuffle-not-out-of-bounds.rs:51:21 +error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: SIMD index #0 is out of bounds (limit 32) + --> $DIR/not-out-of-bounds.rs:49:21 | LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ @@ -42,8 +42,8 @@ LL | test_shuffle_lanes!(16, u8x16, simd_shuffle); | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 64) - --> $DIR/shuffle-not-out-of-bounds.rs:51:21 +error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: SIMD index #0 is out of bounds (limit 64) + --> $DIR/not-out-of-bounds.rs:49:21 | LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ @@ -53,8 +53,8 @@ LL | test_shuffle_lanes!(32, u8x32, simd_shuffle); | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 128) - --> $DIR/shuffle-not-out-of-bounds.rs:51:21 +error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: SIMD index #0 is out of bounds (limit 128) + --> $DIR/not-out-of-bounds.rs:49:21 | LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ @@ -64,12 +64,24 @@ LL | test_shuffle_lanes!(64, u8x64, simd_shuffle); | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 4) - --> $DIR/shuffle-not-out-of-bounds.rs:79:23 +error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: SIMD index #0 is out of bounds (limit 4) + --> $DIR/not-out-of-bounds.rs:74:23 | LL | let _: u8x2 = simd_shuffle(v, v, I); | ^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 7 previous errors +error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected inserted type `u8` (element of input `u8x2`), found `i32` + --> $DIR/not-out-of-bounds.rs:80:9 + | +LL | simd_insert(v, 2, 0); + | ^^^^^^^^^^^^^^^^^^^^ + +error[E0511]: invalid monomorphization of `simd_extract` intrinsic: SIMD index #1 is out of bounds (limit 2) + --> $DIR/not-out-of-bounds.rs:81:24 + | +LL | let _val: u8 = simd_extract(v, 2); + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0511`. From 134e2b2056d3d5519dc3b294ceb1558cf7af276c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 23 Feb 2024 19:34:17 +0100 Subject: [PATCH 4/8] interpret: do no ICE on OOB shuffle/insert/extract indices --- .../src/interpret/intrinsics.rs | 20 +++++++++++-------- src/tools/miri/src/shims/intrinsics/simd.rs | 10 ++++------ .../tests/fail/intrinsics/simd-extract.rs | 8 ++++++++ .../tests/fail/intrinsics/simd-extract.stderr | 15 ++++++++++++++ 4 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/tools/miri/tests/fail/intrinsics/simd-extract.rs create mode 100644 src/tools/miri/tests/fail/intrinsics/simd-extract.stderr diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index f020616f6d8c..1cb991b38f7e 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -379,10 +379,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let (input, input_len) = self.operand_to_simd(&args[0])?; let (dest, dest_len) = self.place_to_simd(dest)?; assert_eq!(input_len, dest_len, "Return vector length must match input length"); - assert!( - index < dest_len, - "Index `{index}` must be in bounds of vector with length {dest_len}" - ); + // Bounds are not checked by typeck so we have to do it ourselves. + if index >= input_len { + throw_ub_format!( + "`simd_insert` index {index} is out-of-bounds of vector with length {input_len}" + ); + } for i in 0..dest_len { let place = self.project_index(&dest, i)?; @@ -397,10 +399,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { sym::simd_extract => { let index = u64::from(self.read_scalar(&args[1])?.to_u32()?); let (input, input_len) = self.operand_to_simd(&args[0])?; - assert!( - index < input_len, - "index `{index}` must be in bounds of vector with length {input_len}" - ); + // Bounds are not checked by typeck so we have to do it ourselves. + if index >= input_len { + throw_ub_format!( + "`simd_extract` index {index} is out-of-bounds of vector with length {input_len}" + ); + } self.copy_op(&self.project_index(&input, index)?, dest)?; } sym::likely | sym::unlikely | sym::black_box => { diff --git a/src/tools/miri/src/shims/intrinsics/simd.rs b/src/tools/miri/src/shims/intrinsics/simd.rs index ea2d104694af..ca8773cac14b 100644 --- a/src/tools/miri/src/shims/intrinsics/simd.rs +++ b/src/tools/miri/src/shims/intrinsics/simd.rs @@ -563,9 +563,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let right_idx = src_index.checked_sub(left_len).unwrap(); this.read_immediate(&this.project_index(&right, right_idx)?)? } else { - span_bug!( - this.cur_span(), - "simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}", + throw_ub_format!( + "`simd_shuffle_generic` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}" ); }; this.write_immediate(*val, &dest)?; @@ -604,9 +603,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let right_idx = src_index.checked_sub(left_len).unwrap(); this.read_immediate(&this.project_index(&right, right_idx)?)? } else { - span_bug!( - this.cur_span(), - "simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}", + throw_ub_format!( + "`simd_shuffle` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}" ); }; this.write_immediate(*val, &dest)?; diff --git a/src/tools/miri/tests/fail/intrinsics/simd-extract.rs b/src/tools/miri/tests/fail/intrinsics/simd-extract.rs new file mode 100644 index 000000000000..02b9d30df5e9 --- /dev/null +++ b/src/tools/miri/tests/fail/intrinsics/simd-extract.rs @@ -0,0 +1,8 @@ +#![feature(portable_simd, core_intrinsics)] +use std::simd::*; + +fn main() { + let v = i32x4::splat(0); + let _x: i32 = unsafe { std::intrinsics::simd::simd_extract(v, 4) }; + //~^ERROR: index 4 is out-of-bounds +} diff --git a/src/tools/miri/tests/fail/intrinsics/simd-extract.stderr b/src/tools/miri/tests/fail/intrinsics/simd-extract.stderr new file mode 100644 index 000000000000..dc6b22de4925 --- /dev/null +++ b/src/tools/miri/tests/fail/intrinsics/simd-extract.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: `simd_extract` index 4 is out-of-bounds of vector with length 4 + --> $DIR/simd-extract.rs:LL:CC + | +LL | let _x: i32 = unsafe { std::intrinsics::simd::simd_extract(v, 4) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `simd_extract` index 4 is out-of-bounds of vector with length 4 + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/simd-extract.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + From 2f3c0b98593044c00492f4287e27ef9733121c97 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Fri, 23 Feb 2024 18:04:01 -0500 Subject: [PATCH 5/8] Ignore less tests in debug builds --- src/tools/compiletest/src/runtest.rs | 7 +++++-- tests/assembly/option-nonzero-eq.rs | 1 - tests/assembly/slice-is_ascii.rs | 1 - tests/assembly/static-relocation-model.rs | 1 - tests/codegen/align-offset.rs | 1 - tests/codegen/array-map.rs | 1 - tests/codegen/ascii-char.rs | 1 - tests/codegen/binary-search-index-no-bound-check.rs | 1 - tests/codegen/infallible-unwrap-in-opt-z.rs | 1 - tests/codegen/issue-97217.rs | 1 - tests/codegen/issues/issue-101082.rs | 1 - tests/codegen/issues/issue-101814.rs | 1 - tests/codegen/issues/issue-106369.rs | 1 - tests/codegen/issues/issue-116878.rs | 1 - tests/codegen/issues/issue-37945.rs | 1 - tests/codegen/issues/issue-45222.rs | 1 - tests/codegen/issues/issue-45466.rs | 1 - tests/codegen/issues/issue-45964-bounds-check-slice-pos.rs | 1 - tests/codegen/issues/issue-69101-bounds-check.rs | 1 - tests/codegen/issues/issue-73258.rs | 1 - .../issues/issue-73396-bounds-check-after-position.rs | 1 - .../issues/issue-98294-get-mut-copy-from-slice-opt.rs | 1 - tests/codegen/iter-repeat-n-trivial-drop.rs | 1 - tests/codegen/layout-size-checks.rs | 1 - tests/codegen/lib-optimizations/iter-sum.rs | 1 - tests/codegen/mem-replace-big-type.rs | 2 +- tests/codegen/mem-replace-simple-type.rs | 2 +- tests/codegen/ptr-arithmetic.rs | 1 - tests/codegen/ptr-read-metadata.rs | 1 - tests/codegen/simd/simd-wide-sum.rs | 1 - tests/codegen/simd/swap-simd-types.rs | 1 - tests/codegen/slice-as_chunks.rs | 1 - tests/codegen/slice-indexing.rs | 1 - tests/codegen/slice-iter-fold.rs | 1 - tests/codegen/slice-iter-len-eq-zero.rs | 1 - tests/codegen/slice-iter-nonnull.rs | 1 - tests/codegen/slice-ref-equality.rs | 1 - tests/codegen/slice-reverse.rs | 2 +- tests/codegen/slice_as_from_ptr_range.rs | 1 - tests/codegen/swap-large-types.rs | 1 - tests/codegen/swap-small-types.rs | 1 - tests/codegen/transmute-optimized.rs | 1 - tests/codegen/unchecked_shifts.rs | 1 - tests/codegen/unwind-landingpad-inline.rs | 1 - tests/codegen/vec-calloc.rs | 1 - tests/codegen/vec-in-place.rs | 2 +- tests/codegen/vec-iter-collect-len.rs | 1 - tests/codegen/vec-iter.rs | 1 - tests/codegen/vec-optimizes-away.rs | 1 - tests/codegen/vec-reserve-extend.rs | 2 -- tests/codegen/vec-shrink-panik.rs | 2 +- tests/codegen/vec_pop_push_noop.rs | 2 -- tests/codegen/vecdeque-drain.rs | 2 +- tests/codegen/vecdeque-nonempty-get-no-panic.rs | 1 - tests/codegen/vecdeque_no_panic.rs | 2 +- tests/codegen/virtual-function-elimination.rs | 1 - tests/mir-opt/pre-codegen/slice_filter.rs | 1 - ...slice_filter.variant_a-{closure#0}.PreCodegen.after.mir | 2 +- ...slice_filter.variant_b-{closure#0}.PreCodegen.after.mir | 2 +- 59 files changed, 14 insertions(+), 62 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 27a8079d893f..61211a7d6753 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2503,8 +2503,11 @@ impl<'test> TestCx<'test> { // overridden by `compile-flags`. rustc.arg("-Copt-level=2"); } - RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake - | CodegenUnits | JsDocTest | Assembly => { + Assembly | Codegen => { + rustc.arg("-Cdebug-assertions=no"); + } + RunPassValgrind | Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake + | CodegenUnits | JsDocTest => { // do not use JSON output } } diff --git a/tests/assembly/option-nonzero-eq.rs b/tests/assembly/option-nonzero-eq.rs index d6ec586d938b..b04cf63fd783 100644 --- a/tests/assembly/option-nonzero-eq.rs +++ b/tests/assembly/option-nonzero-eq.rs @@ -5,7 +5,6 @@ //@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel //@ only-x86_64 //@ ignore-sgx -//@ ignore-debug use std::cmp::Ordering; diff --git a/tests/assembly/slice-is_ascii.rs b/tests/assembly/slice-is_ascii.rs index 0b7643952149..3a050347d898 100644 --- a/tests/assembly/slice-is_ascii.rs +++ b/tests/assembly/slice-is_ascii.rs @@ -5,7 +5,6 @@ //@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel //@ only-x86_64 //@ ignore-sgx -//@ ignore-debug #![feature(str_internals)] diff --git a/tests/assembly/static-relocation-model.rs b/tests/assembly/static-relocation-model.rs index 975818bf94fb..50527b853451 100644 --- a/tests/assembly/static-relocation-model.rs +++ b/tests/assembly/static-relocation-model.rs @@ -6,7 +6,6 @@ //@ [A64] needs-llvm-components: aarch64 //@ [ppc64le] compile-flags: --target powerpc64le-unknown-linux-gnu -Crelocation-model=static //@ [ppc64le] needs-llvm-components: powerpc -//@ ignore-debug: alignment checks insert panics that we don't have a lang item for #![feature(no_core, lang_items)] #![no_core] diff --git a/tests/codegen/align-offset.rs b/tests/codegen/align-offset.rs index 9819dc209668..15b11f413cb5 100644 --- a/tests/codegen/align-offset.rs +++ b/tests/codegen/align-offset.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug (debug assertions in `slice::from_raw_parts` block optimizations) #![crate_type = "lib"] diff --git a/tests/codegen/array-map.rs b/tests/codegen/array-map.rs index b356f8f33f9f..743a15989f78 100644 --- a/tests/codegen/array-map.rs +++ b/tests/codegen/array-map.rs @@ -1,6 +1,5 @@ //@ compile-flags: -C opt-level=3 -C target-cpu=x86-64-v3 //@ only-x86_64 -//@ ignore-debug (the extra assertions get in the way) #![crate_type = "lib"] diff --git a/tests/codegen/ascii-char.rs b/tests/codegen/ascii-char.rs index 30f285096ed8..fab9f8632fca 100644 --- a/tests/codegen/ascii-char.rs +++ b/tests/codegen/ascii-char.rs @@ -1,5 +1,4 @@ //@ compile-flags: -C opt-level=1 -//@ ignore-debug (the extra assertions get in the way) #![crate_type = "lib"] #![feature(ascii_char)] diff --git a/tests/codegen/binary-search-index-no-bound-check.rs b/tests/codegen/binary-search-index-no-bound-check.rs index d2627d67142f..96f6bb54b3fe 100644 --- a/tests/codegen/binary-search-index-no-bound-check.rs +++ b/tests/codegen/binary-search-index-no-bound-check.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] // Make sure no bounds checks are emitted when slicing or indexing diff --git a/tests/codegen/infallible-unwrap-in-opt-z.rs b/tests/codegen/infallible-unwrap-in-opt-z.rs index cbcba03ad0a9..3756fafe3840 100644 --- a/tests/codegen/infallible-unwrap-in-opt-z.rs +++ b/tests/codegen/infallible-unwrap-in-opt-z.rs @@ -1,5 +1,4 @@ //@ compile-flags: -C opt-level=z --edition=2021 -//@ ignore-debug #![crate_type = "lib"] diff --git a/tests/codegen/issue-97217.rs b/tests/codegen/issue-97217.rs index 93dd1228ce12..a0dfff2ef2eb 100644 --- a/tests/codegen/issue-97217.rs +++ b/tests/codegen/issue-97217.rs @@ -1,5 +1,4 @@ //@ compile-flags: -C opt-level=3 -//@ ignore-debug: the debug assertions get in the way //@ min-llvm-version: 17.0.2 #![crate_type = "lib"] diff --git a/tests/codegen/issues/issue-101082.rs b/tests/codegen/issues/issue-101082.rs index 7c96f9a34f8c..550d267a98fa 100644 --- a/tests/codegen/issues/issue-101082.rs +++ b/tests/codegen/issues/issue-101082.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/issues/issue-101814.rs b/tests/codegen/issues/issue-101814.rs index 6175d80c9cde..e3843e9edb0b 100644 --- a/tests/codegen/issues/issue-101814.rs +++ b/tests/codegen/issues/issue-101814.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/issues/issue-106369.rs b/tests/codegen/issues/issue-106369.rs index 5120c5f4e490..fd375e4e6058 100644 --- a/tests/codegen/issues/issue-106369.rs +++ b/tests/codegen/issues/issue-106369.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug (the extra assertions get in the way) #![crate_type = "lib"] diff --git a/tests/codegen/issues/issue-116878.rs b/tests/codegen/issues/issue-116878.rs index 2c561d7be799..a09fac42c018 100644 --- a/tests/codegen/issues/issue-116878.rs +++ b/tests/codegen/issues/issue-116878.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] /// Make sure no bounds checks are emitted after a `get_unchecked`. diff --git a/tests/codegen/issues/issue-37945.rs b/tests/codegen/issues/issue-37945.rs index 3f750157a818..756a75e2f0ed 100644 --- a/tests/codegen/issues/issue-37945.rs +++ b/tests/codegen/issues/issue-37945.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O -Zmerge-functions=disabled //@ ignore-32bit LLVM has a bug with them -//@ ignore-debug // Check that LLVM understands that `Iter` pointer is not null. Issue #37945. diff --git a/tests/codegen/issues/issue-45222.rs b/tests/codegen/issues/issue-45222.rs index 8fa9d87f4970..d2c1ba421c45 100644 --- a/tests/codegen/issues/issue-45222.rs +++ b/tests/codegen/issues/issue-45222.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/issues/issue-45466.rs b/tests/codegen/issues/issue-45466.rs index 165bc3ca4112..fc714247dfb6 100644 --- a/tests/codegen/issues/issue-45466.rs +++ b/tests/codegen/issues/issue-45466.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type="rlib"] diff --git a/tests/codegen/issues/issue-45964-bounds-check-slice-pos.rs b/tests/codegen/issues/issue-45964-bounds-check-slice-pos.rs index c9bc7fc316e9..b7568bea4d0a 100644 --- a/tests/codegen/issues/issue-45964-bounds-check-slice-pos.rs +++ b/tests/codegen/issues/issue-45964-bounds-check-slice-pos.rs @@ -2,7 +2,6 @@ // prevent optimizing away bounds checks //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type="rlib"] diff --git a/tests/codegen/issues/issue-69101-bounds-check.rs b/tests/codegen/issues/issue-69101-bounds-check.rs index f96a8e9da4b4..c014a1c1b1d4 100644 --- a/tests/codegen/issues/issue-69101-bounds-check.rs +++ b/tests/codegen/issues/issue-69101-bounds-check.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] // Make sure no bounds checks are emitted in the loop when upfront slicing diff --git a/tests/codegen/issues/issue-73258.rs b/tests/codegen/issues/issue-73258.rs index bc71e15a41fe..48f14fe2dfe3 100644 --- a/tests/codegen/issues/issue-73258.rs +++ b/tests/codegen/issues/issue-73258.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug (the extra assertions get in the way) #![crate_type = "lib"] diff --git a/tests/codegen/issues/issue-73396-bounds-check-after-position.rs b/tests/codegen/issues/issue-73396-bounds-check-after-position.rs index db91a85474d2..ef4538ac84e1 100644 --- a/tests/codegen/issues/issue-73396-bounds-check-after-position.rs +++ b/tests/codegen/issues/issue-73396-bounds-check-after-position.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] // Make sure no bounds checks are emitted when slicing or indexing diff --git a/tests/codegen/issues/issue-98294-get-mut-copy-from-slice-opt.rs b/tests/codegen/issues/issue-98294-get-mut-copy-from-slice-opt.rs index 9f65222b3869..40827e32a012 100644 --- a/tests/codegen/issues/issue-98294-get-mut-copy-from-slice-opt.rs +++ b/tests/codegen/issues/issue-98294-get-mut-copy-from-slice-opt.rs @@ -1,4 +1,3 @@ -//@ ignore-debug: The debug assertions get in the way //@ compile-flags: -O #![crate_type = "lib"] diff --git a/tests/codegen/iter-repeat-n-trivial-drop.rs b/tests/codegen/iter-repeat-n-trivial-drop.rs index d0838a3e860d..31020b77984b 100644 --- a/tests/codegen/iter-repeat-n-trivial-drop.rs +++ b/tests/codegen/iter-repeat-n-trivial-drop.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O //@ only-x86_64 -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] #![feature(iter_repeat_n)] diff --git a/tests/codegen/layout-size-checks.rs b/tests/codegen/layout-size-checks.rs index 55c2e86b40bb..901f8f822f32 100644 --- a/tests/codegen/layout-size-checks.rs +++ b/tests/codegen/layout-size-checks.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O //@ only-x86_64 -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/lib-optimizations/iter-sum.rs b/tests/codegen/lib-optimizations/iter-sum.rs index 6b6d61a30660..b563a6debb52 100644 --- a/tests/codegen/lib-optimizations/iter-sum.rs +++ b/tests/codegen/lib-optimizations/iter-sum.rs @@ -1,4 +1,3 @@ -//@ ignore-debug: the debug assertions get in the way //@ compile-flags: -O //@ only-x86_64 (vectorization varies between architectures) #![crate_type = "lib"] diff --git a/tests/codegen/mem-replace-big-type.rs b/tests/codegen/mem-replace-big-type.rs index 0234b63aba5e..c71cbbd08f9a 100644 --- a/tests/codegen/mem-replace-big-type.rs +++ b/tests/codegen/mem-replace-big-type.rs @@ -4,7 +4,7 @@ // known to be `1` after inlining). //@ compile-flags: -C no-prepopulate-passes -Zinline-mir=no -//@ ignore-debug: the debug assertions get in the way +//@ ignore-debug: precondition checks in ptr::read make them a bad candidate for MIR inlining #![crate_type = "lib"] diff --git a/tests/codegen/mem-replace-simple-type.rs b/tests/codegen/mem-replace-simple-type.rs index b6885aad9e40..b00fbad05d9c 100644 --- a/tests/codegen/mem-replace-simple-type.rs +++ b/tests/codegen/mem-replace-simple-type.rs @@ -1,6 +1,6 @@ //@ compile-flags: -O -C no-prepopulate-passes //@ only-x86_64 (to not worry about usize differing) -//@ ignore-debug (the debug assertions get in the way) +//@ ignore-debug: precondition checks make mem::replace not a candidate for MIR inlining #![crate_type = "lib"] diff --git a/tests/codegen/ptr-arithmetic.rs b/tests/codegen/ptr-arithmetic.rs index 3a8bfee84ecf..6f115d33d8dd 100644 --- a/tests/codegen/ptr-arithmetic.rs +++ b/tests/codegen/ptr-arithmetic.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -Z merge-functions=disabled -//@ ignore-debug (the extra assertions get in the way) #![crate_type = "lib"] diff --git a/tests/codegen/ptr-read-metadata.rs b/tests/codegen/ptr-read-metadata.rs index 622a1cec4ac6..4c623dee5e1e 100644 --- a/tests/codegen/ptr-read-metadata.rs +++ b/tests/codegen/ptr-read-metadata.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -Z merge-functions=disabled -//@ ignore-debug (the extra assertions get in the way) #![crate_type = "lib"] diff --git a/tests/codegen/simd/simd-wide-sum.rs b/tests/codegen/simd/simd-wide-sum.rs index 010500139e59..2edee552ca69 100644 --- a/tests/codegen/simd/simd-wide-sum.rs +++ b/tests/codegen/simd/simd-wide-sum.rs @@ -1,7 +1,6 @@ //@ revisions: llvm mir-opt3 //@ compile-flags: -C opt-level=3 -Z merge-functions=disabled --edition=2021 //@ only-x86_64 -//@ ignore-debug: the debug assertions get in the way //@ [mir-opt3]compile-flags: -Zmir-opt-level=3 //@ [mir-opt3]build-pass diff --git a/tests/codegen/simd/swap-simd-types.rs b/tests/codegen/simd/swap-simd-types.rs index e03e2d4ff8df..32e75220d696 100644 --- a/tests/codegen/simd/swap-simd-types.rs +++ b/tests/codegen/simd/swap-simd-types.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O -C target-feature=+avx //@ only-x86_64 -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/slice-as_chunks.rs b/tests/codegen/slice-as_chunks.rs index c9cd482a9a4e..631d18d78095 100644 --- a/tests/codegen/slice-as_chunks.rs +++ b/tests/codegen/slice-as_chunks.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O //@ only-64bit (because the LLVM type of i64 for usize shows up) -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] #![feature(slice_as_chunks)] diff --git a/tests/codegen/slice-indexing.rs b/tests/codegen/slice-indexing.rs index 52714a76a8dd..ecce92010719 100644 --- a/tests/codegen/slice-indexing.rs +++ b/tests/codegen/slice-indexing.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O //@ only-64bit (because the LLVM type of i64 for usize shows up) -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/slice-iter-fold.rs b/tests/codegen/slice-iter-fold.rs index 5a9d789b9846..1770cd4a1199 100644 --- a/tests/codegen/slice-iter-fold.rs +++ b/tests/codegen/slice-iter-fold.rs @@ -1,4 +1,3 @@ -//@ ignore-debug: the debug assertions get in the way //@ compile-flags: -O #![crate_type = "lib"] diff --git a/tests/codegen/slice-iter-len-eq-zero.rs b/tests/codegen/slice-iter-len-eq-zero.rs index 43c64511e527..b2a4b2495b6a 100644 --- a/tests/codegen/slice-iter-len-eq-zero.rs +++ b/tests/codegen/slice-iter-len-eq-zero.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug: the debug assertions add extra comparisons #![crate_type = "lib"] type Demo = [u8; 3]; diff --git a/tests/codegen/slice-iter-nonnull.rs b/tests/codegen/slice-iter-nonnull.rs index c82ae3b61b41..c960688b00c1 100644 --- a/tests/codegen/slice-iter-nonnull.rs +++ b/tests/codegen/slice-iter-nonnull.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug (these add extra checks that make it hard to verify) #![crate_type = "lib"] #![feature(exact_size_is_empty)] diff --git a/tests/codegen/slice-ref-equality.rs b/tests/codegen/slice-ref-equality.rs index d34aecd1903a..371e685ec6c9 100644 --- a/tests/codegen/slice-ref-equality.rs +++ b/tests/codegen/slice-ref-equality.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -Zmerge-functions=disabled -//@ ignore-debug (the extra assertions get in the way) #![crate_type = "lib"] diff --git a/tests/codegen/slice-reverse.rs b/tests/codegen/slice-reverse.rs index 40bc89bc9d0c..21add929f051 100644 --- a/tests/codegen/slice-reverse.rs +++ b/tests/codegen/slice-reverse.rs @@ -1,6 +1,6 @@ //@ compile-flags: -O //@ only-x86_64 -//@ ignore-debug: the debug assertions in from_raw_parts get in the way +//@ ignore-debug: debug assertions prevent generating shufflevector #![crate_type = "lib"] diff --git a/tests/codegen/slice_as_from_ptr_range.rs b/tests/codegen/slice_as_from_ptr_range.rs index cc811e8f5894..47c60461c0e8 100644 --- a/tests/codegen/slice_as_from_ptr_range.rs +++ b/tests/codegen/slice_as_from_ptr_range.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O //@ only-64bit (because we're using [ui]size) -//@ ignore-debug (because the assertions get in the way) #![crate_type = "lib"] #![feature(slice_from_ptr_range)] diff --git a/tests/codegen/swap-large-types.rs b/tests/codegen/swap-large-types.rs index 206978908140..b182f3ed9479 100644 --- a/tests/codegen/swap-large-types.rs +++ b/tests/codegen/swap-large-types.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O //@ only-x86_64 -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/swap-small-types.rs b/tests/codegen/swap-small-types.rs index 8d7f9f49eef6..5fdf4a5804a9 100644 --- a/tests/codegen/swap-small-types.rs +++ b/tests/codegen/swap-small-types.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O -Z merge-functions=disabled //@ only-x86_64 -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/transmute-optimized.rs b/tests/codegen/transmute-optimized.rs index 43d2a55c9955..9217def76b51 100644 --- a/tests/codegen/transmute-optimized.rs +++ b/tests/codegen/transmute-optimized.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -Z merge-functions=disabled -//@ ignore-debug #![crate_type = "lib"] diff --git a/tests/codegen/unchecked_shifts.rs b/tests/codegen/unchecked_shifts.rs index 4e351d8d3335..9cf2f2b0cb67 100644 --- a/tests/codegen/unchecked_shifts.rs +++ b/tests/codegen/unchecked_shifts.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug (because unchecked is checked in debug) #![crate_type = "lib"] #![feature(unchecked_shifts)] diff --git a/tests/codegen/unwind-landingpad-inline.rs b/tests/codegen/unwind-landingpad-inline.rs index 953ba5e901a2..77ef8d2a5fe7 100644 --- a/tests/codegen/unwind-landingpad-inline.rs +++ b/tests/codegen/unwind-landingpad-inline.rs @@ -1,6 +1,5 @@ //@ min-llvm-version: 17.0.2 //@ compile-flags: -Copt-level=3 -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] // This test checks that we can inline drop_in_place in diff --git a/tests/codegen/vec-calloc.rs b/tests/codegen/vec-calloc.rs index bae344ab01d6..f88ed7ae8a55 100644 --- a/tests/codegen/vec-calloc.rs +++ b/tests/codegen/vec-calloc.rs @@ -1,6 +1,5 @@ //@ compile-flags: -O -Z merge-functions=disabled //@ only-x86_64 -//@ ignore-debug #![crate_type = "lib"] diff --git a/tests/codegen/vec-in-place.rs b/tests/codegen/vec-in-place.rs index 3ac2ec13d476..7a175dc4f7e1 100644 --- a/tests/codegen/vec-in-place.rs +++ b/tests/codegen/vec-in-place.rs @@ -1,4 +1,4 @@ -//@ ignore-debug: the debug assertions get in the way +//@ ignore-debug: FIXME: checks for call detect scoped noalias metadata //@ compile-flags: -O -Z merge-functions=disabled #![crate_type = "lib"] diff --git a/tests/codegen/vec-iter-collect-len.rs b/tests/codegen/vec-iter-collect-len.rs index 0c225abd326d..e4242c574023 100644 --- a/tests/codegen/vec-iter-collect-len.rs +++ b/tests/codegen/vec-iter-collect-len.rs @@ -1,4 +1,3 @@ -//@ ignore-debug: the debug assertions get in the way //@ compile-flags: -O #![crate_type="lib"] diff --git a/tests/codegen/vec-iter.rs b/tests/codegen/vec-iter.rs index 47e11af5bc3d..310680969c4f 100644 --- a/tests/codegen/vec-iter.rs +++ b/tests/codegen/vec-iter.rs @@ -1,4 +1,3 @@ -//@ ignore-debug: the debug assertions get in the way //@ compile-flags: -O #![crate_type = "lib"] #![feature(exact_size_is_empty)] diff --git a/tests/codegen/vec-optimizes-away.rs b/tests/codegen/vec-optimizes-away.rs index 9cbfbc115b04..77a94b0b4294 100644 --- a/tests/codegen/vec-optimizes-away.rs +++ b/tests/codegen/vec-optimizes-away.rs @@ -1,4 +1,3 @@ -//@ ignore-debug: the debug assertions get in the way //@ compile-flags: -O #![crate_type = "lib"] diff --git a/tests/codegen/vec-reserve-extend.rs b/tests/codegen/vec-reserve-extend.rs index 12795937bc81..1f00f7d20633 100644 --- a/tests/codegen/vec-reserve-extend.rs +++ b/tests/codegen/vec-reserve-extend.rs @@ -1,6 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug -// (with debug assertions turned on, `assert_unchecked` generates a real assertion) #![crate_type = "lib"] diff --git a/tests/codegen/vec-shrink-panik.rs b/tests/codegen/vec-shrink-panik.rs index 33b70300bf41..4e996b234f98 100644 --- a/tests/codegen/vec-shrink-panik.rs +++ b/tests/codegen/vec-shrink-panik.rs @@ -4,7 +4,7 @@ //@ [old]ignore-llvm-version: 17 - 99 //@ [new]min-llvm-version: 17 //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way +//@ ignore-debug: plain old debug assertions //@ needs-unwind #![crate_type = "lib"] #![feature(shrink_to)] diff --git a/tests/codegen/vec_pop_push_noop.rs b/tests/codegen/vec_pop_push_noop.rs index 5a2009b01d7c..83765d108541 100644 --- a/tests/codegen/vec_pop_push_noop.rs +++ b/tests/codegen/vec_pop_push_noop.rs @@ -1,6 +1,4 @@ //@ compile-flags: -O -//@ ignore-debug -// (with debug assertions turned on, `assert_unchecked` generates a real assertion) #![crate_type = "lib"] diff --git a/tests/codegen/vecdeque-drain.rs b/tests/codegen/vecdeque-drain.rs index cd549f8ebd4a..31fcf035f115 100644 --- a/tests/codegen/vecdeque-drain.rs +++ b/tests/codegen/vecdeque-drain.rs @@ -1,7 +1,7 @@ // Check that draining at the front or back doesn't copy memory. //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way +//@ ignore-debug: FIXME: checks for call detect scoped noalias metadata #![crate_type = "lib"] diff --git a/tests/codegen/vecdeque-nonempty-get-no-panic.rs b/tests/codegen/vecdeque-nonempty-get-no-panic.rs index 1128b4ed7a44..3f802de9eeed 100644 --- a/tests/codegen/vecdeque-nonempty-get-no-panic.rs +++ b/tests/codegen/vecdeque-nonempty-get-no-panic.rs @@ -1,7 +1,6 @@ // Guards against regression for optimization discussed in issue #80836 //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way #![crate_type = "lib"] diff --git a/tests/codegen/vecdeque_no_panic.rs b/tests/codegen/vecdeque_no_panic.rs index 57b6b2abbea9..be2c4810ebc4 100644 --- a/tests/codegen/vecdeque_no_panic.rs +++ b/tests/codegen/vecdeque_no_panic.rs @@ -1,7 +1,7 @@ // This test checks that `VecDeque::front[_mut]()` and `VecDeque::back[_mut]()` can't panic. //@ compile-flags: -O -//@ ignore-debug: the debug assertions get in the way +//@ ignore-debug: plain old debug assertions #![crate_type = "lib"] diff --git a/tests/codegen/virtual-function-elimination.rs b/tests/codegen/virtual-function-elimination.rs index bf4a74085ed8..6c391d9114b4 100644 --- a/tests/codegen/virtual-function-elimination.rs +++ b/tests/codegen/virtual-function-elimination.rs @@ -1,6 +1,5 @@ //@ compile-flags: -Zvirtual-function-elimination -Clto -O -Csymbol-mangling-version=v0 //@ ignore-32bit -//@ ignore-debug // CHECK: @vtable.0 = {{.*}}, !type ![[TYPE0:[0-9]+]], !vcall_visibility ![[VCALL_VIS0:[0-9]+]] // CHECK: @vtable.1 = {{.*}}, !type ![[TYPE1:[0-9]+]], !vcall_visibility ![[VCALL_VIS0:[0-9]+]] diff --git a/tests/mir-opt/pre-codegen/slice_filter.rs b/tests/mir-opt/pre-codegen/slice_filter.rs index 45686f0bf880..35881ff2b18c 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.rs +++ b/tests/mir-opt/pre-codegen/slice_filter.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2 -//@ ignore-debug: standard library debug assertions add a panic that breaks this optimization #![crate_type = "lib"] diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir index 7370da5629c1..65cac0a81ef1 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir @@ -1,6 +1,6 @@ // MIR for `variant_a::{closure#0}` after PreCodegen -fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2: &&(usize, usize, usize, usize)) -> bool { +fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2: &&(usize, usize, usize, usize)) -> bool { let mut _0: bool; let mut _3: &(usize, usize, usize, usize); let _4: &usize; diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir index 5477796512c5..d9e118d879a6 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir @@ -1,6 +1,6 @@ // MIR for `variant_b::{closure#0}` after PreCodegen -fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:12:25: 12:41}, _2: &&(usize, usize, usize, usize)) -> bool { +fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41}, _2: &&(usize, usize, usize, usize)) -> bool { let mut _0: bool; let mut _3: &(usize, usize, usize, usize); let _4: usize; From e0bfa5c2940eb926c3b7d8d85f6f351a767d6664 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sat, 24 Feb 2024 10:34:09 +0530 Subject: [PATCH 6/8] Rustdoc: include crate name in links for local primitives It makes the link easier to use in cases in which the path of the page where it will be embedded is not known beforehand such as when we generate impls dynamically from `register_type_impls` method in `main.js` Earlier for local primitives we would generate a path that was relative to the current page depth passed in `cx.current` . e.g if the current page was `std::simd::prelude::Simd` the generated path would be `../../primitive..html` After this change the path will first take you to the the wesite root and add the crate name. e.g. for `std::simd::prelude::Simd` the path now will be `../../../std/primitive..html` --- src/librustdoc/html/format.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index bb68c84f529a..973036a40982 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -879,11 +879,16 @@ fn primitive_link_fragment( match m.primitive_locations.get(&prim) { Some(&def_id) if def_id.is_local() => { let len = cx.current.len(); - let len = if len == 0 { 0 } else { len - 1 }; + let path = if len == 0 { + let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx()); + format!("{cname_sym}/") + } else { + "../".repeat(len - 1) + }; write!( f, "", - "../".repeat(len), + path, prim.as_sym() )?; needs_termination = true; From ff930d4fed085dcff75c7b9df6af3a4e099d2f21 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 24 Feb 2024 09:46:18 +0100 Subject: [PATCH 7/8] compiler/rustc_target/src/spec/base/apple/tests.rs: Avoid unnecessary large move Fixes: $ MAGIC_EXTRA_RUSTFLAGS=-Zmove-size-limit=4096 ./x test compiler/rustc_target error: moving 6216 bytes --> compiler/rustc_target/src/spec/base/apple/tests.rs:17:19 | 17 | for target in all_sim_targets { | ^^^^^^^^^^^^^^^ value moved from here | = note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` = note: `-D large-assignments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(large_assignments)]` --- compiler/rustc_target/src/spec/base/apple/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/base/apple/tests.rs b/compiler/rustc_target/src/spec/base/apple/tests.rs index f13058ebc82a..097039d6c738 100644 --- a/compiler/rustc_target/src/spec/base/apple/tests.rs +++ b/compiler/rustc_target/src/spec/base/apple/tests.rs @@ -14,7 +14,7 @@ fn simulator_targets_set_abi() { aarch64_apple_watchos_sim::target(), ]; - for target in all_sim_targets { + for target in &all_sim_targets { assert_eq!(target.abi, "sim") } } From 55ee14005f7f5798c7cf4c99e2d127c389c23fa7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 24 Feb 2024 12:15:21 +0100 Subject: [PATCH 8/8] update stdarch --- library/stdarch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/stdarch b/library/stdarch index d5fab978fe1c..56087ea170d8 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit d5fab978fe1c2f0043db0451e9f4857eeba17437 +Subproject commit 56087ea170d878a7a57b3a5725e0c00f5f5cad70