forked from OSchip/llvm-project
Use create methods since msvc doesn't handle delegating constructors.
llvm-svn: 209076
This commit is contained in:
parent
77bbb54fbf
commit
f1bedd3747
|
@ -33,29 +33,37 @@ class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
|
||||||
|
|
||||||
void setParent(Module *parent);
|
void setParent(Module *parent);
|
||||||
|
|
||||||
|
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
||||||
|
const Twine &Name, GlobalObject *Aliasee, Module *Parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// allocate space for exactly one operand
|
// allocate space for exactly one operand
|
||||||
void *operator new(size_t s) {
|
void *operator new(size_t s) {
|
||||||
return User::operator new(s, 1);
|
return User::operator new(s, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If a parent module is specified, the alias is automatically inserted into
|
/// If a parent module is specified, the alias is automatically inserted into
|
||||||
/// the end of the specified module's alias list.
|
/// the end of the specified module's alias list.
|
||||||
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
||||||
const Twine &Name, GlobalObject *Aliasee, Module *Parent);
|
LinkageTypes Linkage, const Twine &Name,
|
||||||
|
GlobalObject *Aliasee, Module *Parent);
|
||||||
|
|
||||||
// Without the Aliasee.
|
// Without the Aliasee.
|
||||||
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
||||||
const Twine &Name, Module *Parent);
|
LinkageTypes Linkage, const Twine &Name,
|
||||||
|
Module *Parent);
|
||||||
|
|
||||||
// The module is taken from the Aliasee.
|
// The module is taken from the Aliasee.
|
||||||
GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
|
||||||
const Twine &Name, GlobalObject *Aliasee);
|
LinkageTypes Linkage, const Twine &Name,
|
||||||
|
GlobalObject *Aliasee);
|
||||||
|
|
||||||
// Type, Parent and AddressSpace taken from the Aliasee.
|
// Type, Parent and AddressSpace taken from the Aliasee.
|
||||||
GlobalAlias(LinkageTypes Linkage, const Twine &Name, GlobalObject *Aliasee);
|
static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
|
||||||
|
GlobalObject *Aliasee);
|
||||||
|
|
||||||
// Linkage, Type, Parent and AddressSpace taken from the Aliasee.
|
// Linkage, Type, Parent and AddressSpace taken from the Aliasee.
|
||||||
GlobalAlias(const Twine &Name, GlobalObject *Aliasee);
|
static GlobalAlias *create(const Twine &Name, GlobalObject *Aliasee);
|
||||||
|
|
||||||
/// Provide fast operand accessors
|
/// Provide fast operand accessors
|
||||||
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
|
||||||
|
|
|
@ -697,8 +697,8 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
|
||||||
|
|
||||||
// Okay, create the alias but do not insert it into the module yet.
|
// Okay, create the alias but do not insert it into the module yet.
|
||||||
std::unique_ptr<GlobalAlias> GA(
|
std::unique_ptr<GlobalAlias> GA(
|
||||||
new GlobalAlias(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage, Name,
|
GlobalAlias::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage,
|
||||||
Aliasee, /*Parent*/ nullptr));
|
Name, Aliasee, /*Parent*/ nullptr));
|
||||||
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
|
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
|
||||||
GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
|
GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
|
||||||
|
|
||||||
|
|
|
@ -2004,7 +2004,7 @@ error_code BitcodeReader::ParseModule(bool Resume) {
|
||||||
return Error(InvalidTypeForValue);
|
return Error(InvalidTypeForValue);
|
||||||
|
|
||||||
auto *NewGA =
|
auto *NewGA =
|
||||||
new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
|
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
||||||
GetDecodedLinkage(Record[2]), "", TheModule);
|
GetDecodedLinkage(Record[2]), "", TheModule);
|
||||||
// Old bitcode files didn't have visibility field.
|
// Old bitcode files didn't have visibility field.
|
||||||
// Local linkage must have default visibility.
|
// Local linkage must have default visibility.
|
||||||
|
|
|
@ -1489,7 +1489,7 @@ void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) {
|
||||||
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
|
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
|
||||||
const char *Name) {
|
const char *Name) {
|
||||||
auto *PTy = cast<PointerType>(unwrap(Ty));
|
auto *PTy = cast<PointerType>(unwrap(Ty));
|
||||||
return wrap(new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
|
return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
||||||
GlobalValue::ExternalLinkage, Name,
|
GlobalValue::ExternalLinkage, Name,
|
||||||
unwrap<GlobalObject>(Aliasee), unwrap(M)));
|
unwrap<GlobalObject>(Aliasee), unwrap(M)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,22 +225,34 @@ GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
|
||||||
ParentModule->getAliasList().push_back(this);
|
ParentModule->getAliasList().push_back(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
|
||||||
const Twine &Name, Module *Parent)
|
LinkageTypes Link, const Twine &Name,
|
||||||
: GlobalAlias(Ty, AddressSpace, Linkage, Name, nullptr, Parent) {}
|
GlobalObject *Aliasee, Module *ParentModule) {
|
||||||
|
return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
|
||||||
|
}
|
||||||
|
|
||||||
GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
|
GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
|
||||||
const Twine &Name, GlobalObject *Aliasee)
|
LinkageTypes Linkage, const Twine &Name,
|
||||||
: GlobalAlias(Ty, AddressSpace, Linkage, Name, Aliasee,
|
Module *Parent) {
|
||||||
Aliasee->getParent()) {}
|
return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
|
||||||
|
}
|
||||||
|
|
||||||
GlobalAlias::GlobalAlias(LinkageTypes Link, const Twine &Name,
|
GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
|
||||||
GlobalObject *Aliasee)
|
LinkageTypes Linkage, const Twine &Name,
|
||||||
: GlobalAlias(Aliasee->getType()->getElementType(),
|
GlobalObject *Aliasee) {
|
||||||
Aliasee->getType()->getAddressSpace(), Link, Name, Aliasee) {}
|
return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
|
||||||
|
}
|
||||||
|
|
||||||
GlobalAlias::GlobalAlias(const Twine &Name, GlobalObject *Aliasee)
|
GlobalAlias *GlobalAlias::create(LinkageTypes Link, const Twine &Name,
|
||||||
: GlobalAlias(Aliasee->getLinkage(), Name, Aliasee) {}
|
GlobalObject *Aliasee) {
|
||||||
|
PointerType *PTy = Aliasee->getType();
|
||||||
|
return create(PTy->getElementType(), PTy->getAddressSpace(), Link, Name,
|
||||||
|
Aliasee);
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalAlias *GlobalAlias::create(const Twine &Name, GlobalObject *Aliasee) {
|
||||||
|
return create(Aliasee->getLinkage(), Name, Aliasee);
|
||||||
|
}
|
||||||
|
|
||||||
void GlobalAlias::setParent(Module *parent) {
|
void GlobalAlias::setParent(Module *parent) {
|
||||||
if (getParent())
|
if (getParent())
|
||||||
|
|
|
@ -922,7 +922,8 @@ bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) {
|
||||||
// If there is no linkage to be performed or we're linking from the source,
|
// If there is no linkage to be performed or we're linking from the source,
|
||||||
// bring over SGA.
|
// bring over SGA.
|
||||||
auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType()));
|
auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType()));
|
||||||
auto *NewDA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
|
auto *NewDA =
|
||||||
|
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
||||||
SGA->getLinkage(), SGA->getName(), DstM);
|
SGA->getLinkage(), SGA->getName(), DstM);
|
||||||
copyGVAttributes(NewDA, SGA);
|
copyGVAttributes(NewDA, SGA);
|
||||||
if (NewVisibility)
|
if (NewVisibility)
|
||||||
|
|
|
@ -1328,7 +1328,7 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
|
||||||
// Replace G with an alias to F and delete G.
|
// Replace G with an alias to F and delete G.
|
||||||
void MergeFunctions::writeAlias(Function *F, Function *G) {
|
void MergeFunctions::writeAlias(Function *F, Function *G) {
|
||||||
PointerType *PTy = G->getType();
|
PointerType *PTy = G->getType();
|
||||||
auto *GA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
|
auto *GA = GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
||||||
G->getLinkage(), "", F);
|
G->getLinkage(), "", F);
|
||||||
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
|
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
|
||||||
GA->takeName(G);
|
GA->takeName(G);
|
||||||
|
|
|
@ -68,7 +68,8 @@ Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) {
|
||||||
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
|
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
auto *PTy = cast<PointerType>(I->getType());
|
auto *PTy = cast<PointerType>(I->getType());
|
||||||
auto *GA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
|
auto *GA =
|
||||||
|
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
|
||||||
I->getLinkage(), I->getName(), New);
|
I->getLinkage(), I->getName(), New);
|
||||||
GA->copyAttributesFrom(I);
|
GA->copyAttributesFrom(I);
|
||||||
VMap[I] = GA;
|
VMap[I] = GA;
|
||||||
|
|
|
@ -274,7 +274,7 @@ TEST(ConstantsTest, ReplaceInAliasTest) {
|
||||||
|
|
||||||
Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
|
Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
|
||||||
auto *Global = cast<GlobalObject>(M->getOrInsertGlobal("dummy", Int32Ty));
|
auto *Global = cast<GlobalObject>(M->getOrInsertGlobal("dummy", Int32Ty));
|
||||||
auto *GA = new GlobalAlias(GlobalValue::ExternalLinkage, "alias", Global);
|
auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "alias", Global);
|
||||||
EXPECT_DEATH(Global->replaceAllUsesWith(GA),
|
EXPECT_DEATH(Global->replaceAllUsesWith(GA),
|
||||||
"replaceAliasUseWith cannot form an alias cycle");
|
"replaceAliasUseWith cannot form an alias cycle");
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ TEST(VerifierTest, AliasUnnamedAddr) {
|
||||||
GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true,
|
GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true,
|
||||||
GlobalValue::ExternalLinkage,
|
GlobalValue::ExternalLinkage,
|
||||||
Init, "foo");
|
Init, "foo");
|
||||||
auto *GA = new GlobalAlias(GlobalValue::ExternalLinkage, "bar", Aliasee);
|
auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "bar", Aliasee);
|
||||||
GA->setUnnamedAddr(true);
|
GA->setUnnamedAddr(true);
|
||||||
std::string Error;
|
std::string Error;
|
||||||
raw_string_ostream ErrorOS(Error);
|
raw_string_ostream ErrorOS(Error);
|
||||||
|
|
|
@ -35,7 +35,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalAlias *makeAlias(StringRef Name, GlobalObject *Aliasee) {
|
GlobalAlias *makeAlias(StringRef Name, GlobalObject *Aliasee) {
|
||||||
return new GlobalAlias(GlobalValue::ExternalLinkage, Name, Aliasee);
|
return GlobalAlias::create(GlobalValue::ExternalLinkage, Name, Aliasee);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) {
|
SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) {
|
||||||
|
|
Loading…
Reference in New Issue