| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR |
| 3 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM |
| 5 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG |
| 7 |
|
| 8 |
typedef union { |
| 9 |
int x; |
| 10 |
int y : 4; |
| 11 |
int z : 8; |
| 12 |
} demo; |
| 13 |
|
| 14 |
// CIR: !rec_demo = !cir.record<union "demo" {!s32i, !u8i, !u8i}> |
| 15 |
// LLVM: %union.demo = type { i32 } |
| 16 |
// OGCG: %union.demo = type { i32 } |
| 17 |
|
| 18 |
typedef union { |
| 19 |
int x; |
| 20 |
int y : 3; |
| 21 |
int : 0; |
| 22 |
int z : 2; |
| 23 |
} zero_bit; |
| 24 |
|
| 25 |
// CIR: !rec_zero_bit = !cir.record<union "zero_bit" {!s32i, !u8i, !u8i}> |
| 26 |
// LLVM: %union.zero_bit = type { i32 } |
| 27 |
// OGCG: %union.zero_bit = type { i32 } |
| 28 |
|
| 29 |
demo d; |
| 30 |
zero_bit z; |
| 31 |
|
| 32 |
void f() { |
| 33 |
demo d; |
| 34 |
d.x = 1; |
| 35 |
d.y = 2; |
| 36 |
d.z = 0; |
| 37 |
} |
| 38 |
|
| 39 |
// CIR: #bfi_y = #cir.bitfield_info<name = "y", storage_type = !u8i, size = 4, offset = 0, is_signed = true> |
| 40 |
// CIR: #bfi_z = #cir.bitfield_info<name = "z", storage_type = !u8i, size = 8, offset = 0, is_signed = true> |
| 41 |
|
| 42 |
// CIR: cir.func {{.*}} @f |
| 43 |
// CIR: [[ALLOC:%.*]] = cir.alloca !rec_demo, !cir.ptr<!rec_demo>, ["d"] {alignment = 4 : i64} |
| 44 |
// CIR: [[ONE:%.*]] = cir.const #cir.int<1> : !s32i |
| 45 |
// CIR: [[X:%.*]] = cir.get_member [[ALLOC]][0] {name = "x"} : !cir.ptr<!rec_demo> -> !cir.ptr<!s32i> |
| 46 |
// CIR: cir.store align(4) [[ONE]], [[X]] : !s32i, !cir.ptr<!s32i> |
| 47 |
// CIR: [[TWO:%.*]] = cir.const #cir.int<2> : !s32i |
| 48 |
// CIR: [[Y:%.*]] = cir.get_member [[ALLOC]][1] {name = "y"} : !cir.ptr<!rec_demo> -> !cir.ptr<!u8i> |
| 49 |
// CIR: [[SET:%.*]] = cir.set_bitfield align(4) (#bfi_y, [[Y]] : !cir.ptr<!u8i>, [[TWO]] : !s32i) -> !s32i |
| 50 |
// CIR: [[ZERO:%.*]] = cir.const #cir.int<0> : !s32i |
| 51 |
// CIR: [[Z:%.*]] = cir.get_member [[ALLOC]][2] {name = "z"} : !cir.ptr<!rec_demo> -> !cir.ptr<!u8i> |
| 52 |
// CIR: [[SET2:%.*]] = cir.set_bitfield align(4) (#bfi_z, [[Z]] : !cir.ptr<!u8i>, [[ZERO]] : !s32i) -> !s32i |
| 53 |
// CIR: cir.return |
| 54 |
|
| 55 |
// LLVM: define dso_local void @f |
| 56 |
// LLVM: [[ALLOC:%.*]] = alloca %union.demo, i64 1, align 4 |
| 57 |
// LLVM: store i32 1, ptr [[ALLOC]], align 4 |
| 58 |
// LLVM: [[BFLOAD:%.*]] = load i8, ptr [[ALLOC]], align 4 |
| 59 |
// LLVM: [[CLEAR:%.*]] = and i8 [[BFLOAD]], -16 |
| 60 |
// LLVM: [[SET:%.*]] = or i8 [[CLEAR]], 2 |
| 61 |
// LLVM: store i8 [[SET]], ptr [[ALLOC]], align 4 |
| 62 |
// LLVM: store i8 0, ptr [[ALLOC]], align 4 |
| 63 |
|
| 64 |
// OGCG: define dso_local void @f |
| 65 |
// OGCG: [[ALLOC:%.*]] = alloca %union.demo, align 4 |
| 66 |
// OGCG: store i32 1, ptr [[ALLOC]], align 4 |
| 67 |
// OGCG: [[BFLOAD:%.*]] = load i8, ptr [[ALLOC]], align 4 |
| 68 |
// OGCG: [[CLEAR:%.*]] = and i8 [[BFLOAD]], -16 |
| 69 |
// OGCG: [[SET:%.*]] = or i8 [[CLEAR]], 2 |
| 70 |
// OGCG: store i8 [[SET]], ptr [[ALLOC]], align 4 |
| 71 |
// OGCG: store i8 0, ptr [[ALLOC]], align 4 |