[llvm-commits] [llvm] r75149 - /llvm/trunk/include/llvm/Support/ManagedStatic.h
Alisdair Meredith
public at alisdairm.net
Thu Jul 9 10:26:16 PDT 2009
Author: alisdairm
Date: Thu Jul 9 12:26:16 2009
New Revision: 75149
URL: http://llvm.org/viewvc/llvm-project?rev=75149&view=rev
Log:
Resolve undefined behaviour when ManagedStatic is instantiated with a fixed-length array type.
Modified:
llvm/trunk/include/llvm/Support/ManagedStatic.h
Modified: llvm/trunk/include/llvm/Support/ManagedStatic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ManagedStatic.h?rev=75149&r1=75148&r2=75149&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ManagedStatic.h (original)
+++ llvm/trunk/include/llvm/Support/ManagedStatic.h Thu Jul 9 12:26:16 2009
@@ -27,10 +27,12 @@
/// object_deleter - Helper method for ManagedStatic.
///
-template<class C>
-void object_deleter(void *Ptr) {
- delete (C*)Ptr;
-}
+template<typename T> struct object_deleter {
+ static void call(void * Ptr) { delete (T*)Ptr; }
+};
+template<typename T, size_t N> struct object_deleter<T[N]> {
+ static void call(void * Ptr) { delete[] (T*)Ptr; }
+};
/// ManagedStaticBase - Common base class for ManagedStatic instances.
class ManagedStaticBase {
@@ -62,28 +64,28 @@
C &operator*() {
void* tmp = Ptr;
if (llvm_is_multithreaded()) sys::MemoryFence();
- if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>);
+ if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
return *static_cast<C*>(Ptr);
}
C *operator->() {
void* tmp = Ptr;
if (llvm_is_multithreaded()) sys::MemoryFence();
- if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>);
+ if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
return static_cast<C*>(Ptr);
}
const C &operator*() const {
void* tmp = Ptr;
if (llvm_is_multithreaded()) sys::MemoryFence();
- if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>);
+ if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
return *static_cast<C*>(Ptr);
}
const C *operator->() const {
void* tmp = Ptr;
if (llvm_is_multithreaded()) sys::MemoryFence();
- if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>);
+ if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
return static_cast<C*>(Ptr);
}
More information about the llvm-commits
mailing list