1 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -o - %s | opt -S -strip -o %t 2 // RUX: llvm-gcc -flto -S -O3 -o %t %s 3 // RUN: FileCheck --check-prefix=CHECK-GLOBAL < %t %s 4 // RUN: FileCheck --check-prefix=CHECK-FUNCTIONS < %t %s 5 6 struct s0 { 7 int x; 8 int y __attribute__((packed)); 9 }; 10 11 // CHECK-GLOBAL: @s0_align_x = global i32 4 12 13 // CHECK-GLOBAL: @s0_align_y = global i32 1 14 15 // CHECK-GLOBAL: @s0_align = global i32 4 16 int s0_align_x = __alignof(((struct s0*)0)->x); 17 int s0_align_y = __alignof(((struct s0*)0)->y); 18 int s0_align = __alignof(struct s0); 19 20 // CHECK-FUNCTIONS: define i32 @s0_load_x 21 // CHECK-FUNCTIONS: [[s0_load_x:%.*]] = load i32* {{.*}}, align 4 22 // CHECK-FUNCTIONS: ret i32 [[s0_load_x]] 23 int s0_load_x(struct s0 *a) { return a->x; } 24 // FIXME: This seems like it should be align 1. This is actually something which 25 // has changed in llvm-gcc recently, previously both x and y would be loaded 26 // with align 1 (in 2363.1 at least). 27 // 28 // CHECK-FUNCTIONS: define i32 @s0_load_y 29 // CHECK-FUNCTIONS: [[s0_load_y:%.*]] = load i32* {{.*}}, align 1 30 // CHECK-FUNCTIONS: ret i32 [[s0_load_y]] 31 int s0_load_y(struct s0 *a) { return a->y; } 32 // CHECK-FUNCTIONS: define void @s0_copy 33 // CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 8, i32 4, i1 false) 34 void s0_copy(struct s0 *a, struct s0 *b) { *b = *a; } 35 36 // 37 38 struct s1 { 39 int x; 40 int y; 41 } __attribute__((packed)); 42 43 // CHECK-GLOBAL: @s1_align_x = global i32 1 44 // CHECK-GLOBAL: @s1_align_y = global i32 1 45 // CHECK-GLOBAL: @s1_align = global i32 1 46 int s1_align_x = __alignof(((struct s1*)0)->x); 47 int s1_align_y = __alignof(((struct s1*)0)->y); 48 int s1_align = __alignof(struct s1); 49 50 // CHECK-FUNCTIONS: define i32 @s1_load_x 51 // CHECK-FUNCTIONS: [[s1_load_x:%.*]] = load i32* {{.*}}, align 1 52 // CHECK-FUNCTIONS: ret i32 [[s1_load_x]] 53 int s1_load_x(struct s1 *a) { return a->x; } 54 // CHECK-FUNCTIONS: define i32 @s1_load_y 55 // CHECK-FUNCTIONS: [[s1_load_y:%.*]] = load i32* {{.*}}, align 1 56 // CHECK-FUNCTIONS: ret i32 [[s1_load_y]] 57 int s1_load_y(struct s1 *a) { return a->y; } 58 // CHECK-FUNCTIONS: define void @s1_copy 59 // CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 8, i32 1, i1 false) 60 void s1_copy(struct s1 *a, struct s1 *b) { *b = *a; } 61 62 // 63 64 #pragma pack(push,2) 65 struct s2 { 66 int x; 67 int y; 68 }; 69 #pragma pack(pop) 70 71 // CHECK-GLOBAL: @s2_align_x = global i32 2 72 // CHECK-GLOBAL: @s2_align_y = global i32 2 73 // CHECK-GLOBAL: @s2_align = global i32 2 74 int s2_align_x = __alignof(((struct s2*)0)->x); 75 int s2_align_y = __alignof(((struct s2*)0)->y); 76 int s2_align = __alignof(struct s2); 77 78 // CHECK-FUNCTIONS: define i32 @s2_load_x 79 // CHECK-FUNCTIONS: [[s2_load_y:%.*]] = load i32* {{.*}}, align 2 80 // CHECK-FUNCTIONS: ret i32 [[s2_load_y]] 81 int s2_load_x(struct s2 *a) { return a->x; } 82 // CHECK-FUNCTIONS: define i32 @s2_load_y 83 // CHECK-FUNCTIONS: [[s2_load_y:%.*]] = load i32* {{.*}}, align 2 84 // CHECK-FUNCTIONS: ret i32 [[s2_load_y]] 85 int s2_load_y(struct s2 *a) { return a->y; } 86 // CHECK-FUNCTIONS: define void @s2_copy 87 // CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 8, i32 2, i1 false) 88 void s2_copy(struct s2 *a, struct s2 *b) { *b = *a; } 89 90 struct __attribute__((packed, aligned)) s3 { 91 short aShort; 92 int anInt; 93 }; 94 // CHECK-GLOBAL: @s3_1 = global i32 1 95 int s3_1 = __alignof(((struct s3*) 0)->anInt); 96 // CHECK-FUNCTIONS: define i32 @test3( 97 int test3(struct s3 *ptr) { 98 // CHECK-FUNCTIONS: [[PTR:%.*]] = getelementptr inbounds {{%.*}}* {{%.*}}, i32 0, i32 1 99 // CHECK-FUNCTIONS-NEXT: load i32* [[PTR]], align 1 100 return ptr->anInt; 101 } 102