95 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG7 8// PR5279 - Reduced alignment on typedef.9typedef int myint __attribute__((aligned(1)));10 11void test1(myint *p) {12 *p = 0;13}14 15// CIR: cir.func{{.*}} @test116// CIR: cir.store align(1)17 18// LLVM: @test119// LLVM: store i32 0, ptr {{.*}}, align 120// LLVM: ret void21 22// OGCG: @test123// OGCG: store i32 0, ptr {{.*}}, align 124// OGCG: ret void25 26typedef unsigned char uint8_t;27typedef unsigned short uint16_t;28typedef unsigned int uint32_t;29typedef unsigned long long uint64_t;30typedef struct31{32 uint16_t i16;33 uint32_t i32;34 uint16_t i16_2;35 uint32_t i32_2;36} StructA;37 38void test2(StructA* p) {39 p->i16 = 1;40 p->i32 = 2;41 p->i16_2 = 3;42 p->i32_2 = 4;43}44 45// CIR-LABEL: @test246// CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u16i, !cir.ptr<!u16i>47// CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u32i, !cir.ptr<!u32i>48// CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u16i, !cir.ptr<!u16i>49// CIR: cir.store align(4) %{{.*}}, %{{.*}} : !u32i, !cir.ptr<!u32i>50 51// LLVM: @test252// LLVM: store i16 1, ptr {{.*}}, align 453// LLVM: store i32 2, ptr {{.*}}, align 454// LLVM: store i16 3, ptr {{.*}}, align 455// LLVM: store i32 4, ptr {{.*}}, align 456 57// OGCG: @test258// OGCG: store i16 1, ptr {{.*}}, align 459// OGCG: store i32 2, ptr {{.*}}, align 460// OGCG: store i16 3, ptr {{.*}}, align 461// OGCG: store i32 4, ptr {{.*}}, align 462 63typedef struct {64 short a;65 short b;66 short c;67 short d;68 long e; // Make the struct 8-byte aligned69} StructB;70 71void test3(StructB *ptr) {72 ptr->a = 1; // align 873 ptr->b = 2; // align 274 ptr->c = 3; // align 475 ptr->d = 4; // align 276}77 78// CIR-LABEL: @test379// CIR: cir.store align(8) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>80// CIR: cir.store align(2) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>81// CIR: cir.store align(4) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>82// CIR: cir.store align(2) %{{.*}}, %{{.*}} : !s16i, !cir.ptr<!s16i>83 84// LLVM: @test385// LLVM: store i16 1, ptr {{.*}}, align 886// LLVM: store i16 2, ptr {{.*}}, align 287// LLVM: store i16 3, ptr {{.*}}, align 488// LLVM: store i16 4, ptr {{.*}}, align 289 90// OGCG: @test391// OGCG: store i16 1, ptr {{.*}}, align 892// OGCG: store i16 2, ptr {{.*}}, align 293// OGCG: store i16 3, ptr {{.*}}, align 494// OGCG: store i16 4, ptr {{.*}}, align 295