From: Nicolai Hähnle Date: Wed, 3 Aug 2022 08:56:10 +0000 (+0200) Subject: [Timer][Statistics] Make global constructor ordering more robust X-Git-Tag: upstream/17.0.6~35383 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af2e54992de969f3ec75e397f1840068c2ebd060;p=platform%2Fupstream%2Fllvm.git [Timer][Statistics] Make global constructor ordering more robust It was observed in D129117 that the subtle dependency between statistic and timer code is not entirely robust: the global destructor ~StatisticInfo indirectly calls CreateInfoOutputFile, which requires the LibSupportInfoOutputFilename to not have been destructed. By constructing LibSupportInfoOutputFilename before the StatisticInfo object, the order of destruction is guaranteed. Differential Revision: https://reviews.llvm.org/D131059 --- diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h index 742d20c..d72af35 100644 --- a/llvm/include/llvm/Support/Timer.h +++ b/llvm/include/llvm/Support/Timer.h @@ -231,10 +231,10 @@ public: /// Prints all timers as JSON key/value pairs. static const char *printAllJSONValues(raw_ostream &OS, const char *delim); - /// Ensure global timer group lists are initialized. This function is mostly - /// used by the Statistic code to influence the construction and destruction - /// order of the global timer lists. - static void ConstructTimerLists(); + /// Ensure global objects required for statistics printing are initialized. + /// This function is used by the Statistic code to ensure correct order of + /// global constructors and destructors. + static void constructForStatistics(); /// This makes the default group unmanaged, and lets the user manage the /// group's lifetime. diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp index df9f7c5..24ef3e9 100644 --- a/llvm/lib/Support/Statistic.cpp +++ b/llvm/lib/Support/Statistic.cpp @@ -120,8 +120,9 @@ void TrackingStatistic::RegisterStatistic() { } StatisticInfo::StatisticInfo() { - // Ensure timergroup lists are created first so they are destructed after us. - TimerGroup::ConstructTimerLists(); + // Ensure that necessary timer global objects are created first so they are + // destructed after us. + TimerGroup::constructForStatistics(); } // Print information when destroyed, iff command line option is specified. diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index 08e1a8a..c1b0fdb 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -499,7 +499,8 @@ const char *TimerGroup::printAllJSONValues(raw_ostream &OS, const char *delim) { return delim; } -void TimerGroup::ConstructTimerLists() { +void TimerGroup::constructForStatistics() { + (void)getLibSupportInfoOutputFilename(); (void)*NamedGroupedTimers; }