aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/backend.h
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2018-01-09 21:33:59 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-09 21:33:59 +0000
commit81e0f09288052014c5fb3136e6abc9dfcc7629db (patch)
treed85e4d07a55f301cdce0f9af88f503c2cc802899 /gcc/go/gofrontend/backend.h
parent6ef72c3661318d0b5d7e3fc8821d136bbba37194 (diff)
downloadgcc-81e0f09288052014c5fb3136e6abc9dfcc7629db.zip
gcc-81e0f09288052014c5fb3136e6abc9dfcc7629db.tar.gz
gcc-81e0f09288052014c5fb3136e6abc9dfcc7629db.tar.bz2
compiler: make top-level decl for address-taken non-escaping locals
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. From-SVN: r256398
Diffstat (limited to 'gcc/go/gofrontend/backend.h')
-rw-r--r--gcc/go/gofrontend/backend.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/gcc/go/gofrontend/backend.h b/gcc/go/gofrontend/backend.h
index 601e7c9..b601105 100644
--- a/gcc/go/gofrontend/backend.h
+++ b/gcc/go/gofrontend/backend.h
@@ -516,15 +516,18 @@ class Backend
// Create a local variable. The frontend will create the local
// variables first, and then create the block which contains them.
// FUNCTION is the function in which the variable is defined. NAME
- // is the name of the variable. TYPE is the type. IS_ADDRESS_TAKEN
- // is true if the address of this variable is taken (this implies
- // that the address does not escape the function, as otherwise the
- // variable would be on the heap). LOCATION is where the variable
- // is defined. For each local variable the frontend will call
- // init_statement to set the initial value.
+ // is the name of the variable. TYPE is the type. DECL_VAR, if not
+ // null, gives the location at which the value of this variable may
+ // be found, typically used to create an inner-scope reference to an
+ // outer-scope variable, to extend the lifetime of the variable beyond
+ // the inner scope. IS_ADDRESS_TAKEN is true if the address of this
+ // variable is taken (this implies that the address does not escape
+ // the function, as otherwise the variable would be on the heap).
+ // LOCATION is where the variable is defined. For each local variable
+ // the frontend will call init_statement to set the initial value.
virtual Bvariable*
local_variable(Bfunction* function, const std::string& name, Btype* type,
- bool is_address_taken, Location location) = 0;
+ Bvariable* decl_var, bool is_address_taken, Location location) = 0;
// Create a function parameter. This is an incoming parameter, not
// a result parameter (result parameters are treated as local