From 1f11d841b5748133c2d51da0001fc88bc6b51e78 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 10 Feb 2023 23:54:05 +0000 Subject: Add codegen test --- tests/codegen/function-arguments.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/codegen') diff --git a/tests/codegen/function-arguments.rs b/tests/codegen/function-arguments.rs index 96dfde18683..63f05119031 100644 --- a/tests/codegen/function-arguments.rs +++ b/tests/codegen/function-arguments.rs @@ -1,6 +1,7 @@ // compile-flags: -O -C no-prepopulate-passes #![crate_type = "lib"] +#![feature(dyn_star)] use std::mem::MaybeUninit; use std::num::NonZeroU64; @@ -279,3 +280,9 @@ pub fn enum_id_1(x: Option>) -> Option> { pub fn enum_id_2(x: Option) -> Option { x } + +// CHECK: { {{i8\*|ptr}}, {{i.*\*|ptr}} } @dyn_star({{i8\*|ptr}} noundef %x.0, {{i.*\*|ptr}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %x.1) +#[no_mangle] +pub fn dyn_star(x: dyn* Drop) -> dyn* Drop { + x +} -- cgit 1.4.1-3-g733a5 From e82cc656c822af7f1905b757a27cac5823fbc301 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 15 Feb 2023 03:42:45 +0000 Subject: Make dyn* have the same scalar pair ABI as corresponding fat pointer --- compiler/rustc_codegen_llvm/src/type_of.rs | 7 ++++++- tests/codegen/function-arguments.rs | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'tests/codegen') diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index cc8ff947fc3..9cda24bab87 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -329,7 +329,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { ) -> &'a Type { // HACK(eddyb) special-case fat pointers until LLVM removes // pointee types, to avoid bitcasting every `OperandRef::deref`. - match self.ty.kind() { + match *self.ty.kind() { ty::Ref(..) | ty::RawPtr(_) => { return self.field(cx, index).llvm_type(cx); } @@ -339,6 +339,11 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty()); return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate); } + // `dyn* Trait` has the same ABI as `*mut dyn Trait` + ty::Dynamic(bounds, region, ty::DynStar) => { + let ptr_ty = cx.tcx.mk_mut_ptr(cx.tcx.mk_dynamic(bounds, region, ty::Dyn)); + return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate); + } _ => {} } diff --git a/tests/codegen/function-arguments.rs b/tests/codegen/function-arguments.rs index 63f05119031..d6f019016a5 100644 --- a/tests/codegen/function-arguments.rs +++ b/tests/codegen/function-arguments.rs @@ -281,7 +281,9 @@ pub fn enum_id_2(x: Option) -> Option { x } -// CHECK: { {{i8\*|ptr}}, {{i.*\*|ptr}} } @dyn_star({{i8\*|ptr}} noundef %x.0, {{i.*\*|ptr}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %x.1) +// CHECK: { {{\{\}\*|ptr}}, {{.+}} } @dyn_star({{\{\}\*|ptr}} noundef %x.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %x.1) +// Expect an ABI something like `{ {}*, [3 x i64]* }`, but that's hard to match on generically, +// so do like the `trait_box` test and just match on `{{.+}}` for the vtable. #[no_mangle] pub fn dyn_star(x: dyn* Drop) -> dyn* Drop { x -- cgit 1.4.1-3-g733a5 From 86dbcb53907037dcc3fabb635956aec2c384b4e9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 11 Feb 2023 08:59:19 +0000 Subject: Add codegen test. --- tests/codegen/inherit_overflow.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/codegen/inherit_overflow.rs (limited to 'tests/codegen') diff --git a/tests/codegen/inherit_overflow.rs b/tests/codegen/inherit_overflow.rs new file mode 100644 index 00000000000..d938dadb9c7 --- /dev/null +++ b/tests/codegen/inherit_overflow.rs @@ -0,0 +1,14 @@ +// compile-flags: -Zmir-enable-passes=+Inline,+ConstProp --crate-type lib +// revisions: ASSERT NOASSERT +//[ASSERT] compile-flags: -Coverflow-checks=on +//[NOASSERT] compile-flags: -Coverflow-checks=off + +// CHECK-LABEL: define{{.*}} @assertion +// ASSERT: tail call void @_ZN4core9panicking5panic17h +// NOASSERT: ret i8 0 +#[no_mangle] +pub fn assertion() -> u8 { + // Optimized MIR will replace this `CheckedBinaryOp` by `const (0, true)`. + // Verify that codegen does or does not emit the panic. + ::add(255, 1) +} -- cgit 1.4.1-3-g733a5 From c107e0e9454555505475758893a88829cdde03f6 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 15 Feb 2023 18:43:15 +0000 Subject: Fix codegen test. --- tests/codegen/inherit_overflow.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codegen') diff --git a/tests/codegen/inherit_overflow.rs b/tests/codegen/inherit_overflow.rs index d938dadb9c7..0b0b890b2c9 100644 --- a/tests/codegen/inherit_overflow.rs +++ b/tests/codegen/inherit_overflow.rs @@ -4,7 +4,7 @@ //[NOASSERT] compile-flags: -Coverflow-checks=off // CHECK-LABEL: define{{.*}} @assertion -// ASSERT: tail call void @_ZN4core9panicking5panic17h +// ASSERT: call void @_ZN4core9panicking5panic17h // NOASSERT: ret i8 0 #[no_mangle] pub fn assertion() -> u8 { -- cgit 1.4.1-3-g733a5