compiler: make top-level decl for address-taken non-escaping locals

Programming / Compilers / GCC - ian [138bc75d-0d04-0410-961f-82ee72b054a4] - 9 January 2018 21:33 EST

If a local variable's address is taken and passed out of its lexical scope, GCC backend may reuse the stack slot for the
variable, not knowing it is still live through a pointer. In this case, we create a top-level temporary variable and let the user-defined variable refer to the temporary variable as its storage location. As the temporary variable is declared at the top level, its stack slot will remain live throughout the function.

Reviewed-on: https://go-review.googlesource.com/84675

- go-gcc.cc (local_variable): Add decl_var parameter.

1f33ab41eb9 compiler: make top-level decl for address-taken non-escaping locals
gcc/go/ChangeLog | 4 ++++
gcc/go/go-gcc.cc | 11 ++++++++---
gcc/go/gofrontend/MERGE | 2 +-
gcc/go/gofrontend/backend.h | 17 ++++++++++-------
gcc/go/gofrontend/gogo.cc | 44 +++++++++++++++++++++++++++++++++++++++-----
gcc/go/gofrontend/gogo.h | 17 +++++++++++++++++
6 files changed, 79 insertions(+), 16 deletions(-)

Upstream: gcc.gnu.org


  • Share