On Mon, Mar 30, 2020 at 10:41 AM Martin Liška <[email protected]> wrote:
>
> Hi.
>
> The patch ensures that a deleted new/delete pair has a same context.
> That will fix the issue presented in the PR.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
I think this will break the DCE with LTO since we strip quite some
DECL_CONTEXT in free-lang-data.
Honza - do you remember why we strip DECL_CONTEXT for methods
which will most likely keep their containing record types live through
their this
arguments? Quoting:
/* We need to keep field decls associated with their trees. Otherwise tree
merging may merge some fileds and keep others disjoint wich in turn will
not do well with TREE_CHAIN pointers linking them.
Also do not drop containing types for virtual methods and tables because
these are needed by devirtualization.
C++ destructors are special because C++ frontends sometimes produces
virtual destructor as an alias of non-virtual destructor. In
devirutalization code we always walk through aliases and we need
context to be preserved too. See PR89335 */
if (TREE_CODE (decl) != FIELD_DECL
&& ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
|| (!DECL_VIRTUAL_P (decl)
&& (TREE_CODE (decl) != FUNCTION_DECL
|| !DECL_CXX_DESTRUCTOR_P (decl)))))
DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
and fld_decl_context stripping up to the next non-TYPE context (unless VLA).
Richard.
> Ready to be installed?
> Thanks,
> Martin
>
> gcc/ChangeLog:
>
> 2020-03-30 Martin Liska <[email protected]>
>
> PR c++/94314
> * tree-ssa-dce.c (propagate_necessity): Verify that
> DECL_CONTEXT of a new/delete operators do match.
>
> gcc/testsuite/ChangeLog:
>
> 2020-03-30 Martin Liska <[email protected]>
>
> PR c++/94314
> * g++.dg/pr94314.C: New test.
> ---
> gcc/testsuite/g++.dg/pr94314.C | 84 ++++++++++++++++++++++++++++++++++
> gcc/tree-ssa-dce.c | 31 +++++++++----
> 2 files changed, 105 insertions(+), 10 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/pr94314.C
>
>