This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix missed DSE opportunity with operator delete.


On Tue, 26 Apr 2016, Richard Biener wrote:

On Mon, Apr 25, 2016 at 9:57 PM, Jason Merrill <jason@redhat.com> wrote:
Hmm, this seems to assume that operator delete itself doesn't do
anything with the object being deleted.  This is true of the default
implementation, but I don't see anything in the standard that
prohibits a user-supplied replacement or class-specific deallocation
function from accessing the memory.

Hmm, but the delete expression invokes the (default) destructor which
ends the lifetime of the object and thus invalidates all memory.  Don't
we place a CLOBBER there as well nowadays (seems not).

For

struct A { A(); ~A(); int i; };

int main()
{
 A *a = new A;
 delete a;
}

I see

   struct A * a;
 <<cleanup_point <<< Unknown tree: expr_stmt
 (void) (a = TARGET_EXPR <D.2346, operator new (4)>;, try
   {
     A::A ((struct A *) D.2346);
   }
 catch
   {
     operator delete (D.2346);
   }, (struct A *) D.2346;) >>>>>;
 <<cleanup_point <<< Unknown tree: expr_stmt
 if (SAVE_EXPR <a> != 0B)
   {
     A::~A (SAVE_EXPR <a>);, operator delete ((void *) SAVE_EXPR <a>);;
   }
 else
   {
     <<< Unknown tree: void_cst >>>
   } >>>>>;

so after the destructor is invoked the objects lifetime ends.

You can also call operator new and operator delete directly in C++, not just through new/delete expressions, and that's what std::allocator does.

Especially in C++17 where we should have aligned allocation, I can imagine operator new / delete implemented like gcc/config/i386/gmm_malloc.h on some platforms, which requires reading in operator delete stuff that operator new wrote there. Depending on inline decisions, DSE-ing part of new could be problematic (IIRC those functions are technically not allowed to be marked 'inline', but that's not quite the same thing).

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]