FAQ
Reviewers: rsc, lvd, golang-dev_googlegroups.com,

Message:
Hello rsc@golang.org, lvd@google.com, golang-dev@googlegroups.com (cc:
golang-dev@googlegroups.com),

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
cmd/gc: fix inlining bug with local variables.

Fixes issue 4323.

Please review this at http://codereview.appspot.com/6815061/

Affected files:
M src/cmd/gc/inl.c
A test/fixedbugs/issue4323.go


Index: src/cmd/gc/inl.c
===================================================================
--- a/src/cmd/gc/inl.c
+++ b/src/cmd/gc/inl.c
@@ -556,6 +556,8 @@
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);
Index: test/fixedbugs/issue4323.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/fixedbugs/issue4323.go
@@ -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
+}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 31, '12 at 8:54p
activeNov 1, '12 at 5:59p
posts3
users2
websitegolang.org

2 users in discussion

Remyoudompheng: 2 posts Russ Cox: 1 post

People

Translate

site design / logo © 2022 Grokbase