From 52dc943702a8f7815546e76286b153c3813e1db0 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sun, 15 Mar 2020 15:08:04 -0700 Subject: fix ccom idempotency ccom may be called multiple times on the same node, via 'goto loop' calls from the commute label, OADD, and a few other places. Casts to void could null out the LHS of the node, which would cause the compiler to crash if the cast was revisited due to one of these cases, because we tried frobbing n->left. Now, if n->left is nil, we just return.w --- sys/src/cmd/cc/com.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/src/cmd/cc/com.c b/sys/src/cmd/cc/com.c index 49fcefd1a..6dfc7d421 100644 --- a/sys/src/cmd/cc/com.c +++ b/sys/src/cmd/cc/com.c @@ -1018,6 +1018,8 @@ if(debug['y']) prtree(n, "final"); * remove some zero operands * remove no op casts * evaluate constants + * Note: ccom may be called on the same node + * multiple times. */ void ccom(Node *n) @@ -1078,8 +1080,9 @@ loop: if(n->type == types[TVOID] && !side(l)){ n->left = Z; n->type = T; - break; } + if(n->left == Z) + break; if(castucom(n)) warn(n, "32-bit unsigned complement zero-extended to 64 bits"); ccom(l); -- cgit v1.2.3