[LLVMdev] LLVM is deleting an array pointer without using array notation

OvermindDL1 overminddl1 at gmail.com
Tue May 12 17:07:32 PDT 2009


Here is the warning I am getting:

PseudoSourceValue.cpp
R:\SDKs\llvm\trunk\include\llvm/Support/ManagedStatic.h(23) : warning
C4156: deletion of an array expression without using the array form of
'delete'; array form substituted
        R:\SDKs\llvm\trunk\include\llvm/Support/ManagedStatic.h(72) :
see reference to function template instantiation 'void
llvm::object_deleter<C>(void *)' being compiled
        with
        [
            C=llvm::PseudoSourceValue [4]
        ]
        R:\SDKs\llvm\trunk\include\llvm/Support/ManagedStatic.h(71) :
while compiling class template member function 'void
llvm::ManagedStatic<C>::LazyInit(void) const'
        with
        [
            C=llvm::PseudoSourceValue [4]
        ]
        ..\..\..\trunk\lib\CodeGen\PseudoSourceValue.cpp(23) : see
reference to class template instantiation 'llvm::ManagedStatic<C>'
being compiled
        with
        [
            C=llvm::PseudoSourceValue [4]
        ]

The deleter is in the file ManagedStatic.h on line 21:
template<class C>
void object_deleter(void *Ptr) {
  delete (C*)Ptr;
}

And it is being passed an array to delete in file
PseudoSourceValue.cpp on line 23:
static ManagedStatic<PseudoSourceValue[4]> PSVs;

A template specialization for array types will work, the
tr1::type_traits or boost::type_traits (same thing and you can include
the parts you wish to use with LLVM, the license encourages that) can
detect an array type like that and specialize based on it.  If you do
not mind including a few boost files with LLVM for the
Boost.Type_Traits and Boost.Enable_If then I can specialize based on
an array, or you could always pass another template parameter to
ManagedStatic and hope that the user of it remembers to set it when
they pass an array type (safer to specialize it based on the array
type obviously).

Either way, MSVC is replacing the templated delete with delete[], but
throwing that warning in the process since this is *very*wrong* code.



More information about the llvm-dev mailing list