]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix inlining bug
authorRuss Cox <rsc@golang.org>
Wed, 11 Jan 2012 21:21:06 +0000 (13:21 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 11 Jan 2012 21:21:06 +0000 (13:21 -0800)
Fixes #2682.

R=lvd
CC=golang-dev
https://golang.org/cl/5538043

src/cmd/gc/fmt.c
test/fixedbugs/bug392.dir/one.go
test/fixedbugs/bug392.dir/two.go
test/fixedbugs/bug392.go

index 0eb5854aec55e065c33f96575f7955c63a0112b4..f49c703f360008d42fd620e44375ce7c0dd6aa0e 100644 (file)
@@ -1078,7 +1078,9 @@ exprfmt(Fmt *f, Node *n, int prec)
                if(n->val.ctype == CTNIL)
                        n = n->orig; // if this node was a nil decorated with at type, print the original naked nil
                if(n->type != types[n->type->etype] && n->type != idealbool && n->type != idealstring) {
-                       if(isptr[n->type->etype])
+                       // Need parens when type begins with what might
+                       // be misinterpreted as a unary operator: * or <-.
+                       if(isptr[n->type->etype] || (n->type->etype == TCHAN && n->type->chan == Crecv))
                                return fmtprint(f, "(%T)(%V)", n->type, &n->val);
                        else 
                                return fmtprint(f, "%T(%V)", n->type, &n->val);
index 6353b88e1a9882fcda366753662158e02e1cd1cf..50c1689e3b9b4b96ba8669795c3babe4c244a5dd 100644 (file)
@@ -1,6 +1,15 @@
+// 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.
+
+// Functions that the inliner exported incorrectly.
+
 package one
 
-type file int
-func (file *file) isnil() bool { return file == nil }
-func (fil *file)  isnil2() bool { return fil == nil }
+type T int
+
+// Issue 2678
+func F1(T *T) bool { return T == nil }
 
+// Issue 2682.
+func F2(c chan int) bool { return c == (<-chan int)(nil) }
index 8a5346ab72b0a03032cf23f5e627cf2ec28ee8ba..f16533a3305dfd8abbde8cae41accfe7215f695d 100644 (file)
@@ -1,4 +1,16 @@
+// 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.
+
+// Use the functions in one.go so that the inlined
+// forms get type-checked.
+
 package two
 
-import _ "./one"
+import "./one"
+
+func use() {
+       one.F1(nil)
+       one.F2(nil)
+}
 
index 46781eb4282498353ae4682fa96648103b1e79d7..50af6006fbe698c60458fbbcf1a8c53ff68acafd 100644 (file)
@@ -1,11 +1,7 @@
-// $G $D/$F.dir/one.go && $G -ll $D/$F.dir/two.go
+// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go
 
 // Copyright 2011 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 2678
-// -ll flag in command above is to force typecheck on import, needed to trigger the bug.
-// fixedbugs/bug392.dir/two.go:3: cannot call non-function *one.file (type one.file)
 
 package ignored