commit 190263f1b628ba3171309147120fd3ba0e370b42
parent 7bf08ff50729037c8820b26d085905175b5593c8
Author: Michael Forney <mforney@mforney.org>
Date: Wed, 20 Nov 2019 00:20:21 -0800
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.
Diffstat:
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git 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) {