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
3848 if (const_wanted)3848 if (const_wanted)
3849 tcc_error("expected constant");3849 tcc_error("expected constant");
3850 /* save all registers */3850 /* save all registers */
3851 save_regs(0); 3851 if (!nocode_wanted)
3852 save_regs(0);
3852 /* statement expression : we do not accept break/continue3853 /* statement expression : we do not accept break/continue
3853 inside as GCC does */3854 inside as GCC does */
3854 block(NULL, NULL, NULL, NULL, 0, 1);3855 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
4878 a = gvtst(1, 0);4879 a = gvtst(1, 0);
4879 b = 0;4880 b = 0;
4880 block(&a, &b, case_sym, def_sym, case_reg, 0);4881 block(&a, &b, case_sym, def_sym, case_reg, 0);
4881 gjmp_addr(d);4882 if(!nocode_wanted)
4883 gjmp_addr(d);
4882 gsym(a);4884 gsym(a);
4883 gsym_addr(b, d);4885 gsym_addr(b, d);
4884 } else if (tok == '{') {4886 } else if (tok == '{') {
@@ -5070,7 +5072,8 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 185 unmodified lines
5070 }5072 }
5071 skip(')');5073 skip(')');
5072 block(&a, &b, case_sym, def_sym, case_reg, 0);5074 block(&a, &b, case_sym, def_sym, case_reg, 0);
5073 gjmp_addr(c);5075 if(!nocode_wanted)
5076 gjmp_addr(c);
5074 gsym(a);5077 gsym(a);
5075 gsym_addr(b, c);5078 gsym_addr(b, c);
5076 scope_stack_bottom = scope_stack_bottom->next;5079 scope_stack_bottom = scope_stack_bottom->next;
tests/tests2/82_nocode_wanted.c+80−0
@@ -0,0 +1,80 @@
1extern int printf(const char *format, ...);
2static 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}
16static 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}
30static 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}
47static 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}
71int 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 @@
1begin
2timeout=2
3timeout=1
4timeout=2
5timeout=1
6timeout=2
7timeout=1
8timeout=2
9timeout=1
10end

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