History

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.

Michael Matz committed 10 years ago

Commit 16029981 parent f2a071e3 files · +46 −4Browse files

Unified · Split

3 files
  1. tccgen.c +10 −4
  2. tests/tests2/82_nocode_wanted.c +32 −0
  3. tests/tests2/82_nocode_wanted.expect +4 −0
tccgen.c+10−4
@@ -5605,8 +5605,9 @@ static void block(int *bsym, int *csym, int is_expr) · 5604 unmodified lines
56055605 skip('(');
56065606 gsym(b);
56075607 gexpr();
5608− c = gvtst(0, 0);
5609− gsym_addr(c, d);
5608+ c = gvtst(0, 0);
5609+ if (!nocode_wanted)
5610+ gsym_addr(c, d);
56105611 skip(')');
56115612 gsym(a);
56125613 skip(';');
@@ -5678,7 +5679,10 @@ static void block(int *bsym, int *csym, int is_expr) · 65 unmodified lines
56785679 gexpr();
56795680 if ((vtop->type.t & VT_BTYPE) != VT_PTR)
56805681 expect("pointer");
5681− ggoto();
5682+ if (!nocode_wanted)
5683+ ggoto();
5684+ else
5685+ vtop--;
56825686 } else if (tok >= TOK_UIDENT) {
56835687 s = label_find(tok);
56845688 /* put forward definition if needed */
@@ -5689,7 +5693,9 @@ static void block(int *bsym, int *csym, int is_expr) · 4 unmodified lines
56895693 s->r = LABEL_FORWARD;
56905694 }
56915695 vla_sp_restore_root();
5692− if (s->r & LABEL_FORWARD)
5696+ if (nocode_wanted)
5697+ ;
5698+ else if (s->r & LABEL_FORWARD)
56935699 s->jnext = gjmp(s->jnext);
56945700 else
56955701 gjmp_addr(s->jnext);
tests/tests2/82_nocode_wanted.c+32−0
@@ -27,6 +27,36 @@ static void kb_wait_2(void) · 26 unmodified lines
2727 timeout--;
2828 } while (timeout);
2929 }
30+static void kb_wait_2_1(void)
31+{
32+ unsigned long timeout = 2;
33+ do {
34+ (1 ?
35+ printf("timeout=%ld\n", timeout) :
36+ ({
37+ do {
38+ printf("error\n");
39+ } while (1);
40+ })
41+ );
42+ timeout--;
43+ } while (timeout);
44+}
45+static void kb_wait_2_2(void)
46+{
47+ unsigned long timeout = 2;
48+ do {
49+ (1 ?
50+ printf("timeout=%ld\n", timeout) :
51+ ({
52+ label:
53+ printf("error\n");
54+ goto label;
55+ })
56+ );
57+ timeout--;
58+ } while (timeout);
59+}
3060 static void kb_wait_3(void)
3161 {
3262 unsigned long timeout = 2;
@@ -73,6 +103,8 @@ int main() · 40 unmodified lines
73103 printf("begin\n");
74104 kb_wait_1();
75105 kb_wait_2();
106+ kb_wait_2_1();
107+ kb_wait_2_2();
76108 kb_wait_3();
77109 kb_wait_4();
78110 printf("end\n");
tests/tests2/82_nocode_wanted.expect+4−0
@@ -7,4 +7,8 @@ timeout=2 · 6 unmodified lines
77 timeout=1
88 timeout=2
99 timeout=1
10+timeout=2
11+timeout=1
12+timeout=2
13+timeout=1
1014 end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t