History

tccgen.c: Recognise constant expressions with conditional operator.

tests/tests2/78_vla_label.c: Check that int a[1 ? 1 : 1] is not a VLA.

Edmund Grimley Evans committed 10 years ago

Commit 992cbda1 parent 30c54c92 files · +21 −10Browse files

Unified · Split

2 files
  1. tccgen.c +7 −7
  2. tests/tests2/78_vla_label.c +14 −3
tccgen.c+7−7
@@ -4522,9 +4522,13 @@ static void expr_cond(void) · 4521 unmodified lines
45224522 SValue sv;
45234523 CType type, type1, type2;
45244524
4525− if (const_wanted) {
4525+ if (const_wanted)
45264526 expr_lor_const();
4527− if (tok == '?') {
4527+ else
4528+ expr_lor();
4529+ if (tok == '?') {
4530+ next();
4531+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
45284532 CType boolean;
45294533 int c;
45304534 boolean.t = VT_BOOL;
@@ -4532,7 +4536,6 @@ static void expr_cond(void) · 1 unmodified line
45324536 gen_cast(&boolean);
45334537 c = vtop->c.i;
45344538 vpop();
4535− next();
45364539 if (tok != ':' || !gnu_ext) {
45374540 vpop();
45384541 gexpr();
@@ -4544,10 +4547,7 @@ static void expr_cond(void) · 5 unmodified lines
45444547 if (c)
45454548 vpop();
45464549 }
4547− } else {
4548− expr_lor();
4549− if (tok == '?') {
4550− next();
4550+ else {
45514551 if (vtop != vstack) {
45524552 /* needed to avoid having different registers saved in
45534553 each branch */
tests/tests2/78_vla_label.c+14−3
@@ -1,8 +1,7 @@
11 #include <stdio.h>
22
33 /* This test segfaults as of April 27, 2015. */
4−
5−void f(int argc)
4+void f1(int argc)
65 {
76 char test[argc];
87 if(0)
@@ -13,9 +12,21 @@ void f(int argc) · 4 unmodified lines
1312 goto label;
1413 }
1514
15+/* This segfaulted on 2015-11-19. */
16+void f2(void)
17+{
18+ goto start;
19+ {
20+ int a[1 ? 1 : 1]; /* not a variable-length array */
21+ start:
22+ a[0] = 0;
23+ }
24+}
25+
1626 int main()
1727 {
18− f(2);
28+ f1(2);
29+ f2();
1930
2031 return 0;
2132 }

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