|
| 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 | + |
| 4 | +void A(void) { |
| 5 | + void *ptr = &&LABEL_A; |
| 6 | +LABEL_A: |
| 7 | + return; |
| 8 | +} |
| 9 | +// CIR: cir.func dso_local @A |
| 10 | +// 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 ^bb1 |
| 14 | +// CIR: ^bb1: // pred: ^bb0 |
| 15 | +// CIR: cir.label "LABEL_A" |
| 16 | +// CIR: cir.return |
| 17 | + |
| 18 | +void B(void) { |
| 19 | +LABEL_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 ^bb1 |
| 26 | +// 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.return |
| 31 | + |
| 32 | +void C(int x) { |
| 33 | + void *ptr = (x == 0) ? &&LABEL_A : &&LABEL_B; |
| 34 | +LABEL_A: |
| 35 | + return; |
| 36 | +LABEL_B: |
| 37 | + return; |
| 38 | +} |
| 39 | + |
| 40 | +// CIR: cir.func dso_local @C |
| 41 | +// 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 ^bb1 |
| 46 | +// CIR: ^bb1: // pred: ^bb0 |
| 47 | +// CIR: cir.label "LABEL_A" |
| 48 | +// CIR: cir.br ^bb2 |
| 49 | +// CIR: ^bb2: // 2 preds: ^bb1, ^bb3 |
| 50 | +// CIR: cir.return |
| 51 | +// CIR: ^bb3: // no predecessors |
| 52 | +// CIR: cir.label "LABEL_B" |
| 53 | +// CIR: cir.br ^bb2 |
| 54 | + |
| 55 | +void D(void) { |
| 56 | + void *ptr = &&LABEL_A; |
| 57 | + void *ptr2 = &&LABEL_A; |
| 58 | +LABEL_A: |
| 59 | + void *ptr3 = &&LABEL_A; |
| 60 | + return; |
| 61 | +} |
| 62 | + |
| 63 | +// CIR: cir.func dso_local @D |
| 64 | +// 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 ^bb1 |
| 72 | +// CIR: ^bb1: // pred: ^bb0 |
| 73 | +// 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.return |
0 commit comments