Commit 1dcf658f authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/gc: remove an incorrect assertion in escape analysis.

A fatal error used to happen when escassign-ing a multiple
function return to a single node. However, the situation
naturally appears when using "go f(g())" or "defer f(g())",
because g() is escassign-ed to sink.

Fixes #4529.

R=golang-dev, lvd, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/6920060
parent ff27cdb6
......@@ -639,6 +639,7 @@ static void
escassign(EscState *e, Node *dst, Node *src)
{
int lno;
NodeList *ll;
if(isblank(dst) || dst == N || src == N || src->op == ONONAME || src->op == OXXX)
return;
......@@ -715,9 +716,10 @@ escassign(EscState *e, Node *dst, Node *src)
case OCALLMETH:
case OCALLFUNC:
case OCALLINTER:
if(count(src->escretval) != 1)
fatal("escassign from call %+N", src);
escflows(e, dst, src->escretval->n);
// Flowing multiple returns to a single dst happens when
// analyzing "go f(g())": here g() flows to sink (issue 4529).
for(ll=src->escretval; ll; ll=ll->next)
escflows(e, dst, ll->n);
break;
case ODOT:
......
......@@ -660,6 +660,21 @@ func foo81() *int {
return nil
}
func tee(p *int) (x, y *int) { return p, p } // ERROR "leaking param"
func noop(x, y *int) {} // ERROR "does not escape"
func foo82() {
var x, y, z int // ERROR "moved to heap"
go noop(tee(&z)) // ERROR "&z escapes to heap"
go noop(&x, &y) // ERROR "escapes to heap"
for {
var u, v, w int // ERROR "moved to heap"
defer noop(tee(&u)) // ERROR "&u escapes to heap"
defer noop(&v, &w) // ERROR "escapes to heap"
}
}
type Fooer interface {
Foo()
}
......
// compile
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 4529: escape analysis crashes on "go f(g())"
// when g has multiple returns.
package main
type M interface{}
type A struct {
a string
b chan M
}
func (a *A) I() (b <-chan M, c chan<- M) {
a.b, c = make(chan M), make(chan M)
b = a.b
return
}
func Init(a string, b *A, c interface {
I() (<-chan M, chan<- M)
}) {
b.a = a
go b.c(c.I())
}
func (a *A) c(b <-chan M, _ chan<- M) {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment