PATCH for to use tree clobbers for c++/51060 (temporary re-use)

H.J. Lu hjl.tools@gmail.com
Wed May 30 01:39:00 GMT 2012


On Thu, May 3, 2012 at 3:39 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sat, Nov 12, 2011 at 4:42 PM, Jason Merrill <jason@redhat.com> wrote:
>> Now that we have a way of explicitly marking a variable as dead, we can use
>> that to indicate the end of a temporary's lifetime by adding it as a cleanup
>> for that temporary.  Since gimple_push_cleanup still deals in trees I needed
>> to tweak a couple of places to avoid trying to treat a clobber as a real
>> CONSTRUCTOR, but the changes were small.
>>
>> One somewhat surprising thing that showed up as a result of this change were
>> some failures in the libstdc++ testsuite.  When I investigated, I found that
>> the tests were relying on temporaries living longer than they should:
>>
>>>  const int& x = std::max(1, 2);
>>
>>
>> Since std::max takes its arguments by const reference and returns one of
>> them, x ends up as a dangling reference to the temporary containing 2, which
>> dies at the end of the declaration-statement.  This patch breaks the
>> testcase because now the temporary stack slots get reused by the next
>> statement, so by the time we look at x it no longer points to a 2.  I've
>> fixed the tests by removing the references on the variables.
>>
>> Tested x86_64-pc-linux-gnu, applying to trunk.
>
> This caused:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53220
>
> --
> H.J.

This also caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53356


-- 
H.J.



More information about the Gcc-patches mailing list