77 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR3 4void A(void) {5 void *ptr = &&LABEL_A;6LABEL_A:7 return;8}9// CIR: cir.func dso_local @A10// CIR: [[PTR:%.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] {alignment = 8 : i64}11// CIR: [[BLOCK:%.*]] = cir.block_address <@A, "LABEL_A"> : !cir.ptr<!void>12// CIR: cir.store align(8) [[BLOCK]], [[PTR]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>13// CIR: cir.br ^bb114// CIR: ^bb1: // pred: ^bb015// CIR: cir.label "LABEL_A"16// CIR: cir.return17 18void B(void) {19LABEL_B:20 void *ptr = &&LABEL_B;21}22 23// CIR: cir.func dso_local @B()24// CIR: [[PTR:%.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init] {alignment = 8 : i64}25// CIR: cir.br ^bb126// CIR: ^bb1:27// CIR: cir.label "LABEL_B"28// CIR: [[BLOCK:%.*]] = cir.block_address <@B, "LABEL_B"> : !cir.ptr<!void>29// CIR: cir.store align(8) [[BLOCK]], [[PTR]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>30// CIR: cir.return31 32void C(int x) {33 void *ptr = (x == 0) ? &&LABEL_A : &&LABEL_B;34LABEL_A:35 return;36LABEL_B:37 return;38}39 40// CIR: cir.func dso_local @C41// CIR: [[BLOCK1:%.*]] = cir.block_address <@C, "LABEL_A"> : !cir.ptr<!void>42// CIR: [[BLOCK2:%.*]] = cir.block_address <@C, "LABEL_B"> : !cir.ptr<!void>43// CIR: [[COND:%.*]] = cir.select if [[CMP:%.*]] then [[BLOCK1]] else [[BLOCK2]] : (!cir.bool, !cir.ptr<!void>, !cir.ptr<!void>) -> !cir.ptr<!void>44// CIR: cir.store align(8) [[COND]], [[PTR:%.*]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>45// CIR: cir.br ^bb146// CIR: ^bb1: // pred: ^bb047// CIR: cir.label "LABEL_A"48// CIR: cir.br ^bb249// CIR: ^bb2: // 2 preds: ^bb1, ^bb350// CIR: cir.return51// CIR: ^bb3: // no predecessors52// CIR: cir.label "LABEL_B"53// CIR: cir.br ^bb254 55void D(void) {56 void *ptr = &&LABEL_A;57 void *ptr2 = &&LABEL_A;58LABEL_A:59 void *ptr3 = &&LABEL_A;60 return;61}62 63// CIR: cir.func dso_local @D64// CIR: %[[PTR:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr", init]65// CIR: %[[PTR2:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr2", init]66// CIR: %[[PTR3:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["ptr3", init]67// CIR: %[[BLK1:.*]] = cir.block_address <@D, "LABEL_A"> : !cir.ptr<!void>68// CIR: cir.store align(8) %[[BLK1]], %[[PTR]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>69// CIR: %[[BLK2:.*]] = cir.block_address <@D, "LABEL_A"> : !cir.ptr<!void>70// CIR: cir.store align(8) %[[BLK2]], %[[PTR2]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>71// CIR: cir.br ^bb172// CIR: ^bb1: // pred: ^bb073// CIR: cir.label "LABEL_A"74// CIR: %[[BLK3:.*]] = cir.block_address <@D, "LABEL_A"> : !cir.ptr<!void>75// CIR: cir.store align(8) %[[BLK3]], %[[PTR3]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>76// CIR: cir.return77