From 824e918ca4f799c4105ef1b96d81894a137a1b29 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 13 Feb 2014 21:11:50 -0500 Subject: [PATCH] cmd/gc: fix liveness for addressed results Was spuriously marking results live on entry to function. TBR=iant CC=golang-codereviews https://golang.org/cl/63640043 --- src/cmd/gc/plive.c | 9 ++++++++- test/live.go | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cmd/gc/plive.c b/src/cmd/gc/plive.c index 4e3eadcd74..bd14610864 100644 --- a/src/cmd/gc/plive.c +++ b/src/cmd/gc/plive.c @@ -668,8 +668,15 @@ progeffects(Prog *prog, Array *vars, Bvec *uevar, Bvec *varkill, Bvec *avarinit) node = *(Node**)arrayget(vars, i); switch(node->class & ~PHEAP) { case PPARAM: - case PPARAMOUT: bvset(uevar, i); + case PPARAMOUT: + // If the result had its address taken, it is being tracked + // by the avarinit code, which does not use uevar. + // If we added it to uevar too, we'd not see any kill + // and decide that the varible was live entry, which it is not. + // So only use uevar in the non-addrtaken case. + if(!node->addrtaken) + bvset(uevar, i); break; } } diff --git a/test/live.go b/test/live.go index c0ea131294..c3dbc55c0a 100644 --- a/test/live.go +++ b/test/live.go @@ -86,3 +86,12 @@ func f6() (_, y string) { y = "hello" return } + +// confusion about addressed results used to cause "live at entry to f7: x". + +func f7() (x string) { + _ = &x + x = "hello" + return +} + -- 2.48.1