changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: cc: fix void cast crash

changeset 7370: 442402c215c0
parent 7367: b744681ba93c
child 7371: b73f589b3c7d
author: cinap_lenrek@felloff.net
date: Sat, 07 Sep 2019 02:11:18 +0200
files: sys/src/cmd/cc/com.c
description: cc: fix void cast crash

the following code reproduces the crash:

void
foo(void)
{
}

void
main(int argc, char **argv)
{
(void)(1 ? (void)0 : foo());
}

the problem is that side() gives a false positive on the OCOND
with later constant folding eleminating the acutal side effect
and OCAST ending up with two nested OCATS with the nested one
being zapped (type == T).
     1.1--- a/sys/src/cmd/cc/com.c
     1.2+++ b/sys/src/cmd/cc/com.c
     1.3@@ -1081,6 +1081,11 @@ loop:
     1.4 		if(castucom(n))
     1.5 			warn(n, "32-bit unsigned complement zero-extended to 64 bits");
     1.6 		ccom(l);
     1.7+		if(l->type == T){
     1.8+			n->left = Z;
     1.9+			n->type = T;
    1.10+			break;
    1.11+		}
    1.12 		if(l->op == OCONST) {
    1.13 			evconst(n);
    1.14 			if(n->op == OCONST)