summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-11-20 00:20:21 -0800
committerQuentin Carbonneaux <quentin@c9x.me>2019-11-25 20:40:33 +0100
commit190263f1b628ba3171309147120fd3ba0e370b42 (patch)
treef28db431972eb328fe56fa0b8df07cf9f263c672
parent7bf08ff50729037c8820b26d085905175b5593c8 (diff)
downloadroux-190263f1b628ba3171309147120fd3ba0e370b42.tar.gz
copy: Fix use of compound literal outside its scope
C99 6.5.2.5p6:
> If the compound literal occurs outside the body of a function,
> the object has static storage duration; otherwise, it has automatic
> storage duration associated with the enclosing block.

So, we can't use the address of a compound literal here. Instead,
just set p to NULL, and make the loop conditional on p being non-NULL.

Remarks from Quentin:

I made a cosmetic change to Michael's
original patch and merely pushed the
literal at toplevel.
-rw-r--r--copy.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/copy.c b/copy.c
index 3aa3b98..053f319 100644
--- a/copy.c
+++ b/copy.c
@@ -68,16 +68,18 @@ phisimpl(Phi *p, Ref r, Ref *cpy, Use ***pstk, BSet *ts, BSet *as, Fn *fn)
 	uint nstk, a;
 	int t;
 	Ref r1;
+	Phi *p0;
 
 	bszero(ts);
 	bszero(as);
+	p0 = &(Phi){.narg = 0};
 	stk = *pstk;
 	nstk = 1;
 	stk[0] = &(Use){.type = UPhi, .u.phi = p};
 	while (nstk) {
 		u = stk[--nstk];
 		if (u->type == UIns && iscopy(u->u.ins, r, fn)) {
-			p = &(Phi){.narg = 0};
+			p = p0;
 			t = u->u.ins->to.val;
 		}
 		else if (u->type == UPhi) {