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