| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s |
| 5 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s |
| 7 |
|
| 8 |
// Should generate a union type with all members preserved. |
| 9 |
union U { |
| 10 |
bool b; |
| 11 |
short s; |
| 12 |
int i; |
| 13 |
float f; |
| 14 |
double d; |
| 15 |
}; |
| 16 |
// CIR: !rec_U = !cir.record<union "U" {!cir.bool, !s16i, !s32i, !cir.float, !cir.double}> |
| 17 |
// LLVM: %union.U = type { double } |
| 18 |
// OGCG: %union.U = type { double } |
| 19 |
|
| 20 |
void shouldGenerateUnionAccess(union U u) { |
| 21 |
u.b = true; |
| 22 |
u.b; |
| 23 |
u.i = 1; |
| 24 |
u.i; |
| 25 |
u.f = 0.1F; |
| 26 |
u.f; |
| 27 |
u.d = 0.1; |
| 28 |
u.d; |
| 29 |
} |
| 30 |
// CIR: cir.func {{.*}}shouldGenerateUnionAccess |
| 31 |
// CIR: %[[#BASE:]] = cir.get_member %0[0] {name = "b"} : !cir.ptr<!rec_U> -> !cir.ptr<!cir.bool> |
| 32 |
// CIR: cir.store{{.*}} %{{.+}}, %[[#BASE]] : !cir.bool, !cir.ptr<!cir.bool> |
| 33 |
// CIR: cir.get_member %0[0] {name = "b"} : !cir.ptr<!rec_U> -> !cir.ptr<!cir.bool> |
| 34 |
// CIR: %[[#BASE:]] = cir.get_member %0[2] {name = "i"} : !cir.ptr<!rec_U> -> !cir.ptr<!s32i> |
| 35 |
// CIR: cir.store{{.*}} %{{.+}}, %[[#BASE]] : !s32i, !cir.ptr<!s32i> |
| 36 |
// CIR: %[[#BASE:]] = cir.get_member %0[2] {name = "i"} : !cir.ptr<!rec_U> -> !cir.ptr<!s32i> |
| 37 |
// CIR: %[[#BASE:]] = cir.get_member %0[3] {name = "f"} : !cir.ptr<!rec_U> -> !cir.ptr<!cir.float> |
| 38 |
// CIR: cir.store{{.*}} %{{.+}}, %[[#BASE]] : !cir.float, !cir.ptr<!cir.float> |
| 39 |
// CIR: %[[#BASE:]] = cir.get_member %0[3] {name = "f"} : !cir.ptr<!rec_U> -> !cir.ptr<!cir.float> |
| 40 |
// CIR: %[[#BASE:]] = cir.get_member %0[4] {name = "d"} : !cir.ptr<!rec_U> -> !cir.ptr<!cir.double> |
| 41 |
// CIR: cir.store{{.*}} %{{.+}}, %[[#BASE]] : !cir.double, !cir.ptr<!cir.double> |
| 42 |
// CIR: %[[#BASE:]] = cir.get_member %0[4] {name = "d"} : !cir.ptr<!rec_U> -> !cir.ptr<!cir.double> |
| 43 |
|
| 44 |
// LLVM: define {{.*}}shouldGenerateUnionAccess |
| 45 |
// LLVM: %[[BASE:.*]] = alloca %union.U |
| 46 |
// LLVM: store %union.U %{{.*}}, ptr %[[BASE]] |
| 47 |
// LLVM: store i8 1, ptr %[[BASE]] |
| 48 |
// LLVM: store i32 1, ptr %[[BASE]] |
| 49 |
// LLVM: store float 0x3FB99999A0000000, ptr %[[BASE]] |
| 50 |
// LLVM: store double 1.000000e-01, ptr %[[BASE]] |
| 51 |
|
| 52 |
// OGCG: define {{.*}}shouldGenerateUnionAccess |
| 53 |
// OGCG: %[[BASE:.*]] = alloca %union.U |
| 54 |
// OGCG: %[[DIVE:.*]] = getelementptr inbounds nuw %union.U, ptr %[[BASE]], i32 0, i32 0 |
| 55 |
// OGCG: store i64 %{{.*}}, ptr %[[DIVE]] |
| 56 |
// OGCG: store i8 1, ptr %[[BASE]] |
| 57 |
// OGCG: store i32 1, ptr %[[BASE]] |
| 58 |
// OGCG: store float 0x3FB99999A0000000, ptr %[[BASE]] |
| 59 |
// OGCG: store double 1.000000e-01, ptr %[[BASE]] |