[llvm] r270381 - [Kaleidoscope] Fix static global ordering to prevent crash on exit.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun May 22 15:48:39 PDT 2016


Author: lhames
Date: Sun May 22 17:48:36 2016
New Revision: 270381

URL: http://llvm.org/viewvc/llvm-project?rev=270381&view=rev
Log:
[Kaleidoscope] Fix static global ordering to prevent crash on exit.

If TheModule is declared before LLVMContext then it will be destructed after it,
crashing when it tries to deregister itself from the destructed context.

Modified:
    llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp

Modified: llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp?rev=270381&r1=270380&r2=270381&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp Sun May 22 17:48:36 2016
@@ -388,9 +388,9 @@ static std::unique_ptr<PrototypeAST> Par
 // Code Generation
 //===----------------------------------------------------------------------===//
 
-static std::unique_ptr<Module> TheModule;
 static LLVMContext TheContext;
 static IRBuilder<> Builder(TheContext);
+static std::unique_ptr<Module> TheModule;
 static std::map<std::string, Value *> NamedValues;
 
 Value *LogErrorV(const char *Str) {

Modified: llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp?rev=270381&r1=270380&r2=270381&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp Sun May 22 17:48:36 2016
@@ -397,9 +397,9 @@ static std::unique_ptr<PrototypeAST> Par
 // Code Generation
 //===----------------------------------------------------------------------===//
 
-static std::unique_ptr<Module> TheModule;
 static LLVMContext TheContext;
 static IRBuilder<> Builder(TheContext);
+static std::unique_ptr<Module> TheModule;
 static std::map<std::string, Value *> NamedValues;
 static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
 static std::unique_ptr<KaleidoscopeJIT> TheJIT;

Modified: llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp?rev=270381&r1=270380&r2=270381&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp Sun May 22 17:48:36 2016
@@ -522,9 +522,9 @@ static std::unique_ptr<PrototypeAST> Par
 // Code Generation
 //===----------------------------------------------------------------------===//
 
-static std::unique_ptr<Module> TheModule;
 static LLVMContext TheContext;
 static IRBuilder<> Builder(TheContext);
+static std::unique_ptr<Module> TheModule;
 static std::map<std::string, Value *> NamedValues;
 static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
 static std::unique_ptr<KaleidoscopeJIT> TheJIT;

Modified: llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp?rev=270381&r1=270380&r2=270381&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp Sun May 22 17:48:36 2016
@@ -613,9 +613,9 @@ static std::unique_ptr<PrototypeAST> Par
 // Code Generation
 //===----------------------------------------------------------------------===//
 
-static std::unique_ptr<Module> TheModule;
 static LLVMContext TheContext;
 static IRBuilder<> Builder(TheContext);
+static std::unique_ptr<Module> TheModule;
 static std::map<std::string, Value *> NamedValues;
 static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
 static std::unique_ptr<KaleidoscopeJIT> TheJIT;

Modified: llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp?rev=270381&r1=270380&r2=270381&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp Sun May 22 17:48:36 2016
@@ -684,9 +684,9 @@ static std::unique_ptr<PrototypeAST> Par
 // Code Generation
 //===----------------------------------------------------------------------===//
 
-static std::unique_ptr<Module> TheModule;
 static LLVMContext TheContext;
 static IRBuilder<> Builder(TheContext);
+static std::unique_ptr<Module> TheModule;
 static std::map<std::string, AllocaInst *> NamedValues;
 static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
 static std::unique_ptr<KaleidoscopeJIT> TheJIT;




More information about the llvm-commits mailing list