summaryrefslogtreecommitdiffstats
path: root/tests/ui/sepcomp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/sepcomp
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/sepcomp')
-rw-r--r--tests/ui/sepcomp/auxiliary/sepcomp-extern-lib.rs4
-rw-r--r--tests/ui/sepcomp/auxiliary/sepcomp_cci_lib.rs6
-rw-r--r--tests/ui/sepcomp/auxiliary/sepcomp_lib.rs21
-rw-r--r--tests/ui/sepcomp/sepcomp-cci.rs33
-rw-r--r--tests/ui/sepcomp/sepcomp-extern.rs33
-rw-r--r--tests/ui/sepcomp/sepcomp-fns-backwards.rs33
-rw-r--r--tests/ui/sepcomp/sepcomp-fns.rs30
-rw-r--r--tests/ui/sepcomp/sepcomp-lib-lto.rs19
-rw-r--r--tests/ui/sepcomp/sepcomp-lib.rs16
-rw-r--r--tests/ui/sepcomp/sepcomp-statics.rs31
-rw-r--r--tests/ui/sepcomp/sepcomp-unwind.rs35
11 files changed, 261 insertions, 0 deletions
diff --git a/tests/ui/sepcomp/auxiliary/sepcomp-extern-lib.rs b/tests/ui/sepcomp/auxiliary/sepcomp-extern-lib.rs
new file mode 100644
index 000000000..73fb5e8f3
--- /dev/null
+++ b/tests/ui/sepcomp/auxiliary/sepcomp-extern-lib.rs
@@ -0,0 +1,4 @@
+#[no_mangle]
+pub extern "C" fn foo() -> usize {
+ 1234
+}
diff --git a/tests/ui/sepcomp/auxiliary/sepcomp_cci_lib.rs b/tests/ui/sepcomp/auxiliary/sepcomp_cci_lib.rs
new file mode 100644
index 000000000..64e34a56d
--- /dev/null
+++ b/tests/ui/sepcomp/auxiliary/sepcomp_cci_lib.rs
@@ -0,0 +1,6 @@
+#[inline]
+pub fn cci_fn() -> usize {
+ 1200
+}
+
+pub const CCI_CONST: usize = 34;
diff --git a/tests/ui/sepcomp/auxiliary/sepcomp_lib.rs b/tests/ui/sepcomp/auxiliary/sepcomp_lib.rs
new file mode 100644
index 000000000..1536228c2
--- /dev/null
+++ b/tests/ui/sepcomp/auxiliary/sepcomp_lib.rs
@@ -0,0 +1,21 @@
+// compile-flags: -C codegen-units=3 --crate-type=rlib,dylib -g
+
+pub mod a {
+ pub fn one() -> usize {
+ 1
+ }
+}
+
+pub mod b {
+ pub fn two() -> usize {
+ 2
+ }
+}
+
+pub mod c {
+ use a::one;
+ use b::two;
+ pub fn three() -> usize {
+ one() + two()
+ }
+}
diff --git a/tests/ui/sepcomp/sepcomp-cci.rs b/tests/ui/sepcomp/sepcomp-cci.rs
new file mode 100644
index 000000000..02bbab30e
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-cci.rs
@@ -0,0 +1,33 @@
+// run-pass
+// compile-flags: -C codegen-units=3
+// aux-build:sepcomp_cci_lib.rs
+
+// Test accessing cross-crate inlined items from multiple compilation units.
+
+
+extern crate sepcomp_cci_lib;
+use sepcomp_cci_lib::{cci_fn, CCI_CONST};
+
+fn call1() -> usize {
+ cci_fn() + CCI_CONST
+}
+
+mod a {
+ use sepcomp_cci_lib::{cci_fn, CCI_CONST};
+ pub fn call2() -> usize {
+ cci_fn() + CCI_CONST
+ }
+}
+
+mod b {
+ use sepcomp_cci_lib::{cci_fn, CCI_CONST};
+ pub fn call3() -> usize {
+ cci_fn() + CCI_CONST
+ }
+}
+
+fn main() {
+ assert_eq!(call1(), 1234);
+ assert_eq!(a::call2(), 1234);
+ assert_eq!(b::call3(), 1234);
+}
diff --git a/tests/ui/sepcomp/sepcomp-extern.rs b/tests/ui/sepcomp/sepcomp-extern.rs
new file mode 100644
index 000000000..6323bf664
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-extern.rs
@@ -0,0 +1,33 @@
+// run-pass
+// compile-flags: -C codegen-units=3
+// aux-build:sepcomp-extern-lib.rs
+
+// Test accessing external items from multiple compilation units.
+
+extern crate sepcomp_extern_lib;
+
+extern "C" {
+ fn foo() -> usize;
+}
+
+fn call1() -> usize {
+ unsafe { foo() }
+}
+
+mod a {
+ pub fn call2() -> usize {
+ unsafe { ::foo() }
+ }
+}
+
+mod b {
+ pub fn call3() -> usize {
+ unsafe { ::foo() }
+ }
+}
+
+fn main() {
+ assert_eq!(call1(), 1234);
+ assert_eq!(a::call2(), 1234);
+ assert_eq!(b::call3(), 1234);
+}
diff --git a/tests/ui/sepcomp/sepcomp-fns-backwards.rs b/tests/ui/sepcomp/sepcomp-fns-backwards.rs
new file mode 100644
index 000000000..f56769e2b
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-fns-backwards.rs
@@ -0,0 +1,33 @@
+// run-pass
+#![allow(dead_code)]
+// compile-flags: -C codegen-units=3
+
+// Test references to items that haven't been codegened yet.
+
+// Generate some code in the first compilation unit before declaring any
+// modules. This ensures that the first module doesn't go into the same
+// compilation unit as the top-level module.
+
+fn pad() -> usize { 0 }
+
+mod b {
+ pub fn three() -> usize {
+ ::one() + ::a::two()
+ }
+}
+
+mod a {
+ pub fn two() -> usize {
+ ::one() + ::one()
+ }
+}
+
+fn one() -> usize {
+ 1
+}
+
+fn main() {
+ assert_eq!(one(), 1);
+ assert_eq!(a::two(), 2);
+ assert_eq!(b::three(), 3);
+}
diff --git a/tests/ui/sepcomp/sepcomp-fns.rs b/tests/ui/sepcomp/sepcomp-fns.rs
new file mode 100644
index 000000000..a432c8960
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-fns.rs
@@ -0,0 +1,30 @@
+// run-pass
+// compile-flags: -C codegen-units=3
+
+// Test basic separate compilation functionality. The functions should be able
+// to call each other even though they will be placed in different compilation
+// units.
+
+// Generate some code in the first compilation unit before declaring any
+// modules. This ensures that the first module doesn't go into the same
+// compilation unit as the top-level module.
+
+fn one() -> usize { 1 }
+
+mod a {
+ pub fn two() -> usize {
+ ::one() + ::one()
+ }
+}
+
+mod b {
+ pub fn three() -> usize {
+ ::one() + ::a::two()
+ }
+}
+
+fn main() {
+ assert_eq!(one(), 1);
+ assert_eq!(a::two(), 2);
+ assert_eq!(b::three(), 3);
+}
diff --git a/tests/ui/sepcomp/sepcomp-lib-lto.rs b/tests/ui/sepcomp/sepcomp-lib-lto.rs
new file mode 100644
index 000000000..51a572899
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-lib-lto.rs
@@ -0,0 +1,19 @@
+// run-pass
+// Check that we can use `-C lto` when linking against libraries that were
+// separately compiled.
+
+// aux-build:sepcomp_lib.rs
+// compile-flags: -C lto -g
+// ignore-asmjs wasm2js does not support source maps yet
+// no-prefer-dynamic
+
+extern crate sepcomp_lib;
+use sepcomp_lib::a::one;
+use sepcomp_lib::b::two;
+use sepcomp_lib::c::three;
+
+fn main() {
+ assert_eq!(one(), 1);
+ assert_eq!(two(), 2);
+ assert_eq!(three(), 3);
+}
diff --git a/tests/ui/sepcomp/sepcomp-lib.rs b/tests/ui/sepcomp/sepcomp-lib.rs
new file mode 100644
index 000000000..728dc078b
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-lib.rs
@@ -0,0 +1,16 @@
+// run-pass
+// aux-build:sepcomp_lib.rs
+
+// Test linking against a library built with -C codegen-units > 1
+
+
+extern crate sepcomp_lib;
+use sepcomp_lib::a::one;
+use sepcomp_lib::b::two;
+use sepcomp_lib::c::three;
+
+fn main() {
+ assert_eq!(one(), 1);
+ assert_eq!(two(), 2);
+ assert_eq!(three(), 3);
+}
diff --git a/tests/ui/sepcomp/sepcomp-statics.rs b/tests/ui/sepcomp/sepcomp-statics.rs
new file mode 100644
index 000000000..5457c8a0a
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-statics.rs
@@ -0,0 +1,31 @@
+// run-pass
+#![allow(dead_code)]
+// compile-flags: -C codegen-units=3
+
+// Test references to static items across compilation units.
+
+
+fn pad() -> usize { 0 }
+
+const ONE: usize = 1;
+
+mod b {
+ // Separate compilation always switches to the LLVM module with the fewest
+ // instructions. Make sure we have some instructions in this module so
+ // that `a` and `b` don't go into the same compilation unit.
+ fn pad() -> usize { 0 }
+
+ pub static THREE: usize = ::ONE + ::a::TWO;
+}
+
+mod a {
+ fn pad() -> usize { 0 }
+
+ pub const TWO: usize = ::ONE + ::ONE;
+}
+
+fn main() {
+ assert_eq!(ONE, 1);
+ assert_eq!(a::TWO, 2);
+ assert_eq!(b::THREE, 3);
+}
diff --git a/tests/ui/sepcomp/sepcomp-unwind.rs b/tests/ui/sepcomp/sepcomp-unwind.rs
new file mode 100644
index 000000000..a59e25a27
--- /dev/null
+++ b/tests/ui/sepcomp/sepcomp-unwind.rs
@@ -0,0 +1,35 @@
+// run-pass
+// needs-unwind
+#![allow(dead_code)]
+// compile-flags: -C codegen-units=3
+// ignore-emscripten no threads support
+
+// Test unwinding through multiple compilation units.
+
+// According to acrichto, in the distant past `ld -r` (which is used during
+// linking when codegen-units > 1) was known to produce object files with
+// damaged unwinding tables. This may be related to GNU binutils bug #6893
+// ("Partial linking results in corrupt .eh_frame_hdr"), but I'm not certain.
+// In any case, this test should let us know if enabling parallel codegen ever
+// breaks unwinding.
+
+
+use std::thread;
+
+fn pad() -> usize { 0 }
+
+mod a {
+ pub fn f() {
+ panic!();
+ }
+}
+
+mod b {
+ pub fn g() {
+ ::a::f();
+ }
+}
+
+fn main() {
+ thread::spawn(move|| { ::b::g() }).join().unwrap_err();
+}