forked from Mirrors/tinycc
Fix more nocode_wanted jump problems
In statement expression we really mustn't emit backward jumps under nocode_wanted (they will form infinte loops as no expressions are evaluated). Do-while and explicit loop with gotos weren't handled.master
parent
f2a071e808
commit
1602998751
14
tccgen.c
14
tccgen.c
|
@ -5605,8 +5605,9 @@ static void block(int *bsym, int *csym, int is_expr)
|
||||||
skip('(');
|
skip('(');
|
||||||
gsym(b);
|
gsym(b);
|
||||||
gexpr();
|
gexpr();
|
||||||
c = gvtst(0, 0);
|
c = gvtst(0, 0);
|
||||||
gsym_addr(c, d);
|
if (!nocode_wanted)
|
||||||
|
gsym_addr(c, d);
|
||||||
skip(')');
|
skip(')');
|
||||||
gsym(a);
|
gsym(a);
|
||||||
skip(';');
|
skip(';');
|
||||||
|
@ -5678,7 +5679,10 @@ static void block(int *bsym, int *csym, int is_expr)
|
||||||
gexpr();
|
gexpr();
|
||||||
if ((vtop->type.t & VT_BTYPE) != VT_PTR)
|
if ((vtop->type.t & VT_BTYPE) != VT_PTR)
|
||||||
expect("pointer");
|
expect("pointer");
|
||||||
ggoto();
|
if (!nocode_wanted)
|
||||||
|
ggoto();
|
||||||
|
else
|
||||||
|
vtop--;
|
||||||
} else if (tok >= TOK_UIDENT) {
|
} else if (tok >= TOK_UIDENT) {
|
||||||
s = label_find(tok);
|
s = label_find(tok);
|
||||||
/* put forward definition if needed */
|
/* put forward definition if needed */
|
||||||
|
@ -5689,7 +5693,9 @@ static void block(int *bsym, int *csym, int is_expr)
|
||||||
s->r = LABEL_FORWARD;
|
s->r = LABEL_FORWARD;
|
||||||
}
|
}
|
||||||
vla_sp_restore_root();
|
vla_sp_restore_root();
|
||||||
if (s->r & LABEL_FORWARD)
|
if (nocode_wanted)
|
||||||
|
;
|
||||||
|
else if (s->r & LABEL_FORWARD)
|
||||||
s->jnext = gjmp(s->jnext);
|
s->jnext = gjmp(s->jnext);
|
||||||
else
|
else
|
||||||
gjmp_addr(s->jnext);
|
gjmp_addr(s->jnext);
|
||||||
|
|
|
@ -27,6 +27,36 @@ static void kb_wait_2(void)
|
||||||
timeout--;
|
timeout--;
|
||||||
} while (timeout);
|
} while (timeout);
|
||||||
}
|
}
|
||||||
|
static void kb_wait_2_1(void)
|
||||||
|
{
|
||||||
|
unsigned long timeout = 2;
|
||||||
|
do {
|
||||||
|
(1 ?
|
||||||
|
printf("timeout=%ld\n", timeout) :
|
||||||
|
({
|
||||||
|
do {
|
||||||
|
printf("error\n");
|
||||||
|
} while (1);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
timeout--;
|
||||||
|
} while (timeout);
|
||||||
|
}
|
||||||
|
static void kb_wait_2_2(void)
|
||||||
|
{
|
||||||
|
unsigned long timeout = 2;
|
||||||
|
do {
|
||||||
|
(1 ?
|
||||||
|
printf("timeout=%ld\n", timeout) :
|
||||||
|
({
|
||||||
|
label:
|
||||||
|
printf("error\n");
|
||||||
|
goto label;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
timeout--;
|
||||||
|
} while (timeout);
|
||||||
|
}
|
||||||
static void kb_wait_3(void)
|
static void kb_wait_3(void)
|
||||||
{
|
{
|
||||||
unsigned long timeout = 2;
|
unsigned long timeout = 2;
|
||||||
|
@ -73,6 +103,8 @@ int main()
|
||||||
printf("begin\n");
|
printf("begin\n");
|
||||||
kb_wait_1();
|
kb_wait_1();
|
||||||
kb_wait_2();
|
kb_wait_2();
|
||||||
|
kb_wait_2_1();
|
||||||
|
kb_wait_2_2();
|
||||||
kb_wait_3();
|
kb_wait_3();
|
||||||
kb_wait_4();
|
kb_wait_4();
|
||||||
printf("end\n");
|
printf("end\n");
|
||||||
|
|
|
@ -7,4 +7,8 @@ timeout=2
|
||||||
timeout=1
|
timeout=1
|
||||||
timeout=2
|
timeout=2
|
||||||
timeout=1
|
timeout=1
|
||||||
|
timeout=2
|
||||||
|
timeout=1
|
||||||
|
timeout=2
|
||||||
|
timeout=1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue