about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2017-03-09 13:28:26 +0200
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-03-13 11:52:41 +0200
commit32c9893432634a4de0ad9f743e28e87f60a1b778 (patch)
treea201c492db33d44b0007f0a5259bd88b46cab37b /src/test/codegen
parent5d0be0d72a8fe87c1a038f014beb7f64ba249b29 (diff)
downloadrust-32c9893432634a4de0ad9f743e28e87f60a1b778.tar.gz
rust-32c9893432634a4de0ad9f743e28e87f60a1b778.zip
emit !align attributes on stores of operand pairs
cc #40373
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;
+}