about summary refs log tree commit diff
path: root/tests/codegen/cffi
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2023-07-29 17:28:42 -0700
committerJubilee Young <workingjubilee@gmail.com>2023-07-29 18:34:41 -0700
commitbadba92036e9728a499e118e7a6646fffd33d098 (patch)
tree19bb8bc869384d0ef942c81fbfc283c19138e013 /tests/codegen/cffi
parent0ca0556651f304af3893742ebd6e543648ca1e67 (diff)
tests/codegen/ffi-* -> cffi/ffi-*
Diffstat (limited to 'tests/codegen/cffi')
-rw-r--r--tests/codegen/cffi/ffi-const.rs13
-rw-r--r--tests/codegen/cffi/ffi-out-of-bounds-loads.rs25
-rw-r--r--tests/codegen/cffi/ffi-pure.rs13
-rw-r--r--tests/codegen/cffi/ffi-returns-twice.rs11
4 files changed, 62 insertions, 0 deletions
diff --git a/tests/codegen/cffi/ffi-const.rs b/tests/codegen/cffi/ffi-const.rs
new file mode 100644
index 00000000000..93720503480
--- /dev/null
+++ b/tests/codegen/cffi/ffi-const.rs
@@ -0,0 +1,13 @@
+// compile-flags: -C no-prepopulate-passes
+#![crate_type = "lib"]
+#![feature(ffi_const)]
+
+pub fn bar() { unsafe { foo() } }
+
+extern "C" {
+    // CHECK-LABEL: declare{{.*}}void @foo()
+    // CHECK-SAME: [[ATTRS:#[0-9]+]]
+    // The attribute changed from `readnone` to `memory(none)` with LLVM 16.0.
+    // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}{{readnone|memory\(none\)}}{{.*}} }
+    #[ffi_const] pub fn foo();
+}
diff --git a/tests/codegen/cffi/ffi-out-of-bounds-loads.rs b/tests/codegen/cffi/ffi-out-of-bounds-loads.rs
new file mode 100644
index 00000000000..099726b2f08
--- /dev/null
+++ b/tests/codegen/cffi/ffi-out-of-bounds-loads.rs
@@ -0,0 +1,25 @@
+// Regression test for #29988
+
+// compile-flags: -C no-prepopulate-passes
+// only-x86_64
+// ignore-windows
+
+#[repr(C)]
+struct S {
+    f1: i32,
+    f2: i32,
+    f3: i32,
+}
+
+extern "C" {
+    fn foo(s: S);
+}
+
+fn main() {
+    let s = S { f1: 1, f2: 2, f3: 3 };
+    unsafe {
+        // CHECK: load { i64, i32 }, {{.*}}, align 4
+        // CHECK: call void @foo({ i64, i32 } {{.*}})
+        foo(s);
+    }
+}
diff --git a/tests/codegen/cffi/ffi-pure.rs b/tests/codegen/cffi/ffi-pure.rs
new file mode 100644
index 00000000000..2ed73581358
--- /dev/null
+++ b/tests/codegen/cffi/ffi-pure.rs
@@ -0,0 +1,13 @@
+// compile-flags: -C no-prepopulate-passes
+#![crate_type = "lib"]
+#![feature(ffi_pure)]
+
+pub fn bar() { unsafe { foo() } }
+
+extern "C" {
+    // CHECK-LABEL: declare{{.*}}void @foo()
+    // CHECK-SAME: [[ATTRS:#[0-9]+]]
+    // The attribute changed from `readonly` to `memory(read)` with LLVM 16.0.
+    // CHECK-DAG: attributes [[ATTRS]] = { {{.*}}{{readonly|memory\(read\)}}{{.*}} }
+    #[ffi_pure] pub fn foo();
+}
diff --git a/tests/codegen/cffi/ffi-returns-twice.rs b/tests/codegen/cffi/ffi-returns-twice.rs
new file mode 100644
index 00000000000..0fbe03f0bb6
--- /dev/null
+++ b/tests/codegen/cffi/ffi-returns-twice.rs
@@ -0,0 +1,11 @@
+// compile-flags: -C no-prepopulate-passes
+#![crate_type = "lib"]
+#![feature(ffi_returns_twice)]
+
+pub fn bar() { unsafe { foo() } }
+
+extern "C" {
+    // CHECK: declare{{( dso_local)?}} void @foo(){{.*}}[[ATTRS:#[0-9]+]]
+    // CHECK: attributes [[ATTRS]] = { {{.*}}returns_twice{{.*}} }
+    #[ffi_returns_twice] pub fn foo();
+}