diff options
| author | Edmund Grimley Evans <Edmund.Grimley.Evans@gmail.com> | 2015-11-20 00:24:46 +0000 |
|---|---|---|
| committer | Edmund Grimley Evans <Edmund.Grimley.Evans@gmail.com> | 2015-11-20 00:24:46 +0000 |
| commit | 992cbda8d0958572831ea18c58c32ed11daf812d (patch) | |
| tree | 790cb8891837724ec602dfddf5aa6ce24361f3a2 | |
| parent | 30c54c9d433f5cc213912afd2ed04808cd9a4a23 (diff) | |
| download | tinycc-992cbda8d0958572831ea18c58c32ed11daf812d.tar.gz tinycc-992cbda8d0958572831ea18c58c32ed11daf812d.tar.bz2 | |
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.
| -rw-r--r-- | tccgen.c | 14 | ||||
| -rw-r--r-- | tests/tests2/78_vla_label.c | 17 |
2 files changed, 21 insertions, 10 deletions
@@ -4522,9 +4522,13 @@ static void expr_cond(void) SValue sv; CType type, type1, type2; - if (const_wanted) { + if (const_wanted) expr_lor_const(); - if (tok == '?') { + else + expr_lor(); + if (tok == '?') { + next(); + if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { CType boolean; int c; boolean.t = VT_BOOL; @@ -4532,7 +4536,6 @@ static void expr_cond(void) gen_cast(&boolean); c = vtop->c.i; vpop(); - next(); if (tok != ':' || !gnu_ext) { vpop(); gexpr(); @@ -4544,10 +4547,7 @@ static void expr_cond(void) if (c) vpop(); } - } else { - expr_lor(); - if (tok == '?') { - next(); + else { if (vtop != vstack) { /* needed to avoid having different registers saved in each branch */ diff --git a/tests/tests2/78_vla_label.c b/tests/tests2/78_vla_label.c index 0908e1b..93a8b08 100644 --- a/tests/tests2/78_vla_label.c +++ b/tests/tests2/78_vla_label.c @@ -1,8 +1,7 @@ #include <stdio.h> /* This test segfaults as of April 27, 2015. */ - -void f(int argc) +void f1(int argc) { char test[argc]; if(0) @@ -13,9 +12,21 @@ void f(int argc) goto label; } +/* This segfaulted on 2015-11-19. */ +void f2(void) +{ + goto start; + { + int a[1 ? 1 : 1]; /* not a variable-length array */ + start: + a[0] = 0; + } +} + int main() { - f(2); + f1(2); + f2(); return 0; } |
