mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 00:32:55 +00:00
Resolve undefined behaviour when ManagedStatic is instantiated with a fixed-length array type.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75149 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1fc3d75581
commit
80c8c31782
@ -27,10 +27,12 @@ void* object_creator() {
|
||||
|
||||
/// 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 @@ public:
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user