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