compiler: create temporaries for heap variables
commit7ad5a72c8bc6aa71a0d195ddfa207db01265fe0b
authorIan Lance Taylor <iant@golang.org>
Thu, 11 Mar 2021 03:38:21 +0000 (10 19:38 -0800)
committerIan Lance Taylor <iant@golang.org>
Thu, 11 Mar 2021 23:48:10 +0000 (11 15:48 -0800)
tree764937d8460563db6132d7c75e19b95ef3ea6ea8
parent3857edb5d32dcdc11d9a2fe3ad7c156c52a1ec7f
compiler: create temporaries for heap variables

The compiler generally doesn't create a temporary for an expression
that is a variable, because it's normally valid to simply reload the
value from the variable.  However, if the variable is in the heap,
then loading the value is a pointer indirection.  The process of
creating GCC IR can cause the variable load and the pointer
indirection to be split, such that the second evaluation only does the
pointer indirection.  If there are conditionals in between the two
uses, this can cause the second use to load the pointer from an
uninitialized register.

Avoid this by introducing a new Expression method that returns whether
it is safe to evaluate an expression multiple times, and use it
everywhere.

The test case is https://golang.org/cl/300789.

Fixes golang/go#44383

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/300809
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/expressions.h
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/statements.cc
gcc/go/gofrontend/wb.cc