From 351779e9720e520603325c5a44218016c1bc6192 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 29 May 2017 14:05:29 +0000 Subject: [PATCH] [Timer] Move DefaultTimerGroup into a ManagedStatic. This used to be just leaked. r295370 made it use magic statics. This adds a global destructor, which is something we'd like to avoid. It also creates a weird situation where the mutex used by TimerGroup is re-created during global shutdown and leaked. Using a ManagedStatic here is also subtle as it relies on the mutex inside of ManagedStatic to be recursive. I've added a test for that in a previous change. llvm-svn: 304156 --- llvm/lib/Support/Timer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index 8d68c6ae9682..4cb04c164f02 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -72,10 +72,11 @@ std::unique_ptr llvm::CreateInfoOutputFile() { return llvm::make_unique(2, false); // stderr. } -static TimerGroup *getDefaultTimerGroup() { - static TimerGroup DefaultTimerGroup("misc", "Miscellaneous Ungrouped Timers"); - return &DefaultTimerGroup; +static void *CreateDefaultTimerGroup() { + return new TimerGroup("misc", "Miscellaneous Ungrouped Timers"); } +static ManagedStatic DefaultTimerGroup; +static TimerGroup *getDefaultTimerGroup() { return &*DefaultTimerGroup; } //===----------------------------------------------------------------------===// // Timer Implementation