Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ mlir::LogicalResult CIRGenFunction::emitLabel(const clang::LabelDecl &d) {
mlir::Block *currBlock = builder.getBlock();
mlir::Block *labelBlock = currBlock;

if (!currBlock->empty()) {
if (!currBlock->empty() || currBlock->isEntryBlock()) {
{
mlir::OpBuilder::InsertionGuard guard(builder);
labelBlock = builder.createBlock(builder.getBlock()->getParent());
Expand Down
27 changes: 26 additions & 1 deletion clang/test/CIR/CodeGen/goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ extern "C" void case_follow_label(int v) {
// CIR: cir.func dso_local @case_follow_label
// CIR: cir.switch
// CIR: cir.case(equal, [#cir.int<1> : !s32i]) {
// CIR: cir.br ^bb1
// CIR: ^bb1:
// CIR: cir.label "label"
// CIR: cir.case(equal, [#cir.int<2> : !s32i]) {
// CIR: cir.call @action1()
Expand All @@ -215,9 +217,11 @@ extern "C" void case_follow_label(int v) {

// LLVM: define dso_local void @case_follow_label
// LLVM: switch i32 {{.*}}, label %[[SWDEFAULT:.*]] [
// LLVM: i32 1, label %[[LABEL:.*]]
// LLVM: i32 1, label %[[CASE1:.*]]
// LLVM: i32 2, label %[[CASE2:.*]]
// LLVM: ]
// LLVM: [[CASE1]]:
// LLVM: br label %[[LABEL:.*]]
// LLVM: [[LABEL]]:
// LLVM: br label %[[CASE2]]
// LLVM: [[CASE2]]:
Expand Down Expand Up @@ -303,3 +307,24 @@ extern "C" void default_follow_label(int v) {
// OGCG: br label %label
// OGCG: sw.epilog:
// OGCG: ret void

void g3() {
label:
goto label;
}

// CIR: cir.func dso_local @_Z2g3v
// CIR: cir.br ^bb1
// CIR: ^bb1:
// CIR: cir.label "label"
// CIR: cir.goto "label"

// LLVM: define dso_local void @_Z2g3v()
// LLVM: br label %1
// LLVM: 1:
// LLVM: br label %1

// OGCG: define dso_local void @_Z2g3v()
// OGCG: br label %label
// OGCG: label:
// OGCG: br label %label
32 changes: 26 additions & 6 deletions clang/test/CIR/CodeGen/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ void label() {
}

// CIR: cir.func no_proto dso_local @label
// CIR: cir.br ^bb1
// CIR: ^bb1:
// CIR: cir.label "labelA"
// CIR: cir.return

// LLVM:define dso_local void @label
// LLVM: br label %1
// LLVM: 1:
// LLVM: ret void

// OGCG: define dso_local void @label
Expand All @@ -29,15 +33,19 @@ void multiple_labels() {
}

// CIR: cir.func no_proto dso_local @multiple_labels
// CIR: cir.label "labelB"
// CIR: cir.br ^bb1
// CIR: ^bb1: // pred: ^bb0
// CIR: ^bb1:
// CIR: cir.label "labelB"
// CIR: cir.br ^bb2
// CIR: ^bb2:
// CIR: cir.label "labelC"
// CIR: cir.return

// LLVM: define dso_local void @multiple_labels()
// LLVM: br label %1
// LLVM: 1:
// LLVM: br label %2
// LLVM: 2:
// LLVM: ret void

// OGCG: define dso_local void @multiple_labels
Expand All @@ -56,6 +64,8 @@ void label_in_if(int cond) {

// CIR: cir.func dso_local @label_in_if
// CIR: cir.if {{.*}} {
// CIR: cir.br ^bb1
// CIR: ^bb1:
// CIR: cir.label "labelD"
// CIR: [[LOAD:%.*]] = cir.load align(4) [[COND:%.*]] : !cir.ptr<!s32i>, !s32i
// CIR: [[INC:%.*]] = cir.unary(inc, %3) nsw : !s32i, !s32i
Expand All @@ -68,15 +78,17 @@ void label_in_if(int cond) {
// LLVM: 3:
// LLVM: [[LOAD:%.*]] = load i32, ptr [[COND:%.*]], align 4
// LLVM: [[CMP:%.*]] = icmp ne i32 [[LOAD]], 0
// LLVM: br i1 [[CMP]], label %6, label %9
// LLVM: br i1 [[CMP]], label %6, label %10
// LLVM: 6:
// LLVM: br label %7
// LLVM: 7:
// LLVM: [[LOAD2:%.*]] = load i32, ptr [[COND]], align 4
// LLVM: [[ADD1:%.*]] = add nsw i32 [[LOAD2]], 1
// LLVM: store i32 [[ADD1]], ptr [[COND]], align 4
// LLVM: br label %9
// LLVM: 9:
// LLVM: br label %10
// LLVM: 10:
// LLVM: br label %11
// LLVM: 11:
// LLVM: ret void

// OGCG: define dso_local void @label_in_if
Expand Down Expand Up @@ -142,11 +154,15 @@ void labelWithoutMatch() {
return;
}
// CIR: cir.func no_proto dso_local @labelWithoutMatch
// CIR: cir.br ^bb1
// CIR: ^bb1:
// CIR: cir.label "end"
// CIR: cir.return
// CIR: }

// LLVM: define dso_local void @labelWithoutMatch
// LLVM: br label %1
// LLVM: 1:
// LLVM: ret void

// OGCG: define dso_local void @labelWithoutMatch
Expand All @@ -167,13 +183,17 @@ void foo() {

// CIR: cir.func no_proto dso_local @foo
// CIR: cir.scope {
// CIR: cir.label "label"
// CIR: %0 = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["agg.tmp0"]
// CIR: cir.br ^bb1
// CIR: ^bb1:
// CIR: cir.label "label"

// LLVM:define dso_local void @foo() {
// LLVM: [[ALLOC:%.*]] = alloca %struct.S, i64 1, align 1
// LLVM: br label %2
// LLVM:2:
// LLVM: br label %3
// LLVM:3:
// LLVM: [[CALL:%.*]] = call %struct.S @get()
// LLVM: store %struct.S [[CALL]], ptr [[ALLOC]], align 1
// LLVM: [[LOAD:%.*]] = load %struct.S, ptr [[ALLOC]], align 1
Expand Down