History

nocode_wanted with while/for inside ({})

a test included.

seyko committed 10 years ago

Commit c9473a71 parent 5a704453 files · +96 −3Browse files

Unified · Split

3 files
  1. tccgen.c +6 −3
  2. tests/tests2/82_nocode_wanted.c +80 −0
  3. tests/tests2/82_nocode_wanted.expect +10 −0
tccgen.c+6−3
@@ -3848,7 +3848,8 @@ ST_FUNC void unary(void) · 3847 unmodified lines
38483848 if (const_wanted)
38493849 tcc_error("expected constant");
38503850 /* save all registers */
3851− save_regs(0);
3851+ if (!nocode_wanted)
3852+ save_regs(0);
38523853 /* statement expression : we do not accept break/continue
38533854 inside as GCC does */
38543855 block(NULL, NULL, NULL, NULL, 0, 1);
@@ -4878,7 +4879,8 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 1023 unmodified lines
48784879 a = gvtst(1, 0);
48794880 b = 0;
48804881 block(&a, &b, case_sym, def_sym, case_reg, 0);
4881− gjmp_addr(d);
4882+ if(!nocode_wanted)
4883+ gjmp_addr(d);
48824884 gsym(a);
48834885 gsym_addr(b, d);
48844886 } else if (tok == '{') {
@@ -5070,7 +5072,8 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 185 unmodified lines
50705072 }
50715073 skip(')');
50725074 block(&a, &b, case_sym, def_sym, case_reg, 0);
5073− gjmp_addr(c);
5075+ if(!nocode_wanted)
5076+ gjmp_addr(c);
50745077 gsym(a);
50755078 gsym_addr(b, c);
50765079 scope_stack_bottom = scope_stack_bottom->next;
tests/tests2/82_nocode_wanted.c+80−0
@@ -0,0 +1,80 @@
1+extern int printf(const char *format, ...);
2+static void kb_wait_1(void)
3+{
4+ unsigned long timeout = 2;
5+ do {
6+ (1 ?
7+ printf("timeout=%ld\n", timeout) :
8+ ({
9+ while (1)
10+ printf("error\n");
11+ })
12+ );
13+ timeout--;
14+ } while (timeout);
15+}
16+static void kb_wait_2(void)
17+{
18+ unsigned long timeout = 2;
19+ do {
20+ (1 ?
21+ printf("timeout=%ld\n", timeout) :
22+ ({
23+ for (;;)
24+ printf("error\n");
25+ })
26+ );
27+ timeout--;
28+ } while (timeout);
29+}
30+static void kb_wait_3(void)
31+{
32+ unsigned long timeout = 2;
33+ do {
34+ (1 ?
35+ printf("timeout=%ld\n", timeout) :
36+ ({
37+ int i = 1;
38+ goto label;
39+ i = i + 2;
40+ label:
41+ i = i + 3;
42+ })
43+ );
44+ timeout--;
45+ } while (timeout);
46+}
47+static void kb_wait_4(void)
48+{
49+ unsigned long timeout = 2;
50+ do {
51+ (1 ?
52+ printf("timeout=%ld\n", timeout) :
53+ ({
54+ switch(timeout) {
55+ case 2:
56+ printf("timeout is 2");
57+ break;
58+ case 1:
59+ printf("timeout is 1");
60+ break;
61+ default:
62+ printf("timeout is 0?");
63+ break;
64+ };
65+ // return;
66+ })
67+ );
68+ timeout--;
69+ } while (timeout);
70+}
71+int main()
72+{
73+ printf("begin\n");
74+ kb_wait_1();
75+ kb_wait_2();
76+ kb_wait_3();
77+ kb_wait_4();
78+ printf("end\n");
79+ return 0;
80+}
tests/tests2/82_nocode_wanted.expect+10−0
@@ -0,0 +1,10 @@
1+begin
2+timeout=2
3+timeout=1
4+timeout=2
5+timeout=1
6+timeout=2
7+timeout=1
8+timeout=2
9+timeout=1
10+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