115 lines · c
1// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR3// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM5// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG7 8typedef struct {9 int a : 4;10 int b : 11;11 int c : 17;12} S;13 14// CIR: !rec_S = !cir.record<struct "S" {!u32i}>15// LLVM: %struct.S = type { i32 }16// OGCG: %struct.S = type { i32 }17void def() {18 S s;19}20int init(S* s) {21 return s->c;22}23 24//CIR: cir.func dso_local @init25//CIR: [[TMP0:%.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["s", init] {alignment = 8 : i64}26//CIR: [[TMP1:%.*]] = cir.load align(8) [[TMP0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>27//CIR: [[TMP2:%.*]] = cir.get_member [[TMP1]][0] {name = "c"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i>28//CIR: [[TMP3:%.*]] = cir.get_bitfield align(4) (#bfi_c, [[TMP2]] : !cir.ptr<!u32i>) -> !s32i29 30//LLVM: define dso_local i32 @init(ptr %0){{.*}} {31//LLVM: [[TMP0:%.*]] = alloca ptr, i64 1, align 832//LLVM: [[TMP1:%.*]] = alloca i32, i64 1, align 433//LLVM: [[TMP2:%.*]] = load ptr, ptr [[TMP0]], align 834//LLVM: [[TMP3:%.*]] = getelementptr %struct.S, ptr [[TMP2]], i32 0, i32 035//LLVM: [[TMP4:%.*]] = load i32, ptr [[TMP3]], align 436//LLVM: [[TMP5:%.*]] = shl i32 [[TMP4]], 1537//LLVM: [[TMP6:%.*]] = ashr i32 [[TMP5]], 1538 39//OGCG: define dso_local i32 @init40//OGCG: [[TMP0:%.*]] = alloca ptr, align 841//OGCG: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 842//OGCG: [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 443//OGCG: [[TMP3:%.*]] = shl i32 [[TMP2]], 1544//OGCG: [[TMP4:%.*]] = ashr i32 [[TMP3]], 1545 46 47void load(S* s) {48 s->a = -4;49 s->b = 42;50 s->c = -12345;51}52 53// field 'a'54// CIR: cir.func dso_local @load55// CIR: %[[PTR0:.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["s", init] {alignment = 8 : i64} loc(#loc35)56// CIR: %[[CONST1:.*]] = cir.const #cir.int<4> : !s32i57// CIR: %[[MIN1:.*]] = cir.unary(minus, %[[CONST1]]) nsw : !s32i, !s32i58// CIR: %[[VAL0:.*]] = cir.load align(8) %[[PTR0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>59// CIR: %[[GET0:.*]] = cir.get_member %[[VAL0]][0] {name = "a"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i>60// CIR: %[[SET0:.*]] = cir.set_bitfield align(4) (#bfi_a, %[[GET0]] : !cir.ptr<!u32i>, %[[MIN1]] : !s32i) -> !s32i61 62// LLVM: define dso_local void @load{{.*}}{{.*}}63// LLVM: %[[PTR0:.*]] = load ptr64// LLVM: %[[GET0:.*]] = getelementptr %struct.S, ptr %[[PTR0]], i32 0, i32 065// LLVM: %[[VAL0:.*]] = load i32, ptr %[[GET0]], align 466// LLVM: %[[AND0:.*]] = and i32 %[[VAL0]], 26843545567// LLVM: %[[OR0:.*]] = or i32 %[[AND0]], -107374182468// LLVM: store i32 %[[OR0]], ptr %[[GET0]], align 469 70// OGCG: define dso_local void @load71// OGCG: %[[PTR0:.*]] = load ptr72// OGCG: %[[VAL0:.*]] = load i32, ptr %[[PTR0]], align 473// OGCG: %[[AND0:.*]] = and i32 %[[VAL0]], 26843545574// OGCG: %[[OR0:.*]] = or i32 %[[AND0]], -107374182475// OGCG: store i32 %[[OR0]], ptr %[[PTR0]], align 476 77// field 'b'78// CIR: %[[CONST2:.*]] = cir.const #cir.int<42> : !s32i79// CIR: %[[VAL1:.*]] = cir.load align(8) %[[PTR0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>80// CIR: %[[GET1:.*]] = cir.get_member %[[VAL1]][0] {name = "b"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i>81// CIR: %[[SET1:.*]] = cir.set_bitfield align(4) (#bfi_b, %[[GET1]] : !cir.ptr<!u32i>, %[[CONST2]] : !s32i) -> !s32i82 83// LLVM: %[[PTR1:.*]] = load ptr84// LLVM: %[[GET1:.*]] = getelementptr %struct.S, ptr %[[PTR1]], i32 0, i32 085// LLVM: %[[VAL1:.*]] = load i32, ptr %[[GET1]], align 486// LLVM: %[[AND1:.*]] = and i32 %[[VAL1]], -26830438587// LLVM: %[[OR1:.*]] = or i32 %[[AND1]], 550502488// LLVM: store i32 %[[OR1]], ptr %[[GET1]], align 489 90// OGCG: %[[PTR1:.*]] = load ptr91// OGCG: %[[VAL1:.*]] = load i32, ptr %[[PTR1]], align 492// OGCG: %[[AND1:.*]] = and i32 %[[VAL1]], -26830438593// OGCG: %[[OR1:.*]] = or i32 %[[AND1]], 550502494// OGCG: store i32 %[[OR1]], ptr %[[PTR1]], align 495 96// field 'c'97// CIR: %[[CONST3:.*]] = cir.const #cir.int<12345> : !s32i98// CIR: %[[MIN2:.*]] = cir.unary(minus, %[[CONST3]]) nsw : !s32i, !s32i99// CIR: %[[VAL2:.*]] = cir.load align(8) %[[PTR0]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>100// CIR: %[[GET2:.*]] = cir.get_member %[[VAL2]][0] {name = "c"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i>101// CIR: %[[SET2:.*]] = cir.set_bitfield align(4) (#bfi_c, %[[GET2]] : !cir.ptr<!u32i>, %[[MIN2]] : !s32i) -> !s32i102 103// LLVM: %[[PTR2:.*]] = load ptr104// LLVM: %[[GET2:.*]] = getelementptr %struct.S, ptr %[[PTR2]], i32 0, i32 0105// LLVM: %[[VAL2:.*]] = load i32, ptr %[[GET2]], align 4106// LLVM: %[[AND2:.*]] = and i32 %[[VAL2]], -131072107// LLVM: %[[OR2:.*]] = or i32 %[[AND2]], 118727108// LLVM: store i32 %[[OR2]], ptr %[[GET2]], align 4109 110// OGCG: %[[PTR2:.*]] = load ptr111// OGCG: %[[VAL2:.*]] = load i32, ptr %[[PTR2]], align 4112// OGCG: %[[AND2:.*]] = and i32 %[[VAL2]], -131072113// OGCG: %[[OR2:.*]] = or i32 %[[AND2]], 118727114// OGCG: store i32 %[[OR2]], ptr %[[PTR2]], align 4115