mirror of
https://github.com/golang/go
synced 2024-11-11 22:40:22 -07:00
cmd/gc: fix inlining bug with local variables.
Fixes #4323. R=rsc, lvd, golang-dev CC=golang-dev https://golang.org/cl/6815061
This commit is contained in:
parent
c7873ff2a6
commit
76500b14a1
@ -556,6 +556,8 @@ mkinlcall1(Node **np, Node *fn)
|
|||||||
for(ll = dcl; ll; ll=ll->next)
|
for(ll = dcl; ll; ll=ll->next)
|
||||||
if(ll->n->op == ONAME) {
|
if(ll->n->op == ONAME) {
|
||||||
ll->n->inlvar = inlvar(ll->n);
|
ll->n->inlvar = inlvar(ll->n);
|
||||||
|
// Typecheck because inlvar is not necessarily a function parameter.
|
||||||
|
typecheck(&ll->n->inlvar, Erv);
|
||||||
ninit = list(ninit, nod(ODCL, ll->n->inlvar, N)); // otherwise gen won't emit the allocations for heapallocs
|
ninit = list(ninit, nod(ODCL, ll->n->inlvar, N)); // otherwise gen won't emit the allocations for heapallocs
|
||||||
if (ll->n->class == PPARAMOUT) // we rely on the order being correct here
|
if (ll->n->class == PPARAMOUT) // we rely on the order being correct here
|
||||||
inlretvars = list(inlretvars, ll->n->inlvar);
|
inlretvars = list(inlretvars, ll->n->inlvar);
|
||||||
|
31
test/fixedbugs/issue4323.go
Normal file
31
test/fixedbugs/issue4323.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// 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 4323: inlining of functions with local variables
|
||||||
|
// forgets to typecheck the declarations in the inlined copy.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
type reader struct {
|
||||||
|
C chan T
|
||||||
|
}
|
||||||
|
|
||||||
|
type T struct{ C chan []byte }
|
||||||
|
|
||||||
|
var r = newReader()
|
||||||
|
|
||||||
|
func newReader() *reader { return new(reader) }
|
||||||
|
|
||||||
|
func (r *reader) Read(n int) ([]byte, error) {
|
||||||
|
req := T{C: make(chan []byte)}
|
||||||
|
r.C <- req
|
||||||
|
return <-req.C, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
s, err := r.Read(1)
|
||||||
|
_, _ = s, err
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user