Commit 76500b14 authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/gc: fix inlining bug with local variables.

Fixes #4323.

R=rsc, lvd, golang-dev
CC=golang-dev
https://golang.org/cl/6815061
parent c7873ff2
......@@ -556,6 +556,8 @@ mkinlcall1(Node **np, Node *fn)
for(ll = dcl; ll; ll=ll->next)
if(ll->n->op == ONAME) {
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
if (ll->n->class == PPARAMOUT) // we rely on the order being correct here
inlretvars = list(inlretvars, ll->n->inlvar);
......
// 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
}
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