about summary refs log tree commit diff
path: root/src/test/ui/extern/extern-static-size-overflow.rs
diff options
context:
space:
mode:
authorasquared31415 <34665709+asquared31415@users.noreply.github.com>2022-02-24 14:10:41 -0500
committerasquared31415 <34665709+asquared31415@users.noreply.github.com>2022-02-24 14:10:41 -0500
commit75b15c68f81094ad6f1da6f29bd42a1197585257 (patch)
tree680347d5833b71ea6315139c629900616b453d75 /src/test/ui/extern/extern-static-size-overflow.rs
parent3d127e2040b57157936f5f24e114a8b4c9a505ef (diff)
downloadrust-75b15c68f81094ad6f1da6f29bd42a1197585257.tar.gz
rust-75b15c68f81094ad6f1da6f29bd42a1197585257.zip
don't ice when an extern static is too big
Diffstat (limited to 'src/test/ui/extern/extern-static-size-overflow.rs')
-rw-r--r--src/test/ui/extern/extern-static-size-overflow.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/ui/extern/extern-static-size-overflow.rs b/src/test/ui/extern/extern-static-size-overflow.rs
new file mode 100644
index 00000000000..30a0c445466
--- /dev/null
+++ b/src/test/ui/extern/extern-static-size-overflow.rs
@@ -0,0 +1,43 @@
+#[repr(C)]
+struct ReallyBig {
+    _a: [u8; usize::MAX],
+}
+
+// The limit for "too big for the current architecture" is dependent on the target pointer size
+// however it's artifically limited on 64 bits
+// logic copied from rustc_target::abi::TargetDataLayout::obj_size_bound()
+const fn max_size() -> usize {
+    #[cfg(target_pointer_width = "16")]
+    {
+        1 << 15
+    }
+
+    #[cfg(target_pointer_width = "32")]
+    {
+        1 << 31
+    }
+
+    #[cfg(target_pointer_width = "64")]
+    {
+        1 << 47
+    }
+
+    #[cfg(not(any(
+        target_pointer_width = "16",
+        target_pointer_width = "32",
+        target_pointer_width = "64"
+    )))]
+    {
+        isize::MAX as usize
+    }
+}
+
+extern "C" {
+    static FOO: [u8; 1];
+    static BAR: [u8; max_size() - 1];
+    static BAZ: [u8; max_size()]; //~ ERROR extern static is too large
+    static UWU: [usize; usize::MAX]; //~ ERROR extern static is too large
+    static A: ReallyBig; //~ ERROR extern static is too large
+}
+
+fn main() {}