207 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// RUN: %clang_cc1 -triple x86_64-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 x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG7 8void label() {9labelA:10 return;11}12 13// CIR: cir.func no_proto dso_local @label14// CIR: cir.br ^bb115// CIR: ^bb1:16// CIR: cir.label "labelA"17// CIR: cir.return18 19// LLVM:define dso_local void @label20// LLVM: br label %121// LLVM: 1:22// LLVM: ret void23 24// OGCG: define dso_local void @label25// OGCG: br label %labelA26// OGCG: labelA:27// OGCG: ret void28 29void multiple_labels() {30labelB:31labelC:32 return;33}34 35// CIR: cir.func no_proto dso_local @multiple_labels36// CIR: cir.br ^bb137// CIR: ^bb1:38// CIR: cir.label "labelB"39// CIR: cir.br ^bb240// CIR: ^bb2:41// CIR: cir.label "labelC"42// CIR: cir.return43 44// LLVM: define dso_local void @multiple_labels(){{.*}}45// LLVM: br label %146// LLVM: 1:47// LLVM: br label %248// LLVM: 2:49// LLVM: ret void50 51// OGCG: define dso_local void @multiple_labels52// OGCG: br label %labelB53// OGCG: labelB:54// OGCG: br label %labelC55// OGCG: labelC:56// OGCG: ret void57 58void label_in_if(int cond) {59 if (cond) {60labelD:61 cond++;62 }63}64 65// CIR: cir.func dso_local @label_in_if66// CIR: cir.if {{.*}} {67// CIR: cir.br ^bb168// CIR: ^bb1:69// CIR: cir.label "labelD"70// CIR: [[LOAD:%.*]] = cir.load align(4) [[COND:%.*]] : !cir.ptr<!s32i>, !s32i71// CIR: [[INC:%.*]] = cir.unary(inc, %3) nsw : !s32i, !s32i72// CIR: cir.store align(4) [[INC]], [[COND]] : !s32i, !cir.ptr<!s32i>73// CIR: }74// CIR: cir.return75 76// LLVM: define dso_local void @label_in_if{{.*}}77// LLVM: br label %378// LLVM: 3:79// LLVM: [[LOAD:%.*]] = load i32, ptr [[COND:%.*]], align 480// LLVM: [[CMP:%.*]] = icmp ne i32 [[LOAD]], 081// LLVM: br i1 [[CMP]], label %6, label %1082// LLVM: 6:83// LLVM: br label %784// LLVM: 7:85// LLVM: [[LOAD2:%.*]] = load i32, ptr [[COND]], align 486// LLVM: [[ADD1:%.*]] = add nsw i32 [[LOAD2]], 187// LLVM: store i32 [[ADD1]], ptr [[COND]], align 488// LLVM: br label %1089// LLVM: 10:90// LLVM: br label %1191// LLVM: 11:92// LLVM: ret void93 94// OGCG: define dso_local void @label_in_if95// OGCG: if.then:96// OGCG: br label %labelD97// OGCG: labelD:98// OGCG: [[LOAD:%.*]] = load i32, ptr [[COND:%.*]], align 499// OGCG: [[INC:%.*]] = add nsw i32 %1, 1100// OGCG: store i32 [[INC]], ptr [[COND]], align 4101// OGCG: br label %if.end102// OGCG: if.end:103// OGCG: ret void104 105void after_return() {106 return;107 label:108}109 110// CIR: cir.func no_proto dso_local @after_return111// CIR: cir.br ^bb1112// CIR: ^bb1: // 2 preds: ^bb0, ^bb2113// CIR: cir.return114// CIR: ^bb2: // no predecessors115// CIR: cir.label "label"116// CIR: cir.br ^bb1117 118// LLVM: define dso_local void @after_return{{.*}}119// LLVM: br label %1120// LLVM: 1:121// LLVM: ret void122// LLVM: 2:123// LLVM: br label %1124 125// OGCG: define dso_local void @after_return126// OGCG: br label %label127// OGCG: label:128// OGCG: ret void129 130 131void after_unreachable() {132 __builtin_unreachable();133 label:134}135 136// CIR: cir.func no_proto dso_local @after_unreachable137// CIR: cir.unreachable138// CIR: ^bb1:139// CIR: cir.label "label"140// CIR: cir.return141 142// LLVM: define dso_local void @after_unreachable{{.*}}143// LLVM: unreachable144// LLVM: 1:145// LLVM: ret void146 147// OGCG: define dso_local void @after_unreachable148// OGCG: unreachable149// OGCG: label:150// OGCG: ret void151 152void labelWithoutMatch() {153end:154 return;155}156// CIR: cir.func no_proto dso_local @labelWithoutMatch157// CIR: cir.br ^bb1158// CIR: ^bb1:159// CIR: cir.label "end"160// CIR: cir.return161// CIR: }162 163// LLVM: define dso_local void @labelWithoutMatch164// LLVM: br label %1165// LLVM: 1:166// LLVM: ret void167 168// OGCG: define dso_local void @labelWithoutMatch169// OGCG: br label %end170// OGCG: end:171// OGCG: ret void172 173struct S {};174struct S get();175void bar(struct S);176 177void foo() {178 {179 label:180 bar(get());181 }182}183 184// CIR: cir.func no_proto dso_local @foo185// CIR: cir.scope {186// CIR: %0 = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["agg.tmp0"]187// CIR: cir.br ^bb1188// CIR: ^bb1:189// CIR: cir.label "label"190 191// LLVM: define dso_local void @foo(){{.*}} {192// LLVM: [[ALLOC:%.*]] = alloca %struct.S, i64 1, align 1193// LLVM: br label %2194// LLVM:2:195// LLVM: br label %3196// LLVM:3:197// LLVM: [[CALL:%.*]] = call %struct.S @get()198// LLVM: store %struct.S [[CALL]], ptr [[ALLOC]], align 1199// LLVM: [[LOAD:%.*]] = load %struct.S, ptr [[ALLOC]], align 1200// LLVM: call void @bar(%struct.S [[LOAD]])201 202// OGCG: define dso_local void @foo()203// OGCG: %agg.tmp = alloca %struct.S, align 1204// OGCG: %undef.agg.tmp = alloca %struct.S, align 1205// OGCG: br label %label206// OGCG: label:207