| 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 |
void label() { |
| 9 |
labelA: |
| 10 |
return; |
| 11 |
} |
| 12 |
|
| 13 |
// CIR: cir.func {{.*}} @label |
| 14 |
// CIR: cir.br ^bb1 |
| 15 |
// CIR: ^bb1: |
| 16 |
// CIR: cir.label "labelA" |
| 17 |
// CIR: cir.return |
| 18 |
|
| 19 |
// LLVM:define dso_local void @label |
| 20 |
// LLVM: br label %1 |
| 21 |
// LLVM: 1: |
| 22 |
// LLVM: ret void |
| 23 |
|
| 24 |
// OGCG: define dso_local void @label |
| 25 |
// OGCG: br label %labelA |
| 26 |
// OGCG: labelA: |
| 27 |
// OGCG: ret void |
| 28 |
|
| 29 |
void multiple_labels() { |
| 30 |
labelB: |
| 31 |
labelC: |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
// CIR: cir.func {{.*}} @multiple_labels |
| 36 |
// CIR: cir.br ^bb1 |
| 37 |
// CIR: ^bb1: |
| 38 |
// CIR: cir.label "labelB" |
| 39 |
// CIR: cir.br ^bb2 |
| 40 |
// CIR: ^bb2: |
| 41 |
// CIR: cir.label "labelC" |
| 42 |
// CIR: cir.return |
| 43 |
|
| 44 |
// LLVM: define dso_local void @multiple_labels(){{.*}} |
| 45 |
// LLVM: br label %1 |
| 46 |
// LLVM: 1: |
| 47 |
// LLVM: br label %2 |
| 48 |
// LLVM: 2: |
| 49 |
// LLVM: ret void |
| 50 |
|
| 51 |
// OGCG: define dso_local void @multiple_labels |
| 52 |
// OGCG: br label %labelB |
| 53 |
// OGCG: labelB: |
| 54 |
// OGCG: br label %labelC |
| 55 |
// OGCG: labelC: |
| 56 |
// OGCG: ret void |
| 57 |
|
| 58 |
void label_in_if(int cond) { |
| 59 |
if (cond) { |
| 60 |
labelD: |
| 61 |
cond++; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
// CIR: cir.func {{.*}} @label_in_if |
| 66 |
// CIR: cir.if {{.*}} { |
| 67 |
// CIR: cir.br ^bb1 |
| 68 |
// CIR: ^bb1: |
| 69 |
// CIR: cir.label "labelD" |
| 70 |
// CIR: [[LOAD:%.*]] = cir.load align(4) [[COND:%.*]] : !cir.ptr<!s32i>, !s32i |
| 71 |
// CIR: [[INC:%.*]] = cir.unary(inc, %3) nsw : !s32i, !s32i |
| 72 |
// CIR: cir.store align(4) [[INC]], [[COND]] : !s32i, !cir.ptr<!s32i> |
| 73 |
// CIR: } |
| 74 |
// CIR: cir.return |
| 75 |
|
| 76 |
// LLVM: define dso_local void @label_in_if{{.*}} |
| 77 |
// LLVM: br label %3 |
| 78 |
// LLVM: 3: |
| 79 |
// LLVM: [[LOAD:%.*]] = load i32, ptr [[COND:%.*]], align 4 |
| 80 |
// LLVM: [[CMP:%.*]] = icmp ne i32 [[LOAD]], 0 |
| 81 |
// LLVM: br i1 [[CMP]], label %6, label %10 |
| 82 |
// LLVM: 6: |
| 83 |
// LLVM: br label %7 |
| 84 |
// LLVM: 7: |
| 85 |
// LLVM: [[LOAD2:%.*]] = load i32, ptr [[COND]], align 4 |
| 86 |
// LLVM: [[ADD1:%.*]] = add nsw i32 [[LOAD2]], 1 |
| 87 |
// LLVM: store i32 [[ADD1]], ptr [[COND]], align 4 |
| 88 |
// LLVM: br label %10 |
| 89 |
// LLVM: 10: |
| 90 |
// LLVM: br label %11 |
| 91 |
// LLVM: 11: |
| 92 |
// LLVM: ret void |
| 93 |
|
| 94 |
// OGCG: define dso_local void @label_in_if |
| 95 |
// OGCG: if.then: |
| 96 |
// OGCG: br label %labelD |
| 97 |
// OGCG: labelD: |
| 98 |
// OGCG: [[LOAD:%.*]] = load i32, ptr [[COND:%.*]], align 4 |
| 99 |
// OGCG: [[INC:%.*]] = add nsw i32 %1, 1 |
| 100 |
// OGCG: store i32 [[INC]], ptr [[COND]], align 4 |
| 101 |
// OGCG: br label %if.end |
| 102 |
// OGCG: if.end: |
| 103 |
// OGCG: ret void |
| 104 |
|
| 105 |
void after_return() { |
| 106 |
return; |
| 107 |
label: |
| 108 |
} |
| 109 |
|
| 110 |
// CIR: cir.func {{.*}} @after_return |
| 111 |
// CIR: cir.br ^bb1 |
| 112 |
// CIR: ^bb1: // 2 preds: ^bb0, ^bb2 |
| 113 |
// CIR: cir.return |
| 114 |
// CIR: ^bb2: // no predecessors |
| 115 |
// CIR: cir.label "label" |
| 116 |
// CIR: cir.br ^bb1 |
| 117 |
|
| 118 |
// LLVM: define dso_local void @after_return{{.*}} |
| 119 |
// LLVM: br label %1 |
| 120 |
// LLVM: 1: |
| 121 |
// LLVM: ret void |
| 122 |
// LLVM: 2: |
| 123 |
// LLVM: br label %1 |
| 124 |
|
| 125 |
// OGCG: define dso_local void @after_return |
| 126 |
// OGCG: br label %label |
| 127 |
// OGCG: label: |
| 128 |
// OGCG: ret void |
| 129 |
|
| 130 |
|
| 131 |
void after_unreachable() { |
| 132 |
__builtin_unreachable(); |
| 133 |
label: |
| 134 |
} |
| 135 |
|
| 136 |
// CIR: cir.func {{.*}} @after_unreachable |
| 137 |
// CIR: cir.unreachable |
| 138 |
// CIR: ^bb1: |
| 139 |
// CIR: cir.label "label" |
| 140 |
// CIR: cir.return |
| 141 |
|
| 142 |
// LLVM: define dso_local void @after_unreachable{{.*}} |
| 143 |
// LLVM: unreachable |
| 144 |
// LLVM: 1: |
| 145 |
// LLVM: ret void |
| 146 |
|
| 147 |
// OGCG: define dso_local void @after_unreachable |
| 148 |
// OGCG: unreachable |
| 149 |
// OGCG: label: |
| 150 |
// OGCG: ret void |
| 151 |
|
| 152 |
void labelWithoutMatch() { |
| 153 |
end: |
| 154 |
return; |
| 155 |
} |
| 156 |
// CIR: cir.func {{.*}} @labelWithoutMatch |
| 157 |
// CIR: cir.br ^bb1 |
| 158 |
// CIR: ^bb1: |
| 159 |
// CIR: cir.label "end" |
| 160 |
// CIR: cir.return |
| 161 |
// CIR: } |
| 162 |
|
| 163 |
// LLVM: define dso_local void @labelWithoutMatch |
| 164 |
// LLVM: br label %1 |
| 165 |
// LLVM: 1: |
| 166 |
// LLVM: ret void |
| 167 |
|
| 168 |
// OGCG: define dso_local void @labelWithoutMatch |
| 169 |
// OGCG: br label %end |
| 170 |
// OGCG: end: |
| 171 |
// OGCG: ret void |
| 172 |
|
| 173 |
struct S {}; |
| 174 |
struct S get(); |
| 175 |
void bar(struct S); |
| 176 |
|
| 177 |
void foo() { |
| 178 |
{ |
| 179 |
label: |
| 180 |
bar(get()); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
// CIR: cir.func {{.*}} @foo |
| 185 |
// CIR: cir.scope { |
| 186 |
// CIR: %0 = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["agg.tmp0"] |
| 187 |
// CIR: cir.br ^bb1 |
| 188 |
// CIR: ^bb1: |
| 189 |
// CIR: cir.label "label" |
| 190 |
|
| 191 |
// LLVM: define dso_local void @foo(){{.*}} { |
| 192 |
// LLVM: [[ALLOC:%.*]] = alloca %struct.S, i64 1, align 1 |
| 193 |
// LLVM: br label %2 |
| 194 |
// LLVM:2: |
| 195 |
// LLVM: br label %3 |
| 196 |
// LLVM:3: |
| 197 |
// LLVM: [[CALL:%.*]] = call %struct.S @get() |
| 198 |
// LLVM: store %struct.S [[CALL]], ptr [[ALLOC]], align 1 |
| 199 |
// LLVM: [[LOAD:%.*]] = load %struct.S, ptr [[ALLOC]], align 1 |
| 200 |
// LLVM: call void @bar(%struct.S [[LOAD]]) |
| 201 |
|
| 202 |
// OGCG: define dso_local void @foo() |
| 203 |
// OGCG: %agg.tmp = alloca %struct.S, align 1 |
| 204 |
// OGCG: %undef.agg.tmp = alloca %struct.S, align 1 |
| 205 |
// OGCG: br label %label |
| 206 |
// OGCG: label: |