[IR] Added operator delete to subclasses of User to avoid UB
authorMoritz Sichert <sichert@in.tum.de>
Wed, 26 May 2021 08:50:15 +0000 (10:50 +0200)
committerMoritz Sichert <sichert@in.tum.de>
Thu, 8 Jul 2021 09:59:22 +0000 (11:59 +0200)
commitd58c7a92380e030af6e6f82ce55bc14a919f39ea
treea2913957604b324b99b54f11e80f608f9c41d69c
parent715ca752ac4f8ba69fe68110823e0eabf5614bc7
[IR] Added operator delete to subclasses of User to avoid UB

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.

Differential Revision: https://reviews.llvm.org/D103143
llvm/include/llvm/Analysis/MemorySSA.h
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/GlobalIndirectSymbol.h
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Instructions.h
llvm/lib/IR/ConstantsContext.h