diff --git a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs index a5f2ba2f1ced9..76b10b3280449 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs @@ -5,6 +5,7 @@ use rustc_hir::{CRATE_HIR_ID, HirId}; use rustc_middle::mir::{self, Location, traversal}; use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt}; use rustc_span::def_id::DefId; +use rustc_span::source_map::Spanned; use rustc_span::{DUMMY_SP, Span, Symbol, sym}; use rustc_target::callconv::{FnAbi, PassMode}; @@ -157,12 +158,16 @@ fn do_check_unsized_params<'tcx>( /// - the signature requires target features that are not enabled fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { let typing_env = ty::TypingEnv::fully_monomorphized(); - let Ok(abi) = tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty()))) - else { - // An error will be reported during codegen if we cannot determine the ABI of this - // function. - tcx.dcx().delayed_bug("ABI computation failure should lead to compilation failure"); - return; + let abi = match tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty()))) + { + Ok(abi) => abi, + Err(err) => { + // Emit directly: codegen may never see this instance (dead code, `-Zno-codegen`). + let ty::layout::FnAbiError::Layout(layout_err) = *err; + let span = tcx.def_span(instance.def_id()); + tcx.dcx().emit_err(Spanned { node: layout_err.into_diagnostic(), span }); + return; + } }; // Unlike the call-site check, we do also check "Rust" ABI functions here. // This should never trigger, *except* if we start making use of vector registers diff --git a/tests/crashes/138008.rs b/tests/crashes/138008.rs deleted file mode 100644 index 4645b8c9d562e..0000000000000 --- a/tests/crashes/138008.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ known-bug: #138008 -//@compile-flags: --crate-type=lib -Copt-level=0 -#![feature(repr_simd)] -const C: usize = 16; - -#[repr(simd)] -pub struct Foo([u8; C]); -pub unsafe fn foo(a: Foo) {} diff --git a/tests/ui/layout/post-mono-layout-cycle.rs b/tests/ui/layout/post-mono-layout-cycle.rs index 841fc30a50bcf..655191256e8b3 100644 --- a/tests/ui/layout/post-mono-layout-cycle.rs +++ b/tests/ui/layout/post-mono-layout-cycle.rs @@ -13,7 +13,7 @@ struct Wrapper { _x: ::Assoc, } -fn abi(_: Option>) {} +fn abi(_: Option>) {} //~ ERROR a cycle occurred during layout computation fn indirect() { abi::(None); diff --git a/tests/ui/layout/post-mono-layout-cycle.stderr b/tests/ui/layout/post-mono-layout-cycle.stderr index 7f246b3d409ad..46ee1e741b42d 100644 --- a/tests/ui/layout/post-mono-layout-cycle.stderr +++ b/tests/ui/layout/post-mono-layout-cycle.stderr @@ -5,12 +5,18 @@ error[E0391]: cycle detected when computing layout of `Wrapper<()>` = note: cycle used when computing layout of `core::option::Option>` = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +error: a cycle occurred during layout computation + --> $DIR/post-mono-layout-cycle.rs:16:1 + | +LL | fn abi(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + note: the above error was encountered while instantiating `fn abi::<()>` --> $DIR/post-mono-layout-cycle.rs:19:5 | LL | abi::(None); | ^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/limits/issue-17913.32bit.stderr b/tests/ui/limits/issue-17913.32bit.stderr index 1311822d0d0c4..fb801e3afcef4 100644 --- a/tests/ui/limits/issue-17913.32bit.stderr +++ b/tests/ui/limits/issue-17913.32bit.stderr @@ -1,3 +1,6 @@ +error: values of the type `[&usize; usize::MAX]` are too big for the target architecture + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | @@ -14,6 +17,6 @@ note: the above error was encountered while instantiating `fn Box::<[&usize; usi LL | let a: Box<_> = Box::new([&n; SIZE]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/limits/issue-17913.64bit.stderr b/tests/ui/limits/issue-17913.64bit.stderr index b0481ee99378c..5a8e07d970229 100644 --- a/tests/ui/limits/issue-17913.64bit.stderr +++ b/tests/ui/limits/issue-17913.64bit.stderr @@ -1,3 +1,6 @@ +error: values of the type `[&usize; usize::MAX]` are too big for the target architecture + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | @@ -14,6 +17,6 @@ note: the above error was encountered while instantiating `fn Box::<[&usize; usi LL | let a: Box<_> = Box::new([&n; SIZE]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/limits/issue-17913.rs b/tests/ui/limits/issue-17913.rs index d804b64ab330e..b007136331445 100644 --- a/tests/ui/limits/issue-17913.rs +++ b/tests/ui/limits/issue-17913.rs @@ -19,3 +19,4 @@ fn main() { //~? ERROR are too big for the target architecture //~? ERROR are too big for the target architecture +//~? ERROR are too big for the target architecture diff --git a/tests/ui/simd/monomorphize-oversized-no-codegen.rs b/tests/ui/simd/monomorphize-oversized-no-codegen.rs new file mode 100644 index 0000000000000..ad5968563ec95 --- /dev/null +++ b/tests/ui/simd/monomorphize-oversized-no-codegen.rs @@ -0,0 +1,13 @@ +// Regression test for #149156. +//@ build-fail +//@ compile-flags: -Zno-codegen +//@ only-x86_64 + +#![crate_type = "lib"] +#![allow(private_interfaces)] + +struct Struct([u8; 0xffff_ffff_ffff_ffff]); + +pub fn function(value: Struct) -> u8 { //~ ERROR are too big for the target architecture + value.0[0] +} diff --git a/tests/ui/simd/monomorphize-oversized-no-codegen.stderr b/tests/ui/simd/monomorphize-oversized-no-codegen.stderr new file mode 100644 index 0000000000000..0fec6d7b6a1e6 --- /dev/null +++ b/tests/ui/simd/monomorphize-oversized-no-codegen.stderr @@ -0,0 +1,8 @@ +error: values of the type `[u8; usize::MAX]` are too big for the target architecture + --> $DIR/monomorphize-oversized-no-codegen.rs:11:1 + | +LL | pub fn function(value: Struct) -> u8 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/simd/monomorphize-oversized-unreachable.rs b/tests/ui/simd/monomorphize-oversized-unreachable.rs new file mode 100644 index 0000000000000..a42ffbb5d0470 --- /dev/null +++ b/tests/ui/simd/monomorphize-oversized-unreachable.rs @@ -0,0 +1,13 @@ +// Regression test for #152204. +//@ build-fail +//@ only-x86_64 + +#![feature(portable_simd)] + +fn main() { + if false { + let _ = core::simd::Simd::::splat(0); + } +} + +//~? ERROR the SIMD type `Simd` has more elements than the limit 64 diff --git a/tests/ui/simd/monomorphize-oversized-unreachable.stderr b/tests/ui/simd/monomorphize-oversized-unreachable.stderr new file mode 100644 index 0000000000000..83bbd83fc1af3 --- /dev/null +++ b/tests/ui/simd/monomorphize-oversized-unreachable.stderr @@ -0,0 +1,11 @@ +error: the SIMD type `Simd` has more elements than the limit 64 + --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/vector.rs:LL:COL + +note: the above error was encountered while instantiating `fn Simd::::splat` + --> $DIR/monomorphize-oversized-unreachable.rs:9:17 + | +LL | let _ = core::simd::Simd::::splat(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/simd/monomorphize-repr-simd-const-generic.rs b/tests/ui/simd/monomorphize-repr-simd-const-generic.rs new file mode 100644 index 0000000000000..31844b38b90de --- /dev/null +++ b/tests/ui/simd/monomorphize-repr-simd-const-generic.rs @@ -0,0 +1,12 @@ +// Regression test for #138008. +//@ build-fail +//@ compile-flags: --crate-type=lib -Copt-level=0 + +#![feature(repr_simd)] + +const C: usize = 16; + +#[repr(simd)] +pub struct Foo([u8; C]); + +pub unsafe fn foo(a: Foo) {} //~ ERROR the type `Foo` has an unknown layout diff --git a/tests/ui/simd/monomorphize-repr-simd-const-generic.stderr b/tests/ui/simd/monomorphize-repr-simd-const-generic.stderr new file mode 100644 index 0000000000000..342396e1e6b67 --- /dev/null +++ b/tests/ui/simd/monomorphize-repr-simd-const-generic.stderr @@ -0,0 +1,8 @@ +error: the type `Foo` has an unknown layout + --> $DIR/monomorphize-repr-simd-const-generic.rs:12:1 + | +LL | pub unsafe fn foo(a: Foo) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error +