94 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -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 -std=c++20 -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 -std=c++20 -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 8struct Struct {9 int a;10 float b;11 double c;12 bool d;13};14 15void offset_of_builtin() {16 unsigned long a = __builtin_offsetof(Struct, a);17 unsigned long b = __builtin_offsetof(Struct, b);18 unsigned long c = __builtin_offsetof(Struct, c);19 unsigned long d = __builtin_offsetof(Struct, d);20}21 22// CIR: %[[A_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["a", init]23// CIR: %[[B_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["b", init]24// CIR: %[[C_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["c", init]25// CIR: %[[D_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["d", init]26// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !u64i27// CIR: cir.store {{.*}} %[[CONST_0]], %[[A_ADDR]] : !u64i, !cir.ptr<!u64i>28// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !u64i29// CIR: cir.store {{.*}} %[[CONST_4]], %[[B_ADDR]] : !u64i, !cir.ptr<!u64i>30// CIR: %[[CONST_8:.*]] = cir.const #cir.int<8> : !u64i31// CIR: cir.store {{.*}} %[[CONST_8]], %[[C_ADDR]] : !u64i, !cir.ptr<!u64i>32// CIR: %[[CONST_16:.*]] = cir.const #cir.int<16> : !u64i33// CIR: cir.store {{.*}} %[[CONST_16]], %[[D_ADDR]] : !u64i, !cir.ptr<!u64i>34 35// LLVM: %[[A_ADDR:.*]] = alloca i64, i64 1, align 836// LLVM: %[[B_ADDR:.*]] = alloca i64, i64 1, align 837// LLVM: %[[C_ADDR:.*]] = alloca i64, i64 1, align 838// LLVM: %[[D_ADDR:.*]] = alloca i64, i64 1, align 839// LLVM: store i64 0, ptr %[[A_ADDR]], align 840// LLVM: store i64 4, ptr %[[B_ADDR]], align 841// LLVM: store i64 8, ptr %[[C_ADDR]], align 842// LLVM: store i64 16, ptr %[[D_ADDR]], align 843 44// OGCG: %[[A_ADDR:.*]] = alloca i64, align 845// OGCG: %[[B_ADDR:.*]] = alloca i64, align 846// OGCG: %[[C_ADDR:.*]] = alloca i64, align 847// OGCG: %[[D_ADDR:.*]] = alloca i64, align 848// OGCG: store i64 0, ptr %[[A_ADDR]], align 849// OGCG: store i64 4, ptr %[[B_ADDR]], align 850// OGCG: store i64 8, ptr %[[C_ADDR]], align 851// OGCG: store i64 16, ptr %[[D_ADDR]], align 852 53struct StructWithArray {54 Struct array[4][4];55};56 57void offset_of_builtin_from_array_element() {58 unsigned long a = __builtin_offsetof(StructWithArray, array[0][0].a);59 unsigned long b = __builtin_offsetof(StructWithArray, array[1][1].b);60 unsigned long c = __builtin_offsetof(StructWithArray, array[2][2].c);61 unsigned long d = __builtin_offsetof(StructWithArray, array[3][3].d);62}63 64// CIR: %[[A_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["a", init]65// CIR: %[[B_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["b", init]66// CIR: %[[C_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["c", init]67// CIR: %[[D_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["d", init]68// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !u64i69// CIR: cir.store {{.*}} %[[CONST_0]], %[[A_ADDR]] : !u64i, !cir.ptr<!u64i>70// CIR: %[[CONST_124:.*]] = cir.const #cir.int<124> : !u64i71// CIR: cir.store {{.*}} %[[CONST_124]], %[[B_ADDR]] : !u64i, !cir.ptr<!u64i>72// CIR: %[[CONST_248:.*]] = cir.const #cir.int<248> : !u64i73// CIR: cir.store {{.*}} %[[CONST_248]], %[[C_ADDR]] : !u64i, !cir.ptr<!u64i>74// CIR: %[[CONST_376:.*]] = cir.const #cir.int<376> : !u64i75// CIR: cir.store {{.*}} %[[CONST_376]], %[[D_ADDR]] : !u64i, !cir.ptr<!u64i>76 77// LLVM: %[[A_ADDR:.*]] = alloca i64, i64 1, align 878// LLVM: %[[B_ADDR:.*]] = alloca i64, i64 1, align 879// LLVM: %[[C_ADDR:.*]] = alloca i64, i64 1, align 880// LLVM: %[[D_ADDR:.*]] = alloca i64, i64 1, align 881// LLVM: store i64 0, ptr %[[A_ADDR]], align 882// LLVM: store i64 124, ptr %[[B_ADDR]], align 883// LLVM: store i64 248, ptr %[[C_ADDR]], align 884// LLVM: store i64 376, ptr %[[D_ADDR]], align 885 86// OGCG: %[[A_ADDR:.*]] = alloca i64, align 887// OGCG: %[[B_ADDR:.*]] = alloca i64, align 888// OGCG: %[[C_ADDR:.*]] = alloca i64, align 889// OGCG: %[[D_ADDR:.*]] = alloca i64, align 890// OGCG: store i64 0, ptr %[[A_ADDR]], align 891// OGCG: store i64 124, ptr %[[B_ADDR]], align 892// OGCG: store i64 248, ptr %[[C_ADDR]], align 893// OGCG: store i64 376, ptr %[[D_ADDR]], align 894