158 lines · c
1// RUN: %clang_cc1 -triple x86_64-unk-unk -emit-llvm -Os -o %t %s2// RUN: FileCheck < %t %s3 4struct s0 {5 unsigned int x[2] __attribute__((packed));6};7 8struct s1 {9 unsigned int x[2] __attribute__((packed));10 unsigned int y;11 unsigned int z __attribute__((packed));12};13 14struct s2 {15 unsigned int x[2] __attribute__((packed));16 unsigned int y __attribute__((packed));17 unsigned int z __attribute__((packed));18};19 20struct __attribute__((packed)) s3 {21 unsigned int x[2];22 unsigned int y;23 unsigned int z;24};25 26// CHECK: @align0 ={{.*}} local_unnamed_addr global i32 127int align0 = __alignof(struct s0);28// CHECK: @align1 ={{.*}} local_unnamed_addr global i32 429int align1 = __alignof(struct s1);30// CHECK: @align2 ={{.*}} local_unnamed_addr global i32 131int align2 = __alignof(struct s2);32// CHECK: @align3 ={{.*}} local_unnamed_addr global i32 133int align3 = __alignof(struct s3);34 35// CHECK: @align0_x ={{.*}} local_unnamed_addr global i32 136int align0_x = __alignof(((struct s0*) 0)->x);37//38// CHECK: @align1_x ={{.*}} local_unnamed_addr global i32 139int align1_x = __alignof(((struct s1*) 0)->x);40// CHECK: @align2_x ={{.*}} local_unnamed_addr global i32 141int align2_x = __alignof(((struct s2*) 0)->x);42// CHECK: @align3_x ={{.*}} local_unnamed_addr global i32 143int align3_x = __alignof(((struct s3*) 0)->x);44 45// CHECK: @align0_x0 ={{.*}} local_unnamed_addr global i32 446int align0_x0 = __alignof(((struct s0*) 0)->x[0]);47// CHECK: @align1_x0 ={{.*}} local_unnamed_addr global i32 448int align1_x0 = __alignof(((struct s1*) 0)->x[0]);49// CHECK: @align2_x0 ={{.*}} local_unnamed_addr global i32 450int align2_x0 = __alignof(((struct s2*) 0)->x[0]);51// CHECK: @align3_x0 ={{.*}} local_unnamed_addr global i32 452int align3_x0 = __alignof(((struct s3*) 0)->x[0]);53 54// CHECK-LABEL: define{{.*}} i32 @f0_a55// CHECK: load i32, ptr %{{.*}}, align 156// CHECK: }57// CHECK-LABEL: define{{.*}} i32 @f0_b58// CHECK: load i32, ptr %{{.*}}, align 159// CHECK: }60int f0_a(struct s0 *a) {61 return a->x[1];62}63int f0_b(struct s0 *a) {64 return *(a->x + 1);65}66 67// Note that 'y' still causes struct s1 to be four-byte aligned.68 69// Note that we are incompatible with GCC on this example.70// 71// CHECK-LABEL: define{{.*}} i32 @f1_a72// CHECK: load i32, ptr %{{.*}}, align 473// CHECK: }74// CHECK-LABEL: define{{.*}} i32 @f1_b75// CHECK: load i32, ptr %{{.*}}, align 476// CHECK: }77 78// Note that we are incompatible with GCC on this example.79//80// CHECK-LABEL: define{{.*}} i32 @f1_c81// CHECK: load i32, ptr %{{.*}}, align 482// CHECK: }83// CHECK-LABEL: define{{.*}} i32 @f1_d84// CHECK: load i32, ptr %{{.*}}, align 485// CHECK: }86int f1_a(struct s1 *a) {87 return a->x[1];88}89int f1_b(struct s1 *a) {90 return *(a->x + 1);91}92int f1_c(struct s1 *a) {93 return a->y;94}95int f1_d(struct s1 *a) {96 return a->z;97}98 99// CHECK-LABEL: define{{.*}} i32 @f2_a100// CHECK: load i32, ptr %{{.*}}, align 1101// CHECK: }102// CHECK-LABEL: define{{.*}} i32 @f2_b103// CHECK: load i32, ptr %{{.*}}, align 1104// CHECK: }105// CHECK-LABEL: define{{.*}} i32 @f2_c106// CHECK: load i32, ptr %{{.*}}, align 1107// CHECK: }108// CHECK-LABEL: define{{.*}} i32 @f2_d109// CHECK: load i32, ptr %{{.*}}, align 1110// CHECK: }111int f2_a(struct s2 *a) {112 return a->x[1];113}114int f2_b(struct s2 *a) {115 return *(a->x + 1);116}117int f2_c(struct s2 *a) {118 return a->y;119}120int f2_d(struct s2 *a) {121 return a->z;122}123 124// CHECK-LABEL: define{{.*}} i32 @f3_a125// CHECK: load i32, ptr %{{.*}}, align 1126// CHECK: }127// CHECK-LABEL: define{{.*}} i32 @f3_b128// CHECK: load i32, ptr %{{.*}}, align 1129// CHECK: }130// CHECK-LABEL: define{{.*}} i32 @f3_c131// CHECK: load i32, ptr %{{.*}}, align 1132// CHECK: }133// CHECK-LABEL: define{{.*}} i32 @f3_d134// CHECK: load i32, ptr %{{.*}}, align 1135// CHECK: }136int f3_a(struct s3 *a) {137 return a->x[1];138}139int f3_b(struct s3 *a) {140 return *(a->x + 1);141}142int f3_c(struct s3 *a) {143 return a->y;144}145int f3_d(struct s3 *a) {146 return a->z;147}148 149// Verify we don't claim things are overaligned.150//151// CHECK-LABEL: define{{.*}} double @f4152// CHECK: load double, ptr {{.*}}, align 8153// CHECK: }154extern double g4[5] __attribute__((aligned(16)));155double f4(void) {156 return g4[1];157}158