mirror of
https://github.com/danog/ir.git
synced 2024-11-26 12:24:56 +01:00
Fixed GH Issue #41 (ir_emit_c() dumping misses BB label)
This commit is contained in:
parent
20b9a7513c
commit
4d2ef9401f
@ -768,7 +768,10 @@ static int ir_emit_func(ir_ctx *ctx, FILE *f)
|
||||
if ((bb->flags & (IR_BB_START|IR_BB_ENTRY|IR_BB_EMPTY)) == IR_BB_EMPTY) {
|
||||
continue;
|
||||
}
|
||||
if (bb->predecessors_count > 1 || (bb->predecessors_count == 1 && ctx->cfg_edges[bb->predecessors] != prev)) {
|
||||
if (bb->predecessors_count > 1
|
||||
|| (bb->predecessors_count == 1 && ctx->cfg_edges[bb->predecessors] != prev)
|
||||
|| ctx->ir_base[bb->start].op == IR_CASE_VAL
|
||||
|| ctx->ir_base[bb->start].op == IR_CASE_DEFAULT) {
|
||||
fprintf(f, "bb%d:\n", b);
|
||||
}
|
||||
prev = b;
|
||||
|
57
tests/c/switch_001.irt
Normal file
57
tests/c/switch_001.irt
Normal file
@ -0,0 +1,57 @@
|
||||
--TEST--
|
||||
SWITCH 001
|
||||
--ARGS--
|
||||
--emit-c
|
||||
--CODE--
|
||||
{
|
||||
uintptr_t c_1 = 0;
|
||||
bool c_2 = 0;
|
||||
bool c_3 = 1;
|
||||
int32_t c_4 = 1;
|
||||
int32_t c_5 = 2;
|
||||
int32_t c_6 = 3;
|
||||
int32_t c_7 = 4;
|
||||
l_1 = START(l_16);
|
||||
int32_t d_2 = PARAM(l_1, "z", 0);
|
||||
l_4 = SWITCH(l_1, d_2);
|
||||
l_5 = CASE_VAL(l_4, c_4);
|
||||
int32_t x_1 = COPY(c_4);
|
||||
l_6 = END(l_5);
|
||||
l_7 = CASE_VAL(l_4, c_5);
|
||||
int32_t x_2 = COPY(c_5);
|
||||
l_8 = END(l_7);
|
||||
l_9 = CASE_VAL(l_4, c_6);
|
||||
int32_t x_3 = COPY(c_6);
|
||||
l_10 = END(l_9);
|
||||
l_11 = CASE_DEFAULT(l_4);
|
||||
int32_t x_4 = COPY(c_7);
|
||||
l_12 = END(l_11);
|
||||
l_13 = MERGE/4(l_6, l_8, l_10, l_12);
|
||||
int32_t ret = PHI/4(l_13, x_1, x_2, x_3, x_4);
|
||||
l_16 = RETURN(l_13, ret);
|
||||
}
|
||||
--EXPECT--
|
||||
int32_t test(int32_t z)
|
||||
{
|
||||
int32_t d_1 = z;
|
||||
int32_t d_2;
|
||||
switch (d_1) {
|
||||
case 1: goto bb2;
|
||||
case 2: goto bb4;
|
||||
case 3: goto bb5;
|
||||
default: goto bb6;
|
||||
}
|
||||
bb2:
|
||||
d_2 = 1;
|
||||
bb3:
|
||||
return d_2;
|
||||
bb4:
|
||||
d_2 = 2;
|
||||
goto bb3;
|
||||
bb5:
|
||||
d_2 = 3;
|
||||
goto bb3;
|
||||
bb6:
|
||||
d_2 = 4;
|
||||
goto bb3;
|
||||
}
|
Loading…
Reference in New Issue
Block a user