]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: pad zero-sized stack variables
authorKeith Randall <khr@google.com>
Sat, 22 Dec 2018 00:36:45 +0000 (16:36 -0800)
committerKeith Randall <khr@golang.org>
Sat, 22 Dec 2018 01:16:00 +0000 (01:16 +0000)
commitc5414457c62fc11f299946a46f6c868c4f0bf2ab
treed1dfb4b153923f176766f531cd0ef0287d543183
parentdebca779719a72929932c589fe7ed3fea5341e53
cmd/compile: pad zero-sized stack variables

If someone takes a pointer to a zero-sized stack variable, it can
be incorrectly interpreted as a pointer to the next object in the
stack frame. To avoid this, add some padding after zero-sized variables.

We only need to pad if the next variable in memory (which is the
previous variable in the order in which we allocate variables to the
stack frame) has pointers. If the next variable has no pointers, it
won't hurt to have a pointer to it.

Because we allocate all pointer-containing variables before all
non-pointer-containing variables, we should only have to pad once per
frame.

Fixes #24993

Change-Id: Ife561cdfdf964fdbf69af03ae6ba97d004e6193c
Reviewed-on: https://go-review.googlesource.com/c/155698
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/compile/internal/gc/pgen.go
test/codegen/zerosize.go [new file with mode: 0644]