about summary refs log tree commit diff
path: root/src/test/ui/monomorphize-abi-alignment.rs
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 01:33:01 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 18:56:16 +0300
commit9be35f82c1abf2ecbab489bca9eca138ea648312 (patch)
tree69888506e34af447d9748c0d542de3ba1dd76210 /src/test/ui/monomorphize-abi-alignment.rs
parentca9faa52f5ada0054b1fa27d97aedf448afb059b (diff)
downloadrust-9be35f82c1abf2ecbab489bca9eca138ea648312.tar.gz
rust-9be35f82c1abf2ecbab489bca9eca138ea648312.zip
tests: Move run-pass tests without naming conflicts to ui
Diffstat (limited to 'src/test/ui/monomorphize-abi-alignment.rs')
-rw-r--r--src/test/ui/monomorphize-abi-alignment.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/ui/monomorphize-abi-alignment.rs b/src/test/ui/monomorphize-abi-alignment.rs
new file mode 100644
index 00000000000..637b09fc04e
--- /dev/null
+++ b/src/test/ui/monomorphize-abi-alignment.rs
@@ -0,0 +1,34 @@
+// run-pass
+
+#![allow(non_upper_case_globals)]
+/*!
+ * On x86_64-linux-gnu and possibly other platforms, structs get 8-byte "preferred" alignment,
+ * but their "ABI" alignment (i.e., what actually matters for data layout) is the largest alignment
+ * of any field. (Also, `u64` has 8-byte ABI alignment; this is not always true).
+ *
+ * On such platforms, if monomorphize uses the "preferred" alignment, then it will unify
+ * `A` and `B`, even though `S<A>` and `S<B>` have the field `t` at different offsets,
+ * and apply the wrong instance of the method `unwrap`.
+ */
+
+#[derive(Copy, Clone)]
+struct S<T> { i:u8, t:T }
+
+impl<T> S<T> {
+    fn unwrap(self) -> T {
+        self.t
+    }
+}
+
+#[derive(Copy, Clone, PartialEq, Debug)]
+struct A((u32, u32));
+
+#[derive(Copy, Clone, PartialEq, Debug)]
+struct B(u64);
+
+pub fn main() {
+    static Ca: S<A> = S { i: 0, t: A((13, 104)) };
+    static Cb: S<B> = S { i: 0, t: B(31337) };
+    assert_eq!(Ca.unwrap(), A((13, 104)));
+    assert_eq!(Cb.unwrap(), B(31337));
+}