about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-11 16:51:54 +0000
committerbors <bors@rust-lang.org>2024-03-11 16:51:54 +0000
commit6554a5645a13e4d9331fd028960d69be91d7492d (patch)
tree99769b8987cd4046411fa0e9e0f2a08e4fa45941 /tests/codegen
parent65cd843ae06ad00123c131a431ed5304e4cd577a (diff)
parent7fa6fa4a1f5d48ac46e22756b27cb56f2aebf02d (diff)
Auto merge of #122338 - workingjubilee:rollup-xzpt4v4, r=workingjubilee
Rollup of 15 pull requests

Successful merges:

 - #116791 (Allow codegen backends to opt-out of parallel codegen)
 - #116793 (Allow targets to override default codegen backend)
 - #117458 (LLVM Bitcode Linker: A self contained linker for nvptx and other targets)
 - #119385 (Fix type resolution of associated const equality bounds (take 2))
 - #121438 (std support for wasm32 panic=unwind)
 - #121893 (Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking)
 - #122080 (Clarity improvements to `DropTree`)
 - #122152 (Improve diagnostics for parenthesized type arguments)
 - #122166 (Remove the unused `field_remapping` field from `TypeLowering`)
 - #122249 (interpret: do not call machine read hooks during validation)
 - #122299 (Store backtrace for `must_produce_diag`)
 - #122318 (Revision-related tweaks for next-solver tests)
 - #122320 (Use ptradd for vtable indexing)
 - #122328 (unix_sigpipe: Replace `inherit` with `sig_dfl` in syntax tests)
 - #122330 (bootstrap readme: fix, improve, update)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/dst-offset.rs4
-rw-r--r--tests/codegen/vtable-upcast.rs85
2 files changed, 87 insertions, 2 deletions
diff --git a/tests/codegen/dst-offset.rs b/tests/codegen/dst-offset.rs
index f0157e5a106..ce735baeb6a 100644
--- a/tests/codegen/dst-offset.rs
+++ b/tests/codegen/dst-offset.rs
@@ -25,9 +25,9 @@ struct Dst<T: ?Sized> {
 pub fn dst_dyn_trait_offset(s: &Dst<dyn Drop>) -> &dyn Drop {
 // The alignment of dyn trait is unknown, so we compute the offset based on align from the vtable.
 
-// CHECK: [[SIZE_PTR:%[0-9]+]] = getelementptr inbounds {{.+}} [[VTABLE_PTR]]
+// CHECK: [[SIZE_PTR:%[0-9]+]] = getelementptr inbounds i8, ptr [[VTABLE_PTR]]
 // CHECK: load [[USIZE]], ptr [[SIZE_PTR]]
-// CHECK: [[ALIGN_PTR:%[0-9]+]] = getelementptr inbounds {{.+}} [[VTABLE_PTR]]
+// CHECK: [[ALIGN_PTR:%[0-9]+]] = getelementptr inbounds i8, ptr [[VTABLE_PTR]]
 // CHECK: load [[USIZE]], ptr [[ALIGN_PTR]]
 
 // CHECK: getelementptr inbounds i8, ptr [[DATA_PTR]]
diff --git a/tests/codegen/vtable-upcast.rs b/tests/codegen/vtable-upcast.rs
new file mode 100644
index 00000000000..41a4be26cb4
--- /dev/null
+++ b/tests/codegen/vtable-upcast.rs
@@ -0,0 +1,85 @@
+//! This file tests that we correctly generate GEP instructions for vtable upcasting.
+//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
+
+#![crate_type = "lib"]
+#![feature(trait_upcasting)]
+
+pub trait Base {
+    fn base(&self);
+}
+
+pub trait A : Base {
+    fn a(&self);
+}
+
+pub trait B : Base {
+    fn b(&self);
+}
+
+pub trait Diamond : A + B {
+    fn diamond(&self);
+}
+
+// CHECK-LABEL: upcast_a_to_base
+#[no_mangle]
+pub fn upcast_a_to_base(x: &dyn A) -> &dyn Base {
+    // Requires no adjustment, since its vtable is extended from `Base`.
+
+    // CHECK: start:
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: ret
+    x as &dyn Base
+}
+
+// CHECK-LABEL: upcast_b_to_base
+#[no_mangle]
+pub fn upcast_b_to_base(x: &dyn B) -> &dyn Base {
+    // Requires no adjustment, since its vtable is extended from `Base`.
+
+    // CHECK: start:
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: ret
+    x as &dyn Base
+}
+
+// CHECK-LABEL: upcast_diamond_to_a
+#[no_mangle]
+pub fn upcast_diamond_to_a(x: &dyn Diamond) -> &dyn A {
+    // Requires no adjustment, since its vtable is extended from `A` (as the first supertrait).
+
+    // CHECK: start:
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: ret
+    x as &dyn A
+}
+
+// CHECK-LABEL: upcast_diamond_to_b
+// CHECK-SAME: (ptr align {{[0-9]+}} [[DATA_PTR:%.+]], ptr align {{[0-9]+}} [[VTABLE_PTR:%.+]])
+#[no_mangle]
+pub fn upcast_diamond_to_b(x: &dyn Diamond) -> &dyn B {
+    // Requires adjustment, since it's a non-first supertrait.
+
+    // CHECK: start:
+    // CHECK-NEXT: [[UPCAST_SLOT_PTR:%.+]] = getelementptr inbounds i8, ptr [[VTABLE_PTR]]
+    // CHECK-NEXT: [[UPCAST_VTABLE_PTR:%.+]] = load ptr, ptr [[UPCAST_SLOT_PTR]]
+    // CHECK-NEXT: [[FAT_PTR_1:%.+]] = insertvalue { ptr, ptr } poison, ptr [[DATA_PTR]], 0
+    // CHECK-NEXT: [[FAT_PTR_2:%.+]] = insertvalue { ptr, ptr } [[FAT_PTR_1]], ptr [[UPCAST_VTABLE_PTR]], 1
+    // CHECK-NEXT: ret { ptr, ptr } [[FAT_PTR_2]]
+    x as &dyn B
+}
+
+// CHECK-LABEL: upcast_diamond_to_b
+#[no_mangle]
+pub fn upcast_diamond_to_base(x: &dyn Diamond) -> &dyn Base {
+    // Requires no adjustment, since `Base` is the first supertrait of `A`,
+    // which is the first supertrait of `Diamond`.
+
+    // CHECK: start:
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: insertvalue
+    // CHECK-NEXT: ret
+    x as &dyn Base
+}