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