]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: large ptr literals must escape
authorKeith Randall <khr@golang.org>
Wed, 18 May 2016 20:04:00 +0000 (13:04 -0700)
committerKeith Randall <khr@golang.org>
Thu, 19 May 2016 15:12:01 +0000 (15:12 +0000)
They get rewritten to NEWs, and they must be marked as escaping
so walk doesn't try to allocate them back onto the stack.

Fixes #15733

Change-Id: I433033e737c3de51a9e83a5a273168dbc9110b74
Reviewed-on: https://go-review.googlesource.com/23223
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/gc/esc.go
test/fixedbugs/issue15733.go [new file with mode: 0644]

index bc22dfacc0f71314fa928e865dffe4982b15acc8..553dde8bf99cb907f1d0c2b9bc4c5afbadb1e8d9 100644 (file)
@@ -640,7 +640,7 @@ func esc(e *EscState, n *Node, up *Node) {
        // "Big" conditions that were scattered around in walk have been gathered here
        if n.Esc != EscHeap && n.Type != nil &&
                (n.Type.Width > MaxStackVarSize ||
-                       n.Op == ONEW && n.Type.Elem().Width >= 1<<16 ||
+                       (n.Op == ONEW || n.Op == OPTRLIT) && n.Type.Elem().Width >= 1<<16 ||
                        n.Op == OMAKESLICE && !isSmallMakeSlice(n)) {
                if Debug['m'] > 2 {
                        Warnl(n.Lineno, "%v is too large for stack", n)
diff --git a/test/fixedbugs/issue15733.go b/test/fixedbugs/issue15733.go
new file mode 100644 (file)
index 0000000..8f609e6
--- /dev/null
@@ -0,0 +1,23 @@
+// compile
+
+// Copyright 2016 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.
+
+package main
+
+type S struct {
+       a [1 << 16]byte
+}
+
+func f1() {
+       p := &S{}
+       _ = p
+}
+
+type T [1 << 16]byte
+
+func f2() {
+       p := &T{}
+       _ = p
+}