diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Core.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/Globals.cpp | 13 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 10 |
3 files changed, 18 insertions, 8 deletions
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index efc229d6f5..1ac66ed660 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -700,7 +700,8 @@ void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) { /*--.. Operations on global variables ......................................--*/ LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) { - return wrap(new GlobalVariable(unwrap(Ty), false, + LLVMContext &Context = unwrap(M)->getContext(); + return wrap(new GlobalVariable(Context, unwrap(Ty), false, GlobalValue::ExternalLinkage, 0, Name, unwrap(M))); } diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index 5abe1f9ac4..c31b7b5e76 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -16,6 +16,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/GlobalAlias.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/LeakDetector.h" @@ -93,11 +94,13 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) { // GlobalVariable Implementation //===----------------------------------------------------------------------===// -GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link, +GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, + bool constant, LinkageTypes Link, Constant *InitVal, const std::string &Name, Module *ParentModule, bool ThreadLocal, unsigned AddressSpace) - : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal, + : GlobalValue(Context.getPointerType(Ty, AddressSpace), + Value::GlobalVariableVal, OperandTraits<GlobalVariable>::op_begin(this), InitVal != 0, Link, Name), isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) { @@ -113,11 +116,13 @@ GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link, ParentModule->getGlobalList().push_back(this); } -GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link, +GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty, + bool constant, LinkageTypes Link, Constant *InitVal, const std::string &Name, GlobalVariable *Before, bool ThreadLocal, unsigned AddressSpace) - : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal, + : GlobalValue(Context.getPointerType(Ty, AddressSpace), + Value::GlobalVariableVal, OperandTraits<GlobalVariable>::op_begin(this), InitVal != 0, Link, Name), isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) { diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index f057e81a64..6f3de0257e 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -28,17 +28,20 @@ using namespace llvm; //===----------------------------------------------------------------------===// // Methods to implement the globals and functions lists. +// NOTE: It is ok to allocate the globals used for these methods from the +// global context, because all we ever do is use them to compare for equality. // GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() { - GlobalVariable *Ret = new GlobalVariable(Type::Int32Ty, false, + GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), + Type::Int32Ty, false, GlobalValue::ExternalLinkage); // This should not be garbage monitored. LeakDetector::removeGarbageObject(Ret); return Ret; } GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() { - GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, + GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, GlobalValue::ExternalLinkage); // This should not be garbage monitored. LeakDetector::removeGarbageObject(Ret); @@ -270,7 +273,8 @@ Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) { if (GV == 0) { // Nope, add it GlobalVariable *New = - new GlobalVariable(Ty, false, GlobalVariable::ExternalLinkage, 0, Name); + new GlobalVariable(getContext(), Ty, false, + GlobalVariable::ExternalLinkage, 0, Name); GlobalList.push_back(New); return New; // Return the new declaration. } |