This is an archive of the discontinued LLVM Phabricator instance.

[IR] Added operator delete to subclasses of User to avoid UB
ClosedPublic

Authored by MoritzS on May 26 2021, 2:15 AM.

Details

Summary

Several subclasses of User override operator new without also overriding
operator delete. This means that delete expressions fall back to using
operator delete of the base class, which would be User. However, this is
only allowed if the base class has a virtual destructor which is not the
case for User, so this is UB.

See also [expr.delete] (3) for the exact wording.

This is actually detected in some cases by GCC 11's
-Wmismatched-new-delete now which is how I found this error.

Diff Detail

Event Timeline

MoritzS created this revision.May 26 2021, 2:15 AM
MoritzS requested review of this revision.May 26 2021, 2:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2021, 2:15 AM
MoritzS updated this revision to Diff 356625.Jul 6 2021, 12:45 AM

Rebased onto main

dblaikie accepted this revision.Jul 7 2021, 12:33 PM

Sounds OK to me - might not hurt to fix the naming convention issues on the lines you're touching/adding.

This revision is now accepted and ready to land.Jul 7 2021, 12:33 PM
MoritzS updated this revision to Diff 357151.Jul 8 2021, 12:22 AM

Fixed variable names

MoritzS updated this revision to Diff 357167.Jul 8 2021, 2:11 AM

User::operator delete(Ptr) must not be called with any additional arguments. Fixed that.