From 4fe0094fd15c9b94e4940994cced3e23baafdb9b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 16 May 2014 13:34:04 +0000 Subject: 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. llvm-svn: 208983 --- llvm/lib/IR/Core.cpp | 6 ++++-- llvm/lib/IR/Globals.cpp | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'llvm/lib/IR') diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 81d137edfe0..40c1c70257e 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/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(Aliasee), unwrap (M))); + auto *PTy = cast(unwrap(Ty)); + return wrap(new GlobalAlias( + PTy->getElementType(), GlobalValue::ExternalLinkage, Name, + unwrap(Aliasee), unwrap(M), PTy->getAddressSpace())); } /*--.. Operations on functions .............................................--*/ diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 0ec54fe3c08..8e7478496f0 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/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); -- cgit v1.2.3