d: Fix callee destructor call invalidates the live object [PR113758]
commit3c57b1c12a8e34d50bdf6aaf44146760db6d1b33
authorIain Buclaw <ibuclaw@gdcproject.org>
Sun, 4 Feb 2024 21:04:14 +0000 (4 22:04 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 12 Feb 2024 15:48:41 +0000 (12 16:48 +0100)
tree5ce1a9fa46097af71645adcb4772905e072061a0
parent1fcaa3a8225885a93d537025cb071651c13235f7
d: Fix callee destructor call invalidates the live object [PR113758]

When generating the argument, check the isCalleeDestroyingArgs hook, and
force a TARGET_EXPR to be created if true, so that a reference to the
live object isn't passed directly to the function that runs dtors.

When instead dealing with caller running destructors, two temporaries
were being generated, one explicit temporary generated by the D
front-end, and another implicitly by the code generator.  This has been
reduced to one by setting DECL_VALUE_EXPR on the explicit temporary to
bind it to the implicit slot created for the TARGET_EXPR, as that has
the shorter lifetime of the two.

PR d/113758

gcc/d/ChangeLog:

* d-codegen.cc (d_build_call): Force a TARGET_EXPR when callee
destorys its arguments.
* decl.cc (DeclVisitor::visit (VarDeclaration *)): Set
SET_DECL_VALUE_EXPR on the temporary variable to make it a placeholder
for the TARGET_EXPR_SLOT.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr113758.d: New test.
gcc/d/d-codegen.cc
gcc/d/decl.cc
gcc/testsuite/gdc.dg/torture/pr113758.d [new file with mode: 0644]