[PATCH] D79378: PR34581: Don't remove an 'if (p)' guarding a call to 'operator delete(p)' under -Oz.

Richard Smith - zygoloid via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 17:14:00 PDT 2020


rsmith created this revision.
rsmith added reviewers: davide, dnsampaio, rjmccall.
Herald added a subscriber: hiraditya.
Herald added projects: clang, LLVM.

This transformation is correct for a builtin call to 'free(p)', but not
for 'operator delete(p)'. There is no guarantee that a user replacement
'operator delete' has no effect when called on a null pointer.

However, the principle behind the transformation *is* correct, and can
be applied more broadly: a 'delete p' expression is permitted to
unconditionally call 'operator delete(p)'. So do that in Clang under
-Oz where possible. We do this whether or not 'p' has trivial
destruction, since the destruction might turn out to be trivial after
inlining, and even for a class-specific (but non-virtual,
non-destroying, non-array) 'operator delete'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79378

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/delete.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/malloc-free-delete.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79378.261963.patch
Type: text/x-patch
Size: 5705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200505/a13c4554/attachment-0001.bin>


More information about the llvm-commits mailing list