about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-19 05:35:03 +0000
committerbors <bors@rust-lang.org>2023-02-19 05:35:03 +0000
commit73f40197ecabf77ed59028af61739404eb60dd2e (patch)
treed85c5175b2c1b33af686cef847865a64be4eea77 /tests
parentfcdbd1c07f0b6c8e7d8bbd727c6ca69a1af8c7e9 (diff)
parent7f798c2b216db0bb7ebeb9dd863fbdf7668094c5 (diff)
downloadrust-73f40197ecabf77ed59028af61739404eb60dd2e.tar.gz
rust-73f40197ecabf77ed59028af61739404eb60dd2e.zip
Auto merge of #107772 - compiler-errors:dyn-star-backend-is-ptr, r=eholk
Make `dyn*`'s value backend type a pointer

One tweak on top of Ralf's commit should fix using `usize` as a `dyn*`-coercible type, and should fix when we're using various other pointer types when LLVM opaque pointers is disabled.

r? `@eholk` but feel free to reassign
cc https://github.com/rust-lang/rust/pull/107728#issuecomment-1421231823 `@RalfJung`
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/function-arguments.rs9
-rw-r--r--tests/ui/dyn-star/llvm-old-style-ptrs.rs23
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/codegen/function-arguments.rs b/tests/codegen/function-arguments.rs
index 96dfde18683..d6f019016a5 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,11 @@ pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
 pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
   x
 }
+
+// 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
+}
diff --git a/tests/ui/dyn-star/llvm-old-style-ptrs.rs b/tests/ui/dyn-star/llvm-old-style-ptrs.rs
new file mode 100644
index 00000000000..d35519632be
--- /dev/null
+++ b/tests/ui/dyn-star/llvm-old-style-ptrs.rs
@@ -0,0 +1,23 @@
+// run-pass
+// compile-flags: -Copt-level=0 -Cllvm-args=-opaque-pointers=0
+
+// (opaque-pointers flag is called force-opaque-pointers in LLVM 13...)
+// min-llvm-version: 14.0
+
+// This test can be removed once non-opaque pointers are gone from LLVM, maybe.
+
+#![feature(dyn_star, pointer_like_trait)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+use std::marker::PointerLike;
+
+fn make_dyn_star<'a>(t: impl PointerLike + Debug + 'a) -> dyn* Debug + 'a {
+    t as _
+}
+
+fn main() {
+    println!("{:?}", make_dyn_star(Box::new(1i32)));
+    println!("{:?}", make_dyn_star(2usize));
+    println!("{:?}", make_dyn_star((3usize,)));
+}