1 // RUN: %clang_cc1 %s -triple x86_64-apple-macosx10.7.2 -emit-llvm -o - | FileCheck %s 2 3 struct X { int x[6]; }; 4 struct Y { char x[13]; struct X y; } __attribute((packed)); 5 struct Y g; 6 void f(struct X); 7 struct X foo(void); 8 9 // <rdar://problem/10463337> 10 struct X test1() { 11 // CHECK: @test1 12 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false) 13 return g.y; 14 } 15 struct X test2() { 16 // CHECK: @test2 17 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false) 18 struct X a = g.y; 19 return a; 20 } 21 22 void test3(struct X a) { 23 // CHECK: @test3 24 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1) to i8*), i8* {{.*}}, i64 24, i32 1, i1 false) 25 g.y = a; 26 } 27 28 // <rdar://problem/10530444> 29 void test4() { 30 // CHECK: @test4 31 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false) 32 f(g.y); 33 } 34 35 // PR12395 36 int test5() { 37 // CHECK: @test5 38 // CHECK: load i32* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1, i32 0, i64 0), align 1 39 return g.y.x[0]; 40 } 41 42 // <rdar://problem/11220251> 43 void test6() { 44 // CHECK: @test6 45 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1) to i8*), i8* %{{.*}}, i64 24, i32 1, i1 false) 46 g.y = foo(); 47 } 48 49 50 struct XBitfield { 51 unsigned b1 : 10; 52 unsigned b2 : 12; 53 unsigned b3 : 10; 54 }; 55 struct YBitfield { 56 char x; 57 struct XBitfield y; 58 } __attribute((packed)); 59 struct YBitfield gbitfield; 60 61 unsigned test7() { 62 // CHECK: @test7 63 // CHECK: load i32* getelementptr inbounds (%struct.YBitfield* @gbitfield, i32 0, i32 1, i32 0), align 4 64 return gbitfield.y.b2; 65 } 66