]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix inlining bug with local variables.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 1 Nov 2012 17:59:32 +0000 (18:59 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 1 Nov 2012 17:59:32 +0000 (18:59 +0100)
Fixes #4323.

R=rsc, lvd, golang-dev
CC=golang-dev
https://golang.org/cl/6815061

src/cmd/gc/inl.c
test/fixedbugs/issue4323.go [new file with mode: 0644]

index 40a42af37a0f1650f0f59b7e4e04015b3cd07c0e..54f4a0b59709bf6a2871bdc49555e323da2e4eb1 100644 (file)
@@ -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);
diff --git a/test/fixedbugs/issue4323.go b/test/fixedbugs/issue4323.go
new file mode 100644 (file)
index 0000000..6bb78f4
--- /dev/null
@@ -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
+}