From: Dmitry Vyukov Date: Tue, 14 Apr 2015 09:46:15 +0000 (+0300) Subject: cmd/gc: fix crash during escape analysis X-Git-Tag: go1.5beta1~1123 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=24f246c1b6fba4f8faf29b2d0cf3583f9bb04135;p=gostls13.git cmd/gc: fix crash during escape analysis Fixes #10441 Compiler crashed as: panic: runtime error: invalid memory address or nil pointer dereference goroutine 1 [running]: cmd/internal/gc.haspointers(0x0, 0xffffffffffffffff) src/cmd/internal/gc/reflect.go:623 +0x1f cmd/internal/gc.escwalk(0x20c82dc00, 0xffffffffffffffff, 0x20c82dda0, 0x20c835520) src/cmd/internal/gc/esc.go:1291 +0x14aa cmd/internal/gc.escwalk(0x20c82dc00, 0xffffffffffffffff, 0x20c82dda0, 0x20beac340) src/cmd/internal/gc/esc.go:1386 +0x836 while evaluating haspointers of the fake OADDR node here: leaks = level <= 0 && dst.Escloopdepth < src.Escloopdepth || level < 0 && dst == &e.funcParam && haspointers(src.Type) Change-Id: I13c23fced52e8fcd0ae1df81b374df8632eb7790 Reviewed-on: https://go-review.googlesource.com/8932 Reviewed-by: David Chase Run-TryBot: Dmitry Vyukov TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/internal/gc/esc.go b/src/cmd/internal/gc/esc.go index 6f894c9165..0ca407a734 100644 --- a/src/cmd/internal/gc/esc.go +++ b/src/cmd/internal/gc/esc.go @@ -885,6 +885,7 @@ func escassign(e *EscState, dst *Node, src *Node) { a := Nod(OADDR, src, nil) a.Lineno = src.Lineno a.Escloopdepth = src.Escloopdepth + a.Type = Ptrto(src.Type) escflows(e, dst, a) // Flowing multiple returns to a single dst happens when diff --git a/test/fixedbugs/issue10441.go b/test/fixedbugs/issue10441.go new file mode 100644 index 0000000000..25832fac45 --- /dev/null +++ b/test/fixedbugs/issue10441.go @@ -0,0 +1,17 @@ +// build + +// Copyright 2015 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. + +package p + +func bar() { + f := func() {} + foo(&f) +} + +func foo(f *func()) func() { + defer func() {}() // prevent inlining of foo + return *f +}