llvm.org GIT mirror llvm / ab67b30
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 Rafael Espindola 5 years ago
10 changed file(s) with 42 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
3737 void *operator new(size_t s) {
3838 return User::operator new(s, 1);
3939 }
40 /// GlobalAlias ctor - If a parent module is specified, the alias is
41 /// automatically inserted into the end of the specified module's alias list.
40 /// If a parent module is specified, the alias is automatically inserted into
41 /// the end of the specified module's alias list.
4242 GlobalAlias(Type *Ty, LinkageTypes Linkage, const Twine &Name = "",
43 Constant* Aliasee = nullptr, Module *Parent = nullptr);
43 Constant* Aliasee = nullptr, Module *Parent = nullptr,
44 unsigned AddressSpace = 0);
4445
4546 /// Provide fast operand accessors
4647 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
672672 return Error(AliaseeLoc, "alias must have pointer type");
673673
674674 // Okay, create the alias but do not insert it into the module yet.
675 std::unique_ptr GA(new GlobalAlias(
676 Aliasee->getType(), (GlobalValue::LinkageTypes)Linkage, Name, Aliasee));
675 PointerType *PTy = cast(Aliasee->getType());
676 std::unique_ptr GA(
677 new GlobalAlias(PTy->getElementType(), (GlobalValue::LinkageTypes)Linkage,
678 Name, Aliasee, nullptr, PTy->getAddressSpace()));
677679 GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
678680 GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
679681
19651965 if (!Ty->isPointerTy())
19661966 return Error(InvalidTypeForValue);
19671967
1968 GlobalAlias *NewGA = new GlobalAlias(Ty, GetDecodedLinkage(Record[2]),
1969 "", nullptr, TheModule);
1968 auto *PTy = cast(Ty);
1969 GlobalAlias *NewGA =
1970 new GlobalAlias(PTy->getElementType(), GetDecodedLinkage(Record[2]),
1971 "", nullptr, TheModule, PTy->getAddressSpace());
19701972 // Old bitcode files didn't have visibility field.
19711973 // Local linkage must have default visibility.
19721974 if (Record.size() > 3 && !NewGA->hasLocalLinkage())
14871487
14881488 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
14891489 const char *Name) {
1490 return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name,
1491 unwrap(Aliasee), unwrap (M)));
1490 auto *PTy = cast(unwrap(Ty));
1491 return wrap(new GlobalAlias(
1492 PTy->getElementType(), GlobalValue::ExternalLinkage, Name,
1493 unwrap(Aliasee), unwrap(M), PTy->getAddressSpace()));
14921494 }
14931495
14941496 /*--.. Operations on functions .............................................--*/
212212 // GlobalAlias Implementation
213213 //===----------------------------------------------------------------------===//
214214
215 GlobalAlias::GlobalAlias(Type *Ty, LinkageTypes Link,
216 const Twine &Name, Constant* aliasee,
217 Module *ParentModule)
218 : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name) {
215 GlobalAlias::GlobalAlias(Type *Ty, LinkageTypes Link, const Twine &Name,
216 Constant *Aliasee, Module *ParentModule,
217 unsigned AddressSpace)
218 : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalAliasVal,
219 &Op<0>(), 1, Link, Name) {
219220 LeakDetector::addGarbageObject(this);
220221
221 if (aliasee)
222 assert(aliasee->getType() == Ty && "Alias and aliasee types should match!");
223 Op<0>() = aliasee;
222 if (Aliasee)
223 assert(Aliasee->getType() == getType() &&
224 "Alias and aliasee types should match!");
225 Op<0>() = Aliasee;
224226
225227 if (ParentModule)
226228 ParentModule->getAliasList().push_back(this);
918918
919919 // If there is no linkage to be performed or we're linking from the source,
920920 // bring over SGA.
921 GlobalAlias *NewDA = new GlobalAlias(TypeMap.get(SGA->getType()),
922 SGA->getLinkage(), SGA->getName(),
923 /*aliasee*/nullptr, DstM);
921 auto *PTy = cast(TypeMap.get(SGA->getType()));
922 GlobalAlias *NewDA =
923 new GlobalAlias(PTy->getElementType(), SGA->getLinkage(), SGA->getName(),
924 /*aliasee*/ nullptr, DstM, PTy->getAddressSpace());
924925 copyGVAttributes(NewDA, SGA);
925926 if (NewVisibility)
926927 NewDA->setVisibility(*NewVisibility);
13271327 // Replace G with an alias to F and delete G.
13281328 void MergeFunctions::writeAlias(Function *F, Function *G) {
13291329 Constant *BitcastF = ConstantExpr::getBitCast(F, G->getType());
1330 GlobalAlias *GA = new GlobalAlias(G->getType(), G->getLinkage(), "",
1331 BitcastF, G->getParent());
1330 PointerType *PTy = G->getType();
1331 GlobalAlias *GA =
1332 new GlobalAlias(PTy->getElementType(), G->getLinkage(), "", BitcastF,
1333 G->getParent(), PTy->getAddressSpace());
13321334 F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
13331335 GA->takeName(G);
13341336 GA->setVisibility(G->getVisibility());
6666 // Loop over the aliases in the module
6767 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
6868 I != E; ++I) {
69 GlobalAlias *GA = new GlobalAlias(I->getType(), I->getLinkage(),
70 I->getName(), nullptr, New);
69 auto *PTy = cast(I->getType());
70 auto *GA =
71 new GlobalAlias(PTy->getElementType(), I->getLinkage(), I->getName(),
72 nullptr, New, PTy->getAddressSpace());
7173 GA->copyAttributesFrom(I);
7274 VMap[I] = GA;
7375 }
5151 GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true,
5252 GlobalValue::ExternalLinkage,
5353 Init, "foo");
54 GlobalAlias *GA = new GlobalAlias(Type::getInt8PtrTy(C),
55 GlobalValue::ExternalLinkage,
56 "bar", Aliasee, &M);
54 auto *GA =
55 new GlobalAlias(Ty, GlobalValue::ExternalLinkage, "bar", Aliasee, &M);
5756 GA->setUnnamedAddr(true);
5857 std::string Error;
5958 raw_string_ostream ErrorOS(Error);
3434 }
3535
3636 GlobalAlias *makeAlias(StringRef Name, GlobalValue *Aliasee) {
37 return new GlobalAlias(Aliasee->getType(), GlobalValue::ExternalLinkage,
38 Name, Aliasee, Aliasee->getParent());
37 return new GlobalAlias(Aliasee->getType()->getElementType(),
38 GlobalValue::ExternalLinkage, Name, Aliasee,
39 Aliasee->getParent());
3940 }
4041
4142 SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) {