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.
- 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(-)