diff options
-rw-r--r-- | include/llvm/IR/GlobalAlias.h | 7 | ||||
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 6 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 6 | ||||
-rw-r--r-- | lib/IR/Core.cpp | 6 | ||||
-rw-r--r-- | lib/IR/Globals.cpp | 16 | ||||
-rw-r--r-- | lib/Linker/LinkModules.cpp | 7 | ||||
-rw-r--r-- | lib/Transforms/IPO/MergeFunctions.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/Utils/CloneModule.cpp | 6 | ||||
-rw-r--r-- | unittests/IR/VerifierTest.cpp | 5 | ||||
-rw-r--r-- | unittests/Transforms/Utils/SpecialCaseList.cpp | 5 |
10 files changed, 42 insertions, 28 deletions
diff --git a/include/llvm/IR/GlobalAlias.h b/include/llvm/IR/GlobalAlias.h index 5aa4261256..da228471c9 100644 --- a/include/llvm/IR/GlobalAlias.h +++ b/include/llvm/IR/GlobalAlias.h @@ -38,10 +38,11 @@ public: void *operator new(size_t s) { return User::operator new(s, 1); } - /// GlobalAlias ctor - If a parent module is specified, the alias is - /// automatically inserted into the end of the specified module's alias list. + /// If a parent module is specified, the alias is automatically inserted into + /// the end of the specified module's alias list. GlobalAlias(Type *Ty, LinkageTypes Linkage, const Twine &Name = "", - Constant* Aliasee = nullptr, Module *Parent = nullptr); + Constant* Aliasee = nullptr, Module *Parent = nullptr, + unsigned AddressSpace = 0); /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index d0b380066c..e5813f0d21 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -673,8 +673,10 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc, return Error(AliaseeLoc, "alias must have pointer type"); // Okay, create the alias but do not insert it into the module yet. - std::unique_ptr<GlobalAlias> GA(new GlobalAlias( - Aliasee->getType(), (GlobalValue::LinkageTypes)Linkage, Name, Aliasee)); + PointerType *PTy = cast<PointerType>(Aliasee->getType()); + std::unique_ptr<GlobalAlias> GA( + new GlobalAlias(PTy->getElementType(), (GlobalValue::LinkageTypes)Linkage, + Name, Aliasee, nullptr, PTy->getAddressSpace())); GA->setVisibility((GlobalValue::VisibilityTypes)Visibility); GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index d0ce237ee6..a1ae6baff9 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1966,8 +1966,10 @@ error_code BitcodeReader::ParseModule(bool Resume) { if (!Ty->isPointerTy()) return Error(InvalidTypeForValue); - GlobalAlias *NewGA = new GlobalAlias(Ty, GetDecodedLinkage(Record[2]), - "", nullptr, TheModule); + auto *PTy = cast<PointerType>(Ty); + GlobalAlias *NewGA = + new GlobalAlias(PTy->getElementType(), GetDecodedLinkage(Record[2]), + "", nullptr, TheModule, PTy->getAddressSpace()); // Old bitcode files didn't have visibility field. // Local linkage must have default visibility. if (Record.size() > 3 && !NewGA->hasLocalLinkage()) diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 81d137edfe..40c1c70257 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1488,8 +1488,10 @@ void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) { LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name) { - return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name, - unwrap<Constant>(Aliasee), unwrap (M))); + auto *PTy = cast<PointerType>(unwrap(Ty)); + return wrap(new GlobalAlias( + PTy->getElementType(), GlobalValue::ExternalLinkage, Name, + unwrap<Constant>(Aliasee), unwrap(M), PTy->getAddressSpace())); } /*--.. Operations on functions .............................................--*/ diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index 0ec54fe3c0..8e7478496f 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -213,15 +213,17 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) { // GlobalAlias Implementation //===----------------------------------------------------------------------===// -GlobalAlias::GlobalAlias(Type *Ty, LinkageTypes Link, - const Twine &Name, Constant* aliasee, - Module *ParentModule) - : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name) { +GlobalAlias::GlobalAlias(Type *Ty, LinkageTypes Link, const Twine &Name, + Constant *Aliasee, Module *ParentModule, + unsigned AddressSpace) + : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalAliasVal, + &Op<0>(), 1, Link, Name) { LeakDetector::addGarbageObject(this); - if (aliasee) - assert(aliasee->getType() == Ty && "Alias and aliasee types should match!"); - Op<0>() = aliasee; + if (Aliasee) + assert(Aliasee->getType() == getType() && + "Alias and aliasee types should match!"); + Op<0>() = Aliasee; if (ParentModule) ParentModule->getAliasList().push_back(this); diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 820f3acace..0507c5acc9 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -919,9 +919,10 @@ bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) { // If there is no linkage to be performed or we're linking from the source, // bring over SGA. - GlobalAlias *NewDA = new GlobalAlias(TypeMap.get(SGA->getType()), - SGA->getLinkage(), SGA->getName(), - /*aliasee*/nullptr, DstM); + auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType())); + GlobalAlias *NewDA = + new GlobalAlias(PTy->getElementType(), SGA->getLinkage(), SGA->getName(), + /*aliasee*/ nullptr, DstM, PTy->getAddressSpace()); copyGVAttributes(NewDA, SGA); if (NewVisibility) NewDA->setVisibility(*NewVisibility); diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index 59b6c22aa4..a8106e0c32 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -1328,8 +1328,10 @@ void MergeFunctions::writeThunk(Function *F, Function *G) { // Replace G with an alias to F and delete G. void MergeFunctions::writeAlias(Function *F, Function *G) { Constant *BitcastF = ConstantExpr::getBitCast(F, G->getType()); - GlobalAlias *GA = new GlobalAlias(G->getType(), G->getLinkage(), "", - BitcastF, G->getParent()); + PointerType *PTy = G->getType(); + GlobalAlias *GA = + new GlobalAlias(PTy->getElementType(), G->getLinkage(), "", BitcastF, + G->getParent(), PTy->getAddressSpace()); F->setAlignment(std::max(F->getAlignment(), G->getAlignment())); GA->takeName(G); GA->setVisibility(G->getVisibility()); diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index 5d180a5478..1a3641452d 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -67,8 +67,10 @@ Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) { // Loop over the aliases in the module for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); I != E; ++I) { - GlobalAlias *GA = new GlobalAlias(I->getType(), I->getLinkage(), - I->getName(), nullptr, New); + auto *PTy = cast<PointerType>(I->getType()); + auto *GA = + new GlobalAlias(PTy->getElementType(), I->getLinkage(), I->getName(), + nullptr, New, PTy->getAddressSpace()); GA->copyAttributesFrom(I); VMap[I] = GA; } diff --git a/unittests/IR/VerifierTest.cpp b/unittests/IR/VerifierTest.cpp index 0a660a6b91..92f25b3e37 100644 --- a/unittests/IR/VerifierTest.cpp +++ b/unittests/IR/VerifierTest.cpp @@ -52,9 +52,8 @@ TEST(VerifierTest, AliasUnnamedAddr) { GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true, GlobalValue::ExternalLinkage, Init, "foo"); - GlobalAlias *GA = new GlobalAlias(Type::getInt8PtrTy(C), - GlobalValue::ExternalLinkage, - "bar", Aliasee, &M); + auto *GA = + new GlobalAlias(Ty, GlobalValue::ExternalLinkage, "bar", Aliasee, &M); GA->setUnnamedAddr(true); std::string Error; raw_string_ostream ErrorOS(Error); diff --git a/unittests/Transforms/Utils/SpecialCaseList.cpp b/unittests/Transforms/Utils/SpecialCaseList.cpp index 748834f85e..6863ea5a60 100644 --- a/unittests/Transforms/Utils/SpecialCaseList.cpp +++ b/unittests/Transforms/Utils/SpecialCaseList.cpp @@ -35,8 +35,9 @@ protected: } GlobalAlias *makeAlias(StringRef Name, GlobalValue *Aliasee) { - return new GlobalAlias(Aliasee->getType(), GlobalValue::ExternalLinkage, - Name, Aliasee, Aliasee->getParent()); + return new GlobalAlias(Aliasee->getType()->getElementType(), + GlobalValue::ExternalLinkage, Name, Aliasee, + Aliasee->getParent()); } SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) { |