diff --git a/include/llvm/Support/ManagedStatic.h b/include/llvm/Support/ManagedStatic.h index 9e193c1a469..b4bf3210cc7 100644 --- a/include/llvm/Support/ManagedStatic.h +++ b/include/llvm/Support/ManagedStatic.h @@ -20,7 +20,9 @@ namespace llvm { /// object_creator - Helper method for ManagedStatic. -template void *object_creator() { return new C(); } +template struct object_creator { + static void *call() { return new C(); } +}; /// object_deleter - Helper method for ManagedStatic. /// @@ -54,15 +56,15 @@ public: /// libraries that link in LLVM components) and for making destruction be /// explicit through the llvm_shutdown() function call. /// -template , - void (*Deleter)(void *) = object_deleter::call> +template , + class Deleter = object_deleter> class ManagedStatic : public ManagedStaticBase { public: // Accessors. C &operator*() { void *Tmp = Ptr.load(std::memory_order_acquire); if (!Tmp) - RegisterManagedStatic(Creator, Deleter); + RegisterManagedStatic(Creator::call, Deleter::call); return *static_cast(Ptr.load(std::memory_order_relaxed)); } @@ -72,7 +74,7 @@ public: const C &operator*() const { void *Tmp = Ptr.load(std::memory_order_acquire); if (!Tmp) - RegisterManagedStatic(Creator, Deleter); + RegisterManagedStatic(Creator::call, Deleter::call); return *static_cast(Ptr.load(std::memory_order_relaxed)); } diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index ddcb057218d..dec6baf7bf4 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -73,9 +73,11 @@ std::unique_ptr llvm::CreateInfoOutputFile() { } namespace { -void *CreateDefaultTimerGroup() { - return new TimerGroup("misc", "Miscellaneous Ungrouped Timers"); -} +struct CreateDefaultTimerGroup { + static void *call() { + return new TimerGroup("misc", "Miscellaneous Ungrouped Timers"); + } +}; } // namespace static ManagedStatic DefaultTimerGroup; static TimerGroup *getDefaultTimerGroup() { return &*DefaultTimerGroup; } diff --git a/unittests/Support/ManagedStatic.cpp b/unittests/Support/ManagedStatic.cpp index 96f9e92c6e0..4e2e93036a8 100644 --- a/unittests/Support/ManagedStatic.cpp +++ b/unittests/Support/ManagedStatic.cpp @@ -82,12 +82,17 @@ TEST(ManagedStaticTest, NestedStatics) { } // namespace NestedStatics namespace CustomCreatorDeletor { -void *CustomCreate() { - void *Mem = std::malloc(sizeof(int)); - *((int *)Mem) = 42; - return Mem; -} -static ManagedStatic Custom; +struct CustomCreate { + static void *call() { + void *Mem = std::malloc(sizeof(int)); + *((int *)Mem) = 42; + return Mem; + } +}; +struct CustomDelete { + static void call(void *P) { std::free(P); } +}; +static ManagedStatic Custom; TEST(ManagedStaticTest, CustomCreatorDeletor) { EXPECT_EQ(42, *Custom); }