[llvm-commits] CVS: llvm/lib/Support/Timer.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Jul 31 14:39:00 PDT 2003


Changes in directory llvm/lib/Support:

Timer.cpp updated: 1.22 -> 1.23

---
Log message:

Fix the JIT in the Nightly tester.  This was not a fun bug to track down.  
See the comments in the patch for details.



---
Diffs of the changes:

Index: llvm/lib/Support/Timer.cpp
diff -u llvm/lib/Support/Timer.cpp:1.22 llvm/lib/Support/Timer.cpp:1.23
--- llvm/lib/Support/Timer.cpp:1.22	Thu Jul 31 14:31:21 2003
+++ llvm/lib/Support/Timer.cpp	Thu Jul 31 14:38:34 2003
@@ -17,7 +17,18 @@
 #include <functional>
 #include <fstream>
 
-static std::string LibSupportInfoOutputFilename;
+// getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
+// of constructor/destructor ordering being unspecified by C++.  Basically the
+// problem is that a Statistic<> object gets destroyed, which ends up calling
+// 'GetLibSupportInfoOutputFile()' (below), which calls this function.
+// LibSupportInfoOutputFilename used to be a global variable, but sometimes it
+// would get destroyed before the Statistic, causing havoc to ensue.  We "fix"
+// this by creating the string the first time it is needed and never destroying
+// it.
+static std::string &getLibSupportInfoOutputFilename() {
+  static std::string *LibSupportInfoOutputFilename = new std::string();
+  return *LibSupportInfoOutputFilename;
+}
 
 namespace {
 #ifdef HAVE_MALLINFO
@@ -30,7 +41,7 @@
   cl::opt<std::string, true>
   InfoOutputFilename("info-output-file",
                      cl::desc("File to append -stats and -timer output to"),
-                     cl::Hidden, cl::location(LibSupportInfoOutputFilename));
+                   cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
 }
 
 static TimerGroup *DefaultTimerGroup = 0;
@@ -232,6 +243,7 @@
 
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
 std::ostream *GetLibSupportInfoOutputFile() {
+  std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
   if (LibSupportInfoOutputFilename.empty())
     return &std::cerr;
   if (LibSupportInfoOutputFilename == "-")





More information about the llvm-commits mailing list