]> granicus.if.org Git - clang/commitdiff
The diagtool registration system tries to use a global variable from a method
authorNick Lewycky <nicholas@mxc.ca>
Fri, 12 Aug 2011 01:14:22 +0000 (01:14 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 12 Aug 2011 01:14:22 +0000 (01:14 +0000)
called on another global variable. Use ManagedStatic to ensure that the global
we register with actually exists when we need it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137406 91177308-0d34-0410-b5e6-96231b3b80d8

tools/diagtool/DiagTool.cpp
tools/diagtool/DiagTool.h
tools/diagtool/ListWarnings.cpp
tools/diagtool/diagtool_main.cpp

index 1e3f4ef6374b0ab93d341ff21a5deddfcc4481ca..36e72a2ded5abf20a0734a725b21a69158891f33 100644 (file)
@@ -64,5 +64,5 @@ void DiagTools::printCommands(llvm::raw_ostream &out) {
 }
 
 namespace diagtool {
-  DiagTools diagTools;
+  llvm::ManagedStatic<DiagTools> diagTools;
 }
index 5e5e11f2e28df52769ae70c2e05f5501f7d3e9ea..dcb6ac7c76cb9d8d05dc862e2a1de10693853b9b 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ManagedStatic.h"
 #include <string>
 
 
@@ -45,12 +46,12 @@ public:
   void printCommands(llvm::raw_ostream &out);  
 };
 
-extern DiagTools diagTools;
-  
+extern llvm::ManagedStatic<DiagTools> diagTools;
+
 template <typename DIAGTOOL>
 class RegisterDiagTool {
 public:
-  RegisterDiagTool() { diagTools.registerTool(new DIAGTOOL()); }
+  RegisterDiagTool() { diagTools->registerTool(new DIAGTOOL()); }
 };
 
 } // end diagtool namespace
index 70be1c4531e6de39df1e5ef63821e5ec40f75d67..e286f8d37d61983053d20143215704110011783c 100644 (file)
@@ -50,7 +50,7 @@ int ListWarnings::run(unsigned int argc, char **argv, llvm::raw_ostream &out) {
   llvm::IntrusiveRefCntPtr<DiagnosticIDs> Diags(new DiagnosticIDs);
   Diagnostic D(Diags);
   
-  std::vector<Entry> Flagged, Unflagged;;
+  std::vector<Entry> Flagged, Unflagged;
   llvm::StringMap<std::vector<unsigned> > flagHistogram;
   
   for (DiagnosticIDs::diag_iterator di = DiagnosticIDs::diags_begin(),
index 66a73e947a1730c09ddac3d6dc64561c68480d50..e34f0dc06c657c451052949579dacfae03e1ba66 100644 (file)
@@ -17,10 +17,10 @@ using namespace diagtool;
 
 int main(int argc, char *argv[]) {
   if (argc > 1)
-    if (DiagTool *tool = diagTools.getTool(argv[1]))
+    if (DiagTool *tool = diagTools->getTool(argv[1]))
       return tool->run(argc - 1, &argv[2], llvm::errs());
 
   llvm::errs() << "usage: diagtool <command> [<args>]\n\n";
-  diagTools.printCommands(llvm::errs());
+  diagTools->printCommands(llvm::errs());
   return 1;    
 }