1*67e74705SXin Li // RUN: %clang_cc1 %s -triple x86_64-apple-macosx10.7.2 -emit-llvm -o - | FileCheck %s
2*67e74705SXin Li
3*67e74705SXin Li struct X { int x[6]; };
4*67e74705SXin Li struct Y { char x[13]; struct X y; } __attribute((packed));
5*67e74705SXin Li struct Y g;
6*67e74705SXin Li void f(struct X);
7*67e74705SXin Li struct X foo(void);
8*67e74705SXin Li
9*67e74705SXin Li // <rdar://problem/10463337>
test1()10*67e74705SXin Li struct X test1() {
11*67e74705SXin Li // CHECK: @test1
12*67e74705SXin Li // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y, %struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false)
13*67e74705SXin Li return g.y;
14*67e74705SXin Li }
test2()15*67e74705SXin Li struct X test2() {
16*67e74705SXin Li // CHECK: @test2
17*67e74705SXin Li // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y, %struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false)
18*67e74705SXin Li struct X a = g.y;
19*67e74705SXin Li return a;
20*67e74705SXin Li }
21*67e74705SXin Li
test3(struct X a)22*67e74705SXin Li void test3(struct X a) {
23*67e74705SXin Li // CHECK: @test3
24*67e74705SXin Li // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y, %struct.Y* @g, i32 0, i32 1) to i8*), i8* {{.*}}, i64 24, i32 1, i1 false)
25*67e74705SXin Li g.y = a;
26*67e74705SXin Li }
27*67e74705SXin Li
28*67e74705SXin Li // <rdar://problem/10530444>
test4()29*67e74705SXin Li void test4() {
30*67e74705SXin Li // CHECK: @test4
31*67e74705SXin Li // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y, %struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false)
32*67e74705SXin Li f(g.y);
33*67e74705SXin Li }
34*67e74705SXin Li
35*67e74705SXin Li // PR12395
test5()36*67e74705SXin Li int test5() {
37*67e74705SXin Li // CHECK: @test5
38*67e74705SXin Li // CHECK: load i32, i32* getelementptr inbounds (%struct.Y, %struct.Y* @g, i32 0, i32 1, i32 0, i64 0), align 1
39*67e74705SXin Li return g.y.x[0];
40*67e74705SXin Li }
41*67e74705SXin Li
42*67e74705SXin Li // <rdar://problem/11220251>
test6()43*67e74705SXin Li void test6() {
44*67e74705SXin Li // CHECK: @test6
45*67e74705SXin Li // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y, %struct.Y* @g, i32 0, i32 1) to i8*), i8* %{{.*}}, i64 24, i32 1, i1 false)
46*67e74705SXin Li g.y = foo();
47*67e74705SXin Li }
48*67e74705SXin Li
49*67e74705SXin Li
50*67e74705SXin Li struct XBitfield {
51*67e74705SXin Li unsigned b1 : 10;
52*67e74705SXin Li unsigned b2 : 12;
53*67e74705SXin Li unsigned b3 : 10;
54*67e74705SXin Li };
55*67e74705SXin Li struct YBitfield {
56*67e74705SXin Li char x;
57*67e74705SXin Li struct XBitfield y;
58*67e74705SXin Li } __attribute((packed));
59*67e74705SXin Li struct YBitfield gbitfield;
60*67e74705SXin Li
test7()61*67e74705SXin Li unsigned test7() {
62*67e74705SXin Li // CHECK: @test7
63*67e74705SXin Li // CHECK: load i32, i32* getelementptr inbounds (%struct.YBitfield, %struct.YBitfield* @gbitfield, i32 0, i32 1, i32 0), align 1
64*67e74705SXin Li return gbitfield.y.b2;
65*67e74705SXin Li }
66*67e74705SXin Li
test8(unsigned x)67*67e74705SXin Li void test8(unsigned x) {
68*67e74705SXin Li // CHECK: @test8
69*67e74705SXin Li // CHECK: load i32, i32* getelementptr inbounds (%struct.YBitfield, %struct.YBitfield* @gbitfield, i32 0, i32 1, i32 0), align 1
70*67e74705SXin Li // CHECK: store i32 {{.*}}, i32* getelementptr inbounds (%struct.YBitfield, %struct.YBitfield* @gbitfield, i32 0, i32 1, i32 0), align 1
71*67e74705SXin Li gbitfield.y.b2 = x;
72*67e74705SXin Li }
73*67e74705SXin Li
74*67e74705SXin Li struct TBitfield
75*67e74705SXin Li {
76*67e74705SXin Li long a;
77*67e74705SXin Li char b;
78*67e74705SXin Li unsigned c:15;
79*67e74705SXin Li };
80*67e74705SXin Li struct TBitfield tbitfield;
81*67e74705SXin Li
test9()82*67e74705SXin Li unsigned test9() {
83*67e74705SXin Li // CHECK: @test9
84*67e74705SXin Li // CHECK: load i16, i16* getelementptr inbounds (%struct.TBitfield, %struct.TBitfield* @tbitfield, i32 0, i32 2), align 1
85*67e74705SXin Li return tbitfield.c;
86*67e74705SXin Li }
87*67e74705SXin Li
test10(unsigned x)88*67e74705SXin Li void test10(unsigned x) {
89*67e74705SXin Li // CHECK: @test10
90*67e74705SXin Li // CHECK: load i16, i16* getelementptr inbounds (%struct.TBitfield, %struct.TBitfield* @tbitfield, i32 0, i32 2), align 1
91*67e74705SXin Li // CHECK: store i16 {{.*}}, i16* getelementptr inbounds (%struct.TBitfield, %struct.TBitfield* @tbitfield, i32 0, i32 2), align 1
92*67e74705SXin Li tbitfield.c = x;
93*67e74705SXin Li }
94*67e74705SXin Li
95