Daniel Dunbar | d553408 | 2011-04-01 00:49:43 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -triple x86_64-unk-unk -emit-llvm -Os -o %t %s |
| 2 | // RUN: FileCheck < %t %s |
| 3 | |
| 4 | struct s0 { |
| 5 | unsigned int x[2] __attribute__((packed)); |
| 6 | }; |
| 7 | |
| 8 | struct s1 { |
| 9 | unsigned int x[2] __attribute__((packed)); |
| 10 | unsigned int y; |
| 11 | unsigned int z __attribute__((packed)); |
| 12 | }; |
| 13 | |
| 14 | struct s2 { |
| 15 | unsigned int x[2] __attribute__((packed)); |
| 16 | unsigned int y __attribute__((packed)); |
| 17 | unsigned int z __attribute__((packed)); |
| 18 | }; |
| 19 | |
| 20 | struct __attribute__((packed)) s3 { |
| 21 | unsigned int x[2]; |
| 22 | unsigned int y; |
| 23 | unsigned int z; |
| 24 | }; |
| 25 | |
| 26 | // CHECK: @align0 = global i32 1 |
| 27 | int align0 = __alignof(struct s0); |
| 28 | // CHECK: @align1 = global i32 4 |
| 29 | int align1 = __alignof(struct s1); |
| 30 | // CHECK: @align2 = global i32 1 |
| 31 | int align2 = __alignof(struct s2); |
| 32 | // CHECK: @align3 = global i32 1 |
| 33 | int align3 = __alignof(struct s3); |
| 34 | |
| 35 | // CHECK: @align0_x = global i32 1 |
| 36 | int align0_x = __alignof(((struct s0*) 0)->x); |
| 37 | // We are currently incompatible with GCC here. <rdar://problem/9217290> |
| 38 | // |
| 39 | // CHECK-XFAIL: @align1_x = global i32 1 |
| 40 | // CHECK: @align1_x = global i32 4 |
| 41 | int align1_x = __alignof(((struct s1*) 0)->x); |
| 42 | // CHECK: @align2_x = global i32 1 |
| 43 | int align2_x = __alignof(((struct s2*) 0)->x); |
| 44 | // CHECK: @align3_x = global i32 1 |
| 45 | int align3_x = __alignof(((struct s3*) 0)->x); |
| 46 | |
| 47 | // CHECK: @align0_x0 = global i32 4 |
| 48 | int align0_x0 = __alignof(((struct s0*) 0)->x[0]); |
| 49 | // CHECK: @align1_x0 = global i32 4 |
| 50 | int align1_x0 = __alignof(((struct s1*) 0)->x[0]); |
| 51 | // CHECK: @align2_x0 = global i32 4 |
| 52 | int align2_x0 = __alignof(((struct s2*) 0)->x[0]); |
| 53 | // CHECK: @align3_x0 = global i32 4 |
| 54 | int align3_x0 = __alignof(((struct s3*) 0)->x[0]); |
| 55 | |
| 56 | // CHECK: define i32 @f0_a |
| 57 | // CHECK: load i32* %{{.*}}, align 1 |
| 58 | // CHECK: } |
| 59 | // CHECK: define i32 @f0_b |
| 60 | // CHECK: load i32* %{{.*}}, align 4 |
| 61 | // CHECK: } |
| 62 | int f0_a(struct s0 *a) { |
| 63 | return a->x[1]; |
| 64 | } |
| 65 | int f0_b(struct s0 *a) { |
| 66 | return *(a->x + 1); |
| 67 | } |
| 68 | |
| 69 | // CHECK: define i32 @f1_a |
| 70 | // CHECK: load i32* %{{.*}}, align 4 |
| 71 | // CHECK: } |
| 72 | // CHECK: define i32 @f1_b |
| 73 | // CHECK: load i32* %{{.*}}, align 4 |
| 74 | // CHECK: } |
| 75 | |
| 76 | // Note that we are incompatible with GCC on these two examples. |
| 77 | // |
| 78 | // CHECK: define i32 @f1_c |
| 79 | // CHECK-XFAIL: load i32* %{{.*}}, align 1 |
| 80 | // CHECK: load i32* %{{.*}}, align 4 |
| 81 | // CHECK: } |
| 82 | // CHECK: define i32 @f1_d |
| 83 | // CHECK-XFAIL: load i32* %{{.*}}, align 1 |
| 84 | // CHECK: load i32* %{{.*}}, align 4 |
| 85 | // CHECK: } |
| 86 | int f1_a(struct s1 *a) { |
| 87 | return a->x[1]; |
| 88 | } |
| 89 | int f1_b(struct s1 *a) { |
| 90 | return *(a->x + 1); |
| 91 | } |
| 92 | int f1_c(struct s1 *a) { |
| 93 | return a->y; |
| 94 | } |
| 95 | int f1_d(struct s1 *a) { |
| 96 | return a->z; |
| 97 | } |
| 98 | |
| 99 | // CHECK: define i32 @f2_a |
| 100 | // CHECK: load i32* %{{.*}}, align 1 |
| 101 | // CHECK: } |
| 102 | // CHECK: define i32 @f2_b |
| 103 | // CHECK: load i32* %{{.*}}, align 4 |
| 104 | // CHECK: } |
| 105 | // CHECK: define i32 @f2_c |
| 106 | // CHECK: load i32* %{{.*}}, align 1 |
| 107 | // CHECK: } |
| 108 | // CHECK: define i32 @f2_d |
| 109 | // CHECK: load i32* %{{.*}}, align 1 |
| 110 | // CHECK: } |
| 111 | int f2_a(struct s2 *a) { |
| 112 | return a->x[1]; |
| 113 | } |
| 114 | int f2_b(struct s2 *a) { |
| 115 | return *(a->x + 1); |
| 116 | } |
| 117 | int f2_c(struct s2 *a) { |
| 118 | return a->y; |
| 119 | } |
| 120 | int f2_d(struct s2 *a) { |
| 121 | return a->z; |
| 122 | } |
| 123 | |
| 124 | // CHECK: define i32 @f3_a |
| 125 | // CHECK: load i32* %{{.*}}, align 1 |
| 126 | // CHECK: } |
| 127 | // CHECK: define i32 @f3_b |
| 128 | // CHECK: load i32* %{{.*}}, align 4 |
| 129 | // CHECK: } |
| 130 | // CHECK: define i32 @f3_c |
| 131 | // CHECK: load i32* %{{.*}}, align 1 |
| 132 | // CHECK: } |
| 133 | // CHECK: define i32 @f3_d |
| 134 | // CHECK: load i32* %{{.*}}, align 1 |
| 135 | // CHECK: } |
| 136 | int f3_a(struct s3 *a) { |
| 137 | return a->x[1]; |
| 138 | } |
| 139 | int f3_b(struct s3 *a) { |
| 140 | return *(a->x + 1); |
| 141 | } |
| 142 | int f3_c(struct s3 *a) { |
| 143 | return a->y; |
| 144 | } |
| 145 | int f3_d(struct s3 *a) { |
| 146 | return a->z; |
| 147 | } |
| 148 | |
| 149 | // Verify we don't claim things are overaligned. |
| 150 | // |
| 151 | // CHECK: define double @f4 |
| 152 | // CHECK: load double* {{.*}}, align 8 |
| 153 | // CHECK: } |
| 154 | extern double g4[5] __attribute__((aligned(16))); |
| 155 | double f4() { |
| 156 | return g4[1]; |
| 157 | } |