Change the GlobalAlias constructor to look a bit more like GlobalVariable.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 16 May 2014 13:34:04 +0000 (13:34 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 16 May 2014 13:34:04 +0000 (13:34 +0000)
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

include/llvm/IR/GlobalAlias.h
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/IR/Core.cpp
lib/IR/Globals.cpp
lib/Linker/LinkModules.cpp
lib/Transforms/IPO/MergeFunctions.cpp
lib/Transforms/Utils/CloneModule.cpp
unittests/IR/VerifierTest.cpp
unittests/Transforms/Utils/SpecialCaseList.cpp

index 5aa42612562697914034328e05dee85c88d2ccbc..da228471c91443a65b3f9480b17b0a6a15a3fee1 100644 (file)
@@ -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);
index d0b380066c52796accdb756bd697be980c222082..e5813f0d210a73db75d012c31e95d16e0e8a2422 100644 (file)
@@ -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);
 
index d0ce237ee67e639005c60db10537c4e599a09180..a1ae6baff9fc8be42b02641263152229ed6ebc7f 100644 (file)
@@ -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())
index 81d137edfe05faf63a300f3ce79359496c8fb3ee..40c1c70257e140462a53929199ed2527b9d43f78 100644 (file)
@@ -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 .............................................--*/
index 0ec54fe3c0819dbbbeda900295cd9b1b83fca84a..8e7478496f07ab6fb41b3b215d05f7712068812c 100644 (file)
@@ -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);
index 820f3acaceff0827be823bd09944166abc6be5c4..0507c5acc9cc9cebad7ccfb2a7f247e2c95e7bc3 100644 (file)
@@ -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);
index 59b6c22aa46e6dd821861d67fdb90f29cd50f5af..a8106e0c32f48190382334d206b4ba12d15b48a1 100644 (file)
@@ -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());
index 5d180a5478c5e5f02d6a7effdabcbe777b118d68..1a3641452d9e498ca8e2fb85989f044407798722 100644 (file)
@@ -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;
   }
index 0a660a6b9135edd2180399952f0238c04fcef0be..92f25b3e37aa388e4745d2e0bef92f2cb5f0a669 100644 (file)
@@ -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);
index 748834f85e0cd2dafc599b3c237900ad1330e574..6863ea5a6012f673afb19d57ffff8be2d595f6d1 100644 (file)
@@ -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) {