Bug 51060 - Temporary object stack space is not re-used
Summary: Temporary object stack space is not re-used
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.2
: P3 normal
Target Milestone: 4.7.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 14:02 UTC by Andrey Galkin
Modified: 2011-11-13 00:47 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-11-09 00:00:00


Attachments
10 tmp objects of 1KB in size produce 10KB frame (334 bytes, text/x-c++src)
2011-11-09 14:02 UTC, Andrey Galkin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Galkin 2011-11-09 14:02:06 UTC
Created attachment 25769 [details]
10 tmp objects of 1KB in size produce 10KB frame

I've tried hard finding a related incident, the only one close to it is PR 16269, but its solution doesn't help.

Attached is a sample test, which allocates 10 temporary objects of 1KB size in own blocks in the same function.

If compiled with "-Wframe-larger-than=2048 -Werror -Os" (-Oany) the following warning is produced:
warning: the frame size of 10240 bytes is larger than 2048 bytes [-Wframe-larger-than=]


In our case, function frames are blown away for 100+KB, what makes a code with similar pattern absolutely unusable in embedded systems.


Reproduced on GCC 4.6.1 x86_64 @ Debian and custom built GCC 4.6.2 for ARM.
The same issue exists in GCC 4.3.x for ARM.
Comment 1 Richard Biener 2011-11-09 14:41:24 UTC
Confirmed.  The new death-point stuff doesn't help as the frontend does
not seem to construct scopes properly for this testcase.

;; Function void Test() (null)
;; enabled by -tree-original

<<cleanup_point <<< Unknown tree: expr_stmt
  (void) TARGET_EXPR <D.21343, <<< Unknown tree: aggr_init_expr
  4
  __comp_ctor
  D.21343
  0B >>>> >>>>>;
<<cleanup_point <<< Unknown tree: expr_stmt
  (void) TARGET_EXPR <D.21344, <<< Unknown tree: aggr_init_expr
  4
  __comp_ctor
  D.21344
  0B >>>> >>>>>;
...
Comment 2 Jason Merrill 2011-11-11 21:50:29 UTC
We already deal with cleanups for temporary objects, it should be pretty simple to add the death clobber that way.
Comment 3 Jason Merrill 2011-11-13 00:44:43 UTC
Author: jason
Date: Sun Nov 13 00:44:39 2011
New Revision: 181332

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181332
Log:
	PR c++/51060
	* gimplify.c (gimplify_target_expr): Add a clobber to the cleanup.
	(gimplify_modify_expr): Don't try to simplify it.
	* cp/cp-gimplify.c (cp_gimplify_expr): Leave clobbers alone.

Added:
    trunk/gcc/testsuite/g++.dg/opt/stack2.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-gimplify.c
    trunk/gcc/gimplify.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/testsuite/25_algorithms/max/1.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/min/1.cc
    trunk/libstdc++-v3/testsuite/25_algorithms/minmax/1.cc
Comment 4 Jason Merrill 2011-11-13 00:47:26 UTC
Indeed, pretty simple now that we have that infrastructure.