diff options
author | Chris Manghane <cmang@google.com> | 2015-04-30 20:44:03 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-04-30 20:44:03 +0000 |
commit | 4f576c83fb197b74767c536583107b457aead8ef (patch) | |
tree | ea4d7673e4669f048a90928ef154e42a4227260d /gcc/go/go-gcc.cc | |
parent | 6d158d9a6bc15a0b1bf97cc434b64c7d72f524ff (diff) | |
download | gcc-4f576c83fb197b74767c536583107b457aead8ef.zip gcc-4f576c83fb197b74767c536583107b457aead8ef.tar.gz gcc-4f576c83fb197b74767c536583107b457aead8ef.tar.bz2 |
compiler: Use backend interface for stack allocation.
Stack allocation was being done by making a temporary variable and
taking its address. This does not work when allocating in a loop
because every allocated variable will refer to the same address.
The backend now provides a way to safely allocate in a loop.
* go-gcc.cc (Gcc_backend::stack_allocation_expression): New
method.
From-SVN: r222657
Diffstat (limited to 'gcc/go/go-gcc.cc')
-rw-r--r-- | gcc/go/go-gcc.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index 08f014f..82ce3ee6 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -324,6 +324,9 @@ class Gcc_backend : public Backend call_expression(Bexpression* fn, const std::vector<Bexpression*>& args, Bexpression* static_chain, Location); + Bexpression* + stack_allocation_expression(int64_t size, Location); + // Statements. Bstatement* @@ -1884,6 +1887,17 @@ Gcc_backend::call_expression(Bexpression* fn_expr, return this->make_expression(ret); } +// Return an expression that allocates SIZE bytes on the stack. + +Bexpression* +Gcc_backend::stack_allocation_expression(int64_t size, Location location) +{ + tree alloca = builtin_decl_explicit(BUILT_IN_ALLOCA); + tree size_tree = build_int_cst(integer_type_node, size); + tree ret = build_call_expr_loc(location.gcc_location(), alloca, 1, size_tree); + return this->make_expression(ret); +} + // An expression as a statement. Bstatement* |