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