• Keith Randall's avatar
    cmd/compile: pad zero-sized stack variables · c5414457
    Keith Randall authored
    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: 's avatarIan Lance Taylor <iant@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    c5414457
zerosize.go 537 Bytes