aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tccgen.c34
-rw-r--r--tests/tests2/78_vla_label.c9
-rw-r--r--tests/tests2/78_vla_label.expect4
3 files changed, 39 insertions, 8 deletions
diff --git a/tccgen.c b/tccgen.c
index 3b5ad75..4e6a116 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -4468,8 +4468,11 @@ static void expr_land(void)
expr_land();
gen_cast(&ctb);
} else {
+ int saved_nocode_wanted = nocode_wanted;
+ nocode_wanted = 1;
expr_land();
vpop();
+ nocode_wanted = saved_nocode_wanted;
}
gen_cast(&cti);
} else {
@@ -4499,8 +4502,11 @@ static void expr_lor(void)
next();
gen_cast(&ctb);
if (vtop->c.i) {
+ int saved_nocode_wanted = nocode_wanted;
+ nocode_wanted = 1;
expr_lor();
vpop();
+ nocode_wanted = saved_nocode_wanted;
} else {
vpop();
expr_lor();
@@ -4533,6 +4539,7 @@ static void expr_cond(void)
if (tok == '?') {
next();
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ int saved_nocode_wanted = nocode_wanted;
CType boolean;
int c;
boolean.t = VT_BOOL;
@@ -4540,16 +4547,27 @@ static void expr_cond(void)
gen_cast(&boolean);
c = vtop->c.i;
vpop();
- if (tok != ':' || !gnu_ext) {
- vpop();
- gexpr();
- }
- if (!c)
+ if (c) {
+ if (tok != ':' || !gnu_ext) {
+ vpop();
+ gexpr();
+ }
+ skip(':');
+ nocode_wanted = 1;
+ expr_cond();
vpop();
- skip(':');
- expr_cond();
- if (c)
+ nocode_wanted = saved_nocode_wanted;
+ } else {
vpop();
+ if (tok != ':' || !gnu_ext) {
+ nocode_wanted = 1;
+ gexpr();
+ vpop();
+ nocode_wanted = saved_nocode_wanted;
+ }
+ skip(':');
+ expr_cond();
+ }
}
else {
if (vtop != vstack) {
diff --git a/tests/tests2/78_vla_label.c b/tests/tests2/78_vla_label.c
index 39654c6..4096495 100644
--- a/tests/tests2/78_vla_label.c
+++ b/tests/tests2/78_vla_label.c
@@ -27,10 +27,19 @@ void f2(void)
}
}
+void f3(void)
+{
+ printf("%d\n", 0 ? printf("x1\n") : 11);
+ printf("%d\n", 1 ? 12 : printf("x2\n"));
+ printf("%d\n", 0 && printf("x3\n"));
+ printf("%d\n", 1 || printf("x4\n"));
+}
+
int main()
{
f1(2);
f2();
+ f3();
return 0;
}
diff --git a/tests/tests2/78_vla_label.expect b/tests/tests2/78_vla_label.expect
index 9a8c159..3f4063b 100644
--- a/tests/tests2/78_vla_label.expect
+++ b/tests/tests2/78_vla_label.expect
@@ -1,2 +1,6 @@
boom!
boom!
+11
+12
+0
+1