Use create methods since msvc doesn't handle delegating constructors.
authorRafael Espindola <rafael.espindola@gmail.com>
Sat, 17 May 2014 21:29:57 +0000 (21:29 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sat, 17 May 2014 21:29:57 +0000 (21:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209076 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/ConstantsTest.cpp
unittests/IR/VerifierTest.cpp
unittests/Transforms/Utils/SpecialCaseList.cpp

index f5181ab6aaf6313ff0a88ba0280bea43c0be3105..d9f0b4a89b838b25f48354b05c7db50642d3a5cc 100644 (file)
@@ -33,29 +33,37 @@ class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
 
   void setParent(Module *parent);
 
+  GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
+              const Twine &Name, GlobalObject *Aliasee, Module *Parent);
+
 public:
   // allocate space for exactly one operand
   void *operator new(size_t s) {
     return User::operator new(s, 1);
   }
+
   /// If a parent module is specified, the alias is automatically inserted into
   /// the end of the specified module's alias list.
-  GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
-              const Twine &Name, GlobalObject *Aliasee, Module *Parent);
+  static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
+                             LinkageTypes Linkage, const Twine &Name,
+                             GlobalObject *Aliasee, Module *Parent);
 
   // Without the Aliasee.
-  GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
-              const Twine &Name, Module *Parent);
+  static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
+                             LinkageTypes Linkage, const Twine &Name,
+                             Module *Parent);
 
   // The module is taken from the Aliasee.
-  GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
-              const Twine &Name, GlobalObject *Aliasee);
+  static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
+                             LinkageTypes Linkage, const Twine &Name,
+                             GlobalObject *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.
-  GlobalAlias(const Twine &Name, GlobalObject *Aliasee);
+  static GlobalAlias *create(const Twine &Name, GlobalObject *Aliasee);
 
   /// Provide fast operand accessors
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
index b463d49af52b6c285748dbf1a49ecef4188b787c..4c020c1bfc87c6726aeb5a9c294aa0b7a4407ee7 100644 (file)
@@ -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.
   std::unique_ptr<GlobalAlias> GA(
-      new GlobalAlias(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage, Name,
-                      Aliasee, /*Parent*/ nullptr));
+      GlobalAlias::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage,
+                          Name, Aliasee, /*Parent*/ nullptr));
   GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
   GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
 
index 478103f982f539e841dac701c4ae6c7a999aedb8..fe5d57262ef1c6d4aacc7ace91f859fb0c6fd9f3 100644 (file)
@@ -2004,8 +2004,8 @@ error_code BitcodeReader::ParseModule(bool Resume) {
         return Error(InvalidTypeForValue);
 
       auto *NewGA =
-          new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
-                          GetDecodedLinkage(Record[2]), "", TheModule);
+          GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
+                              GetDecodedLinkage(Record[2]), "", TheModule);
       // Old bitcode files didn't have visibility field.
       // Local linkage must have default visibility.
       if (Record.size() > 3 && !NewGA->hasLocalLinkage())
index dc3d6f34c883871f82bc99c809d68f82c11e27f8..27ce503e1c34ee674a078b3708ef1fc6f165d1b8 100644 (file)
@@ -1489,9 +1489,9 @@ void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) {
 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
                           const char *Name) {
   auto *PTy = cast<PointerType>(unwrap(Ty));
-  return wrap(new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
-                              GlobalValue::ExternalLinkage, Name,
-                              unwrap<GlobalObject>(Aliasee), unwrap(M)));
+  return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
+                                  GlobalValue::ExternalLinkage, Name,
+                                  unwrap<GlobalObject>(Aliasee), unwrap(M)));
 }
 
 /*--.. Operations on functions .............................................--*/
index dae3bad5eaee138b432eb58dd73ffb3f6c39bf42..c905cfe31e2d213fee959961093da69ae2d3187c 100644 (file)
@@ -225,22 +225,34 @@ GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
     ParentModule->getAliasList().push_back(this);
 }
 
-GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
-                         const Twine &Name, Module *Parent)
-    : GlobalAlias(Ty, AddressSpace, Linkage, Name, nullptr, Parent) {}
-
-GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
-                         const Twine &Name, GlobalObject *Aliasee)
-    : GlobalAlias(Ty, AddressSpace, Linkage, Name, Aliasee,
-                  Aliasee->getParent()) {}
-
-GlobalAlias::GlobalAlias(LinkageTypes Link, const Twine &Name,
-                         GlobalObject *Aliasee)
-    : GlobalAlias(Aliasee->getType()->getElementType(),
-                  Aliasee->getType()->getAddressSpace(), Link, Name, Aliasee) {}
-
-GlobalAlias::GlobalAlias(const Twine &Name, GlobalObject *Aliasee)
-    : GlobalAlias(Aliasee->getLinkage(), Name, Aliasee) {}
+GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
+                                 LinkageTypes Link, const Twine &Name,
+                                 GlobalObject *Aliasee, Module *ParentModule) {
+  return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
+}
+
+GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
+                                 LinkageTypes Linkage, const Twine &Name,
+                                 Module *Parent) {
+  return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
+}
+
+GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
+                                 LinkageTypes Linkage, const Twine &Name,
+                                 GlobalObject *Aliasee) {
+  return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
+}
+
+GlobalAlias *GlobalAlias::create(LinkageTypes Link, const Twine &Name,
+                                 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) {
   if (getParent())
index 518b681046aa10af2c4f6a47aae269ac37ef8170..45f2d4e03a19934fc5a58eafbbfe24764a46ad9c 100644 (file)
@@ -922,8 +922,9 @@ bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) {
   // If there is no linkage to be performed or we're linking from the source,
   // bring over SGA.
   auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType()));
-  auto *NewDA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
-                                SGA->getLinkage(), SGA->getName(), DstM);
+  auto *NewDA =
+      GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
+                          SGA->getLinkage(), SGA->getName(), DstM);
   copyGVAttributes(NewDA, SGA);
   if (NewVisibility)
     NewDA->setVisibility(*NewVisibility);
index bcc2835d3da5b86258ef39c99640fe41bc3ef5b3..c3a2b1205c1aafdeb0ceaf3fe717f4a63dbaf3ea 100644 (file)
@@ -1328,8 +1328,8 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
 // Replace G with an alias to F and delete G.
 void MergeFunctions::writeAlias(Function *F, Function *G) {
   PointerType *PTy = G->getType();
-  auto *GA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
-                             G->getLinkage(), "", F);
+  auto *GA = GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
+                                 G->getLinkage(), "", F);
   F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
   GA->takeName(G);
   GA->setVisibility(G->getVisibility());
index 4ccdd9c2b86aee6be7b95746f453f62049473520..eb67db1f85dbcc46d6fe0c4eb3154528d142acf8 100644 (file)
@@ -68,8 +68,9 @@ Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) {
   for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
        I != E; ++I) {
     auto *PTy = cast<PointerType>(I->getType());
-    auto *GA = new GlobalAlias(PTy->getElementType(), PTy->getAddressSpace(),
-                               I->getLinkage(), I->getName(), New);
+    auto *GA =
+        GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
+                            I->getLinkage(), I->getName(), New);
     GA->copyAttributesFrom(I);
     VMap[I] = GA;
   }
index abab12202292cf04f3194c4d60c0c5cfee5876b2..c11729c08f076649e7431886271a8fd0ad970d93 100644 (file)
@@ -274,7 +274,7 @@ TEST(ConstantsTest, ReplaceInAliasTest) {
 
   Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
   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),
                "replaceAliasUseWith cannot form an alias cycle");
 }
index 3499bc315ef772199707d935851d7dc886e91d66..252bdd333c18e69dbcb68cd394bb32a16c5bdb86 100644 (file)
@@ -52,7 +52,7 @@ TEST(VerifierTest, AliasUnnamedAddr) {
   GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true,
                                                GlobalValue::ExternalLinkage,
                                                Init, "foo");
-  auto *GA = new GlobalAlias(GlobalValue::ExternalLinkage, "bar", Aliasee);
+  auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "bar", Aliasee);
   GA->setUnnamedAddr(true);
   std::string Error;
   raw_string_ostream ErrorOS(Error);
index 190167d0c12bc544cd754eb180b0ea8844879b14..fd00687f898557e979c0b9ca9d57bd4499fed5f6 100644 (file)
@@ -35,7 +35,7 @@ protected:
   }
 
   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) {