summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-05-16 13:34:04 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-05-16 13:34:04 +0000
commitab67b30df6b14e8e90f4778215ed4e1d5939638e (patch)
tree0dd738ae6d07cd9fac9f37bc7f34dbea1d7014c1 /lib
parentb95580a711b70e373ba7a52b3867e7ea6881e413 (diff)
downloadllvm-ab67b30df6b14e8e90f4778215ed4e1d5939638e.tar.gz
llvm-ab67b30df6b14e8e90f4778215ed4e1d5939638e.tar.bz2
llvm-ab67b30df6b14e8e90f4778215ed4e1d5939638e.tar.xz
Change the GlobalAlias constructor to look a bit more like GlobalVariable.
This is part of the fix for pr10367. A GlobalAlias always has a pointer type, so just have the constructor build the type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208983 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AsmParser/LLParser.cpp6
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp6
-rw-r--r--lib/IR/Core.cpp6
-rw-r--r--lib/IR/Globals.cpp16
-rw-r--r--lib/Linker/LinkModules.cpp7
-rw-r--r--lib/Transforms/IPO/MergeFunctions.cpp6
-rw-r--r--lib/Transforms/Utils/CloneModule.cpp6
7 files changed, 33 insertions, 20 deletions
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;
}