]> gcc.gnu.org Git - gcc.git/commit
call maybe_return_this in build_clone
authorAlexandre Oliva <oliva@adacore.com>
Wed, 29 Nov 2023 07:00:35 +0000 (04:00 -0300)
committerTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Fri, 9 Feb 2024 21:13:31 +0000 (22:13 +0100)
commit583bd84075d23cde5fd489ab726093060870d773
tree8747e6dc8879806a0f420dd0da5fb42a6af652f0
parent5b3dcff46780192a2e526bc434d61c8626898050
call maybe_return_this in build_clone

__dt_base doesn't get its body from a maybe_return_this caller, it's
rather cloned with the full body within build_clone, and then it's
left alone, without going through finish_function_body or
build_delete_destructor_body, that call maybe_return_this.

Now, this is correct as far as the generated code is concerned, since
the cloned body of a cdtor that returns this is also a cdtor body that
returns this.  The problem is that the decl for THIS is also cloned,
and it doesn't get the warning suppression introduced by
maybe_return_this, so Wuse-after-free3.C fails with an excess warning
at the closing brace of the dtor body.

I've split out the warning suppression from maybe_return_this, and
arranged to call that bit from the relevant build_clone case.
Unfortunately, because the warning is silenced for all uses of the
THIS decl, rather than only for the ABI-mandated return stmt, this
also silences the very warning that the testcase checks for.

I'm not revamping the warning suppression approach to overcome this,
so I'm xfailing the expected warning on ARM EABI, hoping that's the
only target with cdtor_return_this, and leaving it at that.

for  gcc/cp/ChangeLog

* decl.cc (maybe_prepare_return_this): Split out of...
(maybe_return_this): ... this.
* cp-tree.h (maybe_prepare_return_this): Declare.
* class.cc (build_clone): Call it.

for  gcc/testsuite/ChangeLog

* g++.dg/warn/Wuse-after-free3.C: xfail on arm_eabi.

(cherry picked from commit 0d24289d129639efdc79338a64188d6d404375e8)
gcc/cp/class.cc
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/testsuite/g++.dg/warn/Wuse-after-free3.C
This page took 0.06257 seconds and 5 git commands to generate.