about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-03-13 09:57:38 +0000
committerbors <bors@rust-lang.org>2017-03-13 09:57:38 +0000
commitddc1708b739dcd9c87b84ec0bc4a997cb2b41634 (patch)
tree1b63e24495f8d94fd871f23a111099d4d32fd379 /src/test/codegen
parent40e5b18609c015cf6e331a08aa1e2f13c0d52b82 (diff)
parent32c9893432634a4de0ad9f743e28e87f60a1b778 (diff)
downloadrust-ddc1708b739dcd9c87b84ec0bc4a997cb2b41634.tar.gz
rust-ddc1708b739dcd9c87b84ec0bc4a997cb2b41634.zip
Auto merge of #40385 - arielb1:packed-again, r=eddyb
emit !align attributes on stores of operand pairs

This avoids another case of missing-align UB. cc #40373

r? @eddyb
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/packed.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/codegen/packed.rs b/src/test/codegen/packed.rs
index db2cd3b4165..99e6e38a3bf 100644
--- a/src/test/codegen/packed.rs
+++ b/src/test/codegen/packed.rs
@@ -27,3 +27,36 @@ pub fn write_pkd(pkd: &mut Packed) -> u32 {
     pkd.data = 42;
     result
 }
+
+pub struct Array([i32; 8]);
+#[repr(packed)]
+pub struct BigPacked {
+    dealign: u8,
+    data: Array
+}
+
+// CHECK-LABEL: @call_pkd
+#[no_mangle]
+pub fn call_pkd(f: fn() -> Array) -> BigPacked {
+// CHECK: [[ALLOCA:%[_a-z0-9]+]] = alloca %Array
+// CHECK: call void %{{.*}}(%Array* noalias nocapture sret dereferenceable(32) [[ALLOCA]])
+// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 32, i32 1, i1 false)
+    // check that calls whose destination is a field of a packed struct
+    // go through an alloca rather than calling the function with an
+    // unaligned destination.
+    BigPacked { dealign: 0, data: f() }
+}
+
+#[repr(packed)]
+#[derive(Copy, Clone)]
+pub struct PackedPair(u8, u32);
+
+// CHECK-LABEL: @pkd_pair
+#[no_mangle]
+pub fn pkd_pair(pair1: &mut PackedPair, pair2: &mut PackedPair) {
+    // CHECK: [[V1:%[a-z0-9]+]] = load i8, i8* %{{.*}}, align 1
+    // CHECK: [[V2:%[a-z0-9]+]] = load i32, i32* %{{.*}}, align 1
+    // CHECK: store i8 [[V1]], i8* {{.*}}, align 1
+    // CHECK: store i32 [[V2]], i32* {{.*}}, align 1
+    *pair2 = *pair1;
+}