New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: autotemps can make stack frame too large #27447

Open
randall77 opened this Issue Sep 2, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@randall77
Contributor

randall77 commented Sep 2, 2018

When the order pass introduces temporaries, it always allocates them on the stack, even if they are too big for the stack.

package main

import "reflect"

func f() {
	g(reflect.TypeOf([2000000000]*byte{}))
}

//go:noescape
func g(p reflect.Type)

We should use the same rules as escape analysis does to decide if we should put the temporary on the stack or the heap.

Before order:

.   .   .   AS2-list
.   .   .   .   NAME-reflect.i a(true) l(1376) x(0) class(PAUTO) tc(1) addrtaken assigned used INTER-interface {}
.   .   .   AS2-rlist
.   .   .   .   CONVIFACE l(6) esc(no) tc(1) implicit(true) INTER-interface {}
.   .   .   .   .   ARRAYLIT l(6) esc(h) tc(1) ARRAY-[2000000000]*byte

After order:

.   AS l(6) tc(1)
.   .   NAME-main..autotmp_5 a(true) l(6) x(0) class(PAUTO) esc(N) tc(1) assigned used ARRAY-[2000000000]*byte
.   .   ARRAYLIT l(6) esc(h) tc(1) ARRAY-[2000000000]*byte

.   AS2 l(6) tc(1)
.   AS2-list
.   .   NAME-reflect.i a(true) l(1376) x(0) class(PAUTO) tc(1) addrtaken assigned used INTER-interface {}
.   AS2-rlist
.   .   CONVIFACE l(6) esc(no) tc(1) implicit(true) INTER-interface {}
.   .   .   NAME-main..autotmp_5 a(true) l(6) x(0) class(PAUTO) esc(N) tc(1) assigned used ARRAY-[2000000000]*byte

.   VARKILL l(6) tc(1)
.   .   NAME-main..autotmp_5 a(true) l(6) x(0) class(PAUTO) esc(N) tc(1) assigned used ARRAY-[2000000000]*byte
@randall77

This comment has been minimized.

Contributor

randall77 commented Sep 2, 2018

This is the error:

$ go tool compile tmp2.go
tmp2.go:5:6: stack frame too large (>1GB)
@josharian

This comment has been minimized.

Contributor

josharian commented Sep 2, 2018

The cutoff (1<<16) is also duplicated in a couple of places in walk.go (func isSmallMakeSlice, case ONEW in func walkexpr). Should unify all of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment