blob: 6097e3f32eae725a8fa2fee70d885cac21ccc47a [file] [log] [blame]
Eli Friedmanbd7d8282011-12-05 22:23:28 +00001// RUN: %clang_cc1 %s -triple x86_64-apple-macosx10.7.2 -emit-llvm -o - | FileCheck %s
Eli Friedmanbd7d8282011-12-05 22:23:28 +00002
3struct X { int x[6]; };
4struct Y { char x[13]; struct X y; } __attribute((packed));
5struct Y g;
6void f(struct X);
Chad Rosier7fea7c82012-04-17 00:35:38 +00007struct X foo(void);
Eli Friedmanbd7d8282011-12-05 22:23:28 +00008
Eli Friedman377ecc72012-04-16 03:54:45 +00009// <rdar://problem/10463337>
Eli Friedmanbd7d8282011-12-05 22:23:28 +000010struct 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}
15struct 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
22void 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
Eli Friedman377ecc72012-04-16 03:54:45 +000028// <rdar://problem/10530444>
Eli Friedmanbd7d8282011-12-05 22:23:28 +000029void test4() {
30 // CHECK: @test4
31 // FIXME: 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}
Eli Friedman377ecc72012-04-16 03:54:45 +000034
35// PR12395
36int 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}
Chad Rosier7fea7c82012-04-17 00:35:38 +000041
42// <rdar://problem/11220251>
43void test6() {
44 // CHECK: @test6
Eli Friedman7d6c8a12012-04-17 01:57:28 +000045 // 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)
Chad Rosier7fea7c82012-04-17 00:35:38 +000046 g.y = foo();
47}
Eli Friedmanf4bcfa12012-06-27 21:19:48 +000048
49
50struct XBitfield {
51 unsigned b1 : 10;
52 unsigned b2 : 12;
53 unsigned b3 : 10;
54};
55struct YBitfield {
56 char x;
57 struct XBitfield y;
58} __attribute((packed));
59struct YBitfield gbitfield;
60
61unsigned test7() {
62 // CHECK: @test7
63 // CHECK: load i32* bitcast (%struct.XBitfield* getelementptr inbounds (%struct.YBitfield* @gbitfield, i32 0, i32 1) to i32*), align 1
64 return gbitfield.y.b2;
65}