Skip to content

Crash with label with break in a switch case #876

@ChuanqiXu9

Description

@ChuanqiXu9

Reproducer:

void action1();
void action2();
void double_label(int v) {
  switch (v) {
    default:
        action1();
      label:
        action2();
        break;
  }
}

Diagnostic message:

loc("/disk2/workspace.xuchuanqi/clangir/clang/test/CIR/CodeGen/tmp.c":10:7): error: operation with block successors must terminate its parent block
fatal error: error in backend: CIR codegen: module verification error before running CIR passes

It looks like the it generates the break instruction in the wrong place:

      "cir.switch"(%1) <{cases = [#cir.case<value = [], kind = 1 : i32>]}> ({
        %2 = "cir.get_global"() <{name = @action1}> : () -> !cir.ptr<!cir.func<!void (...)>> loc(#loc24)
        %3 = "cir.cast"(%2) <{kind = 4 : i32}> : (!cir.ptr<!cir.func<!void (...)>>) -> !cir.ptr<!cir.func<!void ()>> loc(#loc24)
        "cir.call"(%3) <{ast = #cir.call.expr.ast, calling_conv = 1 : i32, extra_attrs = #fn_attr}> ({
        }) : (!cir.ptr<!cir.func<!void ()>>) -> () loc(#loc13)
        "cir.br"()[^bb1] : () -> () loc(#loc15) ; problematic
        "cir.break"() : () -> () loc(#loc16)
      ^bb1:  // pred: ^bb0
        "cir.label"() <{label = "label"}> : () -> () loc(#loc15)
        %4 = "cir.get_global"() <{name = @action2}> : () -> !cir.ptr<!cir.func<!void (...)>> loc(#loc25)
        %5 = "cir.cast"(%4) <{kind = 4 : i32}> : (!cir.ptr<!cir.func<!void (...)>>) -> !cir.ptr<!cir.func<!void ()>> loc(#loc25)
        "cir.call"(%5) <{ast = #cir.call.expr.ast, calling_conv = 1 : i32, extra_attrs = #fn_attr}> ({
        }) : (!cir.ptr<!cir.func<!void ()>>) -> () loc(#loc17)
        "cir.yield"() : () -> () loc(#loc10)
      }) : (!s32i) -> () loc(#loc10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions