[llvm] r208983 - Change the GlobalAlias constructor to look a bit more like GlobalVariable.
Rafael Espindola
rafael.espindola at gmail.com
Fri May 16 06:34:04 PDT 2014
Author: rafael
Date: Fri May 16 08:34:04 2014
New Revision: 208983
URL: http://llvm.org/viewvc/llvm-project?rev=208983&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/IR/GlobalAlias.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
llvm/trunk/unittests/IR/VerifierTest.cpp
llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp
Modified: llvm/trunk/include/llvm/IR/GlobalAlias.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalAlias.h?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalAlias.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalAlias.h Fri May 16 08:34:04 2014
@@ -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);
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Fri May 16 08:34:04 2014
@@ -673,8 +673,10 @@ bool LLParser::ParseAlias(const std::str
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);
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri May 16 08:34:04 2014
@@ -1966,8 +1966,10 @@ error_code BitcodeReader::ParseModule(bo
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())
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Fri May 16 08:34:04 2014
@@ -1488,8 +1488,10 @@ void LLVMSetExternallyInitialized(LLVMVa
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 .............................................--*/
Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Fri May 16 08:34:04 2014
@@ -213,15 +213,17 @@ void GlobalVariable::copyAttributesFrom(
// 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);
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri May 16 08:34:04 2014
@@ -919,9 +919,10 @@ bool ModuleLinker::linkAliasProto(Global
// 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);
Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Fri May 16 08:34:04 2014
@@ -1328,8 +1328,10 @@ void MergeFunctions::writeThunk(Function
// 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());
Modified: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneModule.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Fri May 16 08:34:04 2014
@@ -67,8 +67,10 @@ Module *llvm::CloneModule(const Module *
// 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;
}
Modified: llvm/trunk/unittests/IR/VerifierTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/VerifierTest.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/VerifierTest.cpp (original)
+++ llvm/trunk/unittests/IR/VerifierTest.cpp Fri May 16 08:34:04 2014
@@ -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);
Modified: llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp?rev=208983&r1=208982&r2=208983&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp Fri May 16 08:34:04 2014
@@ -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) {
More information about the llvm-commits
mailing list