[llvm] r209007 - Fix most of PR10367.

Rafael Espindola rafael.espindola at gmail.com
Fri May 16 12:35:40 PDT 2014


Author: rafael
Date: Fri May 16 14:35:39 2014
New Revision: 209007

URL: http://llvm.org/viewvc/llvm-project?rev=209007&view=rev
Log:
Fix most of PR10367.

This patch changes the design of GlobalAlias so that it doesn't take a
ConstantExpr anymore. It now points directly to a GlobalObject, but its type is
independent of the aliasee type.

To avoid changing all alias related tests in this patches, I kept the common
syntax

@foo = alias i32* @bar

to mean the same as now. The cases that used to use cast now use the more
general syntax

@foo = alias i16, i32* @bar.

Note that GlobalAlias now behaves a bit more like GlobalVariable. We
know that its type is always a pointer, so we omit the '*'.

For the bitcode, a nice surprise is that we were writing both identical types
already, so the format change is minimal. Auto upgrade is handled by looking
through the casts and no new fields are needed for now. New bitcode will
simply have different types for Alias and Aliasee.

One last interesting point in the patch is that replaceAllUsesWith becomes
smart enough to avoid putting a ConstantExpr in the aliasee. This seems better
than checking and updating every caller.

A followup patch will delete getAliasedGlobal now that it is redundant. Another
patch will add support for an explicit offset.

Added:
    llvm/trunk/test/Assembler/alias-addrspace.ll
    llvm/trunk/test/Assembler/alias-to-alias.ll
    llvm/trunk/test/Assembler/alias-to-alias2.ll
    llvm/trunk/test/Assembler/alias-type.ll
    llvm/trunk/test/Bitcode/old-aliases.ll
    llvm/trunk/test/Bitcode/old-aliases.ll.bc
    llvm/trunk/test/Feature/alias2.ll
    llvm/trunk/test/Linker/Inputs/alias.ll
    llvm/trunk/test/Linker/Inputs/cycle.ll
    llvm/trunk/test/Linker/alias.ll
    llvm/trunk/test/Linker/cycle.ll
Removed:
    llvm/trunk/test/Assembler/2009-04-25-AliasGEP.ll
    llvm/trunk/test/Verifier/aliasing-chain.ll
    llvm/trunk/test/Verifier/bitcast-alias-address-space.ll
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/AsmWriter.cpp
    llvm/trunk/lib/IR/Core.cpp
    llvm/trunk/lib/IR/Globals.cpp
    llvm/trunk/lib/IR/Value.cpp
    llvm/trunk/lib/IR/Verifier.cpp
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
    llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
    llvm/trunk/test/Assembler/addrspacecast-alias.ll
    llvm/trunk/test/CodeGen/ARM/aliases.ll
    llvm/trunk/test/CodeGen/X86/aliases.ll
    llvm/trunk/test/CodeGen/X86/dllexport-x86_64.ll
    llvm/trunk/test/CodeGen/X86/dllexport.ll
    llvm/trunk/test/Feature/aliases.ll
    llvm/trunk/test/Linker/Inputs/PR8300.b.ll
    llvm/trunk/test/Other/extract-alias.ll
    llvm/trunk/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll
    llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll
    llvm/trunk/test/Transforms/GlobalOpt/alias-resolve.ll
    llvm/trunk/test/Transforms/InstCombine/bitcast-alias-function.ll
    llvm/trunk/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll
    llvm/trunk/unittests/IR/ConstantsTest.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=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalAlias.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalAlias.h Fri May 16 14:35:39 2014
@@ -41,7 +41,7 @@ public:
   /// 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,
+              GlobalObject *Aliasee = nullptr, Module *Parent = nullptr,
               unsigned AddressSpace = 0);
 
   /// Provide fast operand accessors
@@ -58,18 +58,19 @@ public:
   void eraseFromParent() override;
 
   /// set/getAliasee - These methods retrive and set alias target.
-  void setAliasee(Constant *GV);
-  const Constant *getAliasee() const {
-    return getOperand(0);
+  void setAliasee(GlobalObject *GO);
+  const GlobalObject *getAliasee() const {
+    return const_cast<GlobalAlias *>(this)->getAliasee();
   }
-  Constant *getAliasee() {
-    return getOperand(0);
+
+  GlobalObject *getAliasee() {
+    return cast_or_null<GlobalObject>(getOperand(0));
+  }
+
+  GlobalObject *getAliasedGlobal() {
+    return getAliasee();
   }
 
-  /// This method tries to ultimately resolve the alias by going through the
-  /// aliasing chain and trying to find the very last global. Returns NULL if a
-  /// cycle was found.
-  GlobalObject *getAliasedGlobal();
   const GlobalObject *getAliasedGlobal() const {
     return const_cast<GlobalAlias *>(this)->getAliasedGlobal();
   }

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Fri May 16 14:35:39 2014
@@ -630,10 +630,11 @@ static bool isValidVisibilityForLinkage(
 /// ParseAlias:
 ///   ::= GlobalVar '=' OptionalVisibility OptionalDLLStorageClass 'alias'
 ///                     OptionalLinkage Aliasee
+///   ::= GlobalVar '=' OptionalVisibility OptionalDLLStorageClass 'alias'
+///                     OptionalLinkage OptionalAddrSpace Type, Aliasee
+///
 /// Aliasee
 ///   ::= TypeAndValue
-///   ::= 'bitcast' '(' TypeAndValue 'to' Type ')'
-///   ::= 'getelementptr' 'inbounds'? '(' ... ')'
 ///
 /// Everything through DLL storage class has already been parsed.
 ///
@@ -655,28 +656,49 @@ bool LLParser::ParseAlias(const std::str
     return Error(LinkageLoc,
                  "symbol with local linkage must have default visibility");
 
-  Constant *Aliasee;
-  LocTy AliaseeLoc = Lex.getLoc();
-  if (Lex.getKind() != lltok::kw_bitcast &&
-      Lex.getKind() != lltok::kw_getelementptr) {
-    if (ParseGlobalTypeAndValue(Aliasee)) return true;
+  bool HasAddrSpace = Lex.getKind() == lltok::kw_addrspace;
+  unsigned AddrSpace;
+  LocTy AddrSpaceLoc = Lex.getLoc();
+  if (ParseOptionalAddrSpace(AddrSpace))
+    return true;
+
+  LocTy TyLoc = Lex.getLoc();
+  Type *Ty = nullptr;
+  if (ParseType(Ty))
+    return true;
+
+  bool DifferentType = EatIfPresent(lltok::comma);
+  if (HasAddrSpace && !DifferentType)
+    return Error(AddrSpaceLoc, "A type is required if addrspace is given");
+
+  Type *AliaseeType = nullptr;
+  if (DifferentType) {
+    if (ParseType(AliaseeType))
+      return true;
   } else {
-    // The bitcast dest type is not present, it is implied by the dest type.
-    ValID ID;
-    if (ParseValID(ID)) return true;
-    if (ID.Kind != ValID::t_Constant)
-      return Error(AliaseeLoc, "invalid aliasee");
-    Aliasee = ID.ConstantVal;
+    AliaseeType = Ty;
+    auto *PTy = dyn_cast<PointerType>(Ty);
+    if (!PTy)
+      return Error(TyLoc, "An alias must have pointer type");
+    Ty = PTy->getElementType();
+    AddrSpace = PTy->getAddressSpace();
   }
 
-  if (!Aliasee->getType()->isPointerTy())
-    return Error(AliaseeLoc, "alias must have pointer type");
+  LocTy AliaseeLoc = Lex.getLoc();
+  Constant *C;
+  if (ParseGlobalValue(AliaseeType, C))
+    return true;
+
+  auto *Aliasee = dyn_cast<GlobalObject>(C);
+  if (!Aliasee)
+    return Error(AliaseeLoc, "Alias must point to function or variable");
+
+  assert(Aliasee->getType()->isPointerTy());
 
   // Okay, create the alias but do not insert it into the module yet.
-  PointerType *PTy = cast<PointerType>(Aliasee->getType());
   std::unique_ptr<GlobalAlias> GA(
-      new GlobalAlias(PTy->getElementType(), (GlobalValue::LinkageTypes)Linkage,
-                      Name, Aliasee, nullptr, PTy->getAddressSpace()));
+      new GlobalAlias(Ty, (GlobalValue::LinkageTypes)Linkage, Name, Aliasee,
+                      /*Parent*/ nullptr, AddrSpace));
   GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
   GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
 
@@ -698,6 +720,11 @@ bool LLParser::ParseAlias(const std::str
 
     // If they agree, just RAUW the old value with the alias and remove the
     // forward ref info.
+    for (auto *User : Val->users()) {
+      if (auto *GA = dyn_cast<GlobalAlias>(User))
+        return Error(NameLoc, "Alias is pointed by alias " + GA->getName());
+    }
+
     Val->replaceAllUsesWith(GA.get());
     Val->eraseFromParent();
     ForwardRefVals.erase(I);

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri May 16 14:35:39 2014
@@ -1092,6 +1092,28 @@ uint64_t BitcodeReader::decodeSignRotate
   return 1ULL << 63;
 }
 
+// FIXME: Delete this in LLVM 4.0 and just assert that the aliasee is a
+// GlobalObject.
+static GlobalObject &
+getGlobalObjectInExpr(const DenseMap<GlobalAlias *, Constant *> &Map,
+                      Constant &C) {
+  auto *GO = dyn_cast<GlobalObject>(&C);
+  if (GO)
+    return *GO;
+
+  auto *GA = dyn_cast<GlobalAlias>(&C);
+  if (GA)
+    return getGlobalObjectInExpr(Map, *Map.find(GA)->second);
+
+  auto &CE = cast<ConstantExpr>(C);
+  assert(CE.getOpcode() == Instruction::BitCast ||
+         CE.getOpcode() == Instruction::GetElementPtr ||
+         CE.getOpcode() == Instruction::AddrSpaceCast);
+  if (CE.getOpcode() == Instruction::GetElementPtr)
+    assert(cast<GEPOperator>(CE).hasAllZeroIndices());
+  return getGlobalObjectInExpr(Map, *CE.getOperand(0));
+}
+
 /// ResolveGlobalAndAliasInits - Resolve all of the initializers for global
 /// values and aliases that we can.
 error_code BitcodeReader::ResolveGlobalAndAliasInits() {
@@ -1117,19 +1139,30 @@ error_code BitcodeReader::ResolveGlobalA
     GlobalInitWorklist.pop_back();
   }
 
+  // FIXME: Delete this in LLVM 4.0
+  // Older versions of llvm could write an alias pointing to another. We cannot
+  // construct those aliases, so we first collect an alias to aliasee expression
+  // and then compute the actual aliasee.
+  DenseMap<GlobalAlias *, Constant *> AliasInit;
+
   while (!AliasInitWorklist.empty()) {
     unsigned ValID = AliasInitWorklist.back().second;
     if (ValID >= ValueList.size()) {
       AliasInits.push_back(AliasInitWorklist.back());
     } else {
       if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
-        AliasInitWorklist.back().first->setAliasee(C);
+        AliasInit.insert(std::make_pair(AliasInitWorklist.back().first, C));
       else
         return Error(ExpectedConstant);
     }
     AliasInitWorklist.pop_back();
   }
 
+  for (auto &Pair : AliasInit) {
+    auto &GO = getGlobalObjectInExpr(AliasInit, *Pair.second);
+    Pair.first->setAliasee(&GO);
+  }
+
   while (!FunctionPrefixWorklist.empty()) {
     unsigned ValID = FunctionPrefixWorklist.back().second;
     if (ValID >= ValueList.size()) {

Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Fri May 16 14:35:39 2014
@@ -1493,10 +1493,16 @@ void AssemblyWriter::printAlias(const Gl
 
   PrintLinkage(GA->getLinkage(), Out);
 
+  PointerType *Ty = GA->getType();
   const Constant *Aliasee = GA->getAliasee();
+  if (!Aliasee || Ty != Aliasee->getType()) {
+    if (unsigned AddressSpace = Ty->getAddressSpace())
+      Out << "addrspace(" << AddressSpace << ") ";
+    TypePrinter.print(Ty->getElementType(), Out);
+    Out << ", ";
+  }
 
   if (!Aliasee) {
-    TypePrinter.print(GA->getType(), Out);
     Out << " <<NULL ALIASEE>>";
   } else {
     writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));

Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Fri May 16 14:35:39 2014
@@ -1491,7 +1491,7 @@ LLVMValueRef LLVMAddAlias(LLVMModuleRef
   auto *PTy = cast<PointerType>(unwrap(Ty));
   return wrap(new GlobalAlias(
       PTy->getElementType(), GlobalValue::ExternalLinkage, Name,
-      unwrap<Constant>(Aliasee), unwrap(M), PTy->getAddressSpace()));
+      unwrap<GlobalObject>(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=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Fri May 16 14:35:39 2014
@@ -214,15 +214,11 @@ void GlobalVariable::copyAttributesFrom(
 //===----------------------------------------------------------------------===//
 
 GlobalAlias::GlobalAlias(Type *Ty, LinkageTypes Link, const Twine &Name,
-                         Constant *Aliasee, Module *ParentModule,
+                         GlobalObject *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() == getType() &&
-           "Alias and aliasee types should match!");
   Op<0>() = Aliasee;
 
   if (ParentModule)
@@ -245,42 +241,4 @@ void GlobalAlias::eraseFromParent() {
   getParent()->getAliasList().erase(this);
 }
 
-void GlobalAlias::setAliasee(Constant *Aliasee) {
-  assert((!Aliasee || Aliasee->getType() == getType()) &&
-         "Alias and aliasee types should match!");
-
-  setOperand(0, Aliasee);
-}
-
-static GlobalValue *getAliaseeGV(GlobalAlias *GA) {
-  Constant *C = GA->getAliasee();
-  assert(C && "Must alias something");
-
-  if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
-    return GV;
-
-  ConstantExpr *CE = cast<ConstantExpr>(C);
-  assert((CE->getOpcode() == Instruction::BitCast ||
-          CE->getOpcode() == Instruction::AddrSpaceCast ||
-          CE->getOpcode() == Instruction::GetElementPtr) &&
-         "Unsupported aliasee");
-
-  return cast<GlobalValue>(CE->getOperand(0));
-}
-
-GlobalObject *GlobalAlias::getAliasedGlobal() {
-  SmallPtrSet<GlobalValue*, 3> Visited;
-
-  GlobalAlias *GA = this;
-
-  for (;;) {
-    GlobalValue *GV = getAliaseeGV(GA);
-    if (!Visited.insert(GV))
-      return nullptr;
-
-    // Iterate over aliasing chain.
-    GA = dyn_cast<GlobalAlias>(GV);
-    if (!GA)
-      return cast<GlobalObject>(GV);
-  }
-}
+void GlobalAlias::setAliasee(GlobalObject *Aliasee) { setOperand(0, Aliasee); }

Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Fri May 16 14:35:39 2014
@@ -301,6 +301,28 @@ void Value::takeName(Value *V) {
     ST->reinsertValue(this);
 }
 
+static GlobalObject &findReplacementForAliasUse(Value &C) {
+  if (auto *GO = dyn_cast<GlobalObject>(&C))
+    return *GO;
+  if (auto *GA = dyn_cast<GlobalAlias>(&C))
+    return *GA->getAliasee();
+  auto *CE = cast<ConstantExpr>(&C);
+  assert(CE->getOpcode() == Instruction::BitCast ||
+         CE->getOpcode() == Instruction::GetElementPtr ||
+         CE->getOpcode() == Instruction::AddrSpaceCast);
+  if (CE->getOpcode() == Instruction::GetElementPtr)
+    assert(cast<GEPOperator>(CE)->hasAllZeroIndices());
+  return findReplacementForAliasUse(*CE->getOperand(0));
+}
+
+static void replaceAliasUseWith(Use &U, Value *New) {
+  GlobalObject &Replacement = findReplacementForAliasUse(*New);
+  auto *Old = &cast<GlobalObject>(*U);
+  assert(Old != &Replacement &&
+         "replaceAliasUseWith cannot form an alias cycle");
+  U.set(&Replacement);
+}
+
 #ifndef NDEBUG
 static bool contains(SmallPtrSet<ConstantExpr *, 4> &Cache, ConstantExpr *Expr,
                      Constant *C) {
@@ -351,7 +373,11 @@ void Value::replaceAllUsesWith(Value *Ne
     Use &U = *UseList;
     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
     // constant because they are uniqued.
-    if (Constant *C = dyn_cast<Constant>(U.getUser())) {
+    if (auto *C = dyn_cast<Constant>(U.getUser())) {
+      if (isa<GlobalAlias>(C)) {
+        replaceAliasUseWith(U, New);
+        continue;
+      }
       if (!isa<GlobalValue>(C)) {
         C->replaceUsesOfWithOnConstant(this, New, &U);
         continue;

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Fri May 16 14:35:39 2014
@@ -473,8 +473,6 @@ void Verifier::visitGlobalAlias(const Gl
           "Alias should have external or external weak linkage!", &GA);
   Assert1(GA.getAliasee(),
           "Aliasee cannot be NULL!", &GA);
-  Assert1(GA.getType() == GA.getAliasee()->getType(),
-          "Alias and aliasee types should match!", &GA);
   Assert1(!GA.hasUnnamedAddr(), "Alias cannot have unnamed_addr!", &GA);
 
   const Constant *Aliasee = GA.getAliasee();
@@ -506,10 +504,6 @@ void Verifier::visitGlobalAlias(const Gl
             &GA);
   }
 
-  const GlobalValue *AG = GA.getAliasedGlobal();
-  Assert1(AG, "Aliasing chain should end with function or global variable",
-          &GA);
-
   visitGlobalValue(GA);
 }
 

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri May 16 14:35:39 2014
@@ -389,6 +389,8 @@ namespace {
     /// actually need, but this allows us to reuse the ValueMapper code.
     ValueToValueMapTy ValueMap;
 
+    std::vector<std::pair<GlobalValue *, GlobalAlias *>> ReplaceWithAlias;
+
     struct AppendingVarInfo {
       GlobalVariable *NewGV;  // New aggregate global in dest module.
       Constant *DstInit;      // Old initializer from dest module.
@@ -920,18 +922,15 @@ bool ModuleLinker::linkAliasProto(Global
   // 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()));
-  GlobalAlias *NewDA =
+  auto *NewDA =
       new GlobalAlias(PTy->getElementType(), SGA->getLinkage(), SGA->getName(),
                       /*aliasee*/ nullptr, DstM, PTy->getAddressSpace());
   copyGVAttributes(NewDA, SGA);
   if (NewVisibility)
     NewDA->setVisibility(*NewVisibility);
 
-  if (DGV) {
-    // Any uses of DGV need to change to NewDA, with cast.
-    DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDA, DGV->getType()));
-    DGV->eraseFromParent();
-  }
+  if (DGV)
+    ReplaceWithAlias.push_back(std::make_pair(DGV, NewDA));
 
   ValueMap[SGA] = NewDA;
   return false;
@@ -1017,6 +1016,19 @@ void ModuleLinker::linkFunctionBody(Func
 
 }
 
+static GlobalObject &getGlobalObjectInExpr(Constant &C) {
+  auto *GO = dyn_cast<GlobalObject>(&C);
+  if (GO)
+    return *GO;
+  auto *GA = dyn_cast<GlobalAlias>(&C);
+  if (GA)
+    return *GA->getAliasee();
+  auto &CE = cast<ConstantExpr>(C);
+  assert(CE.getOpcode() == Instruction::BitCast ||
+         CE.getOpcode() == Instruction::AddrSpaceCast);
+  return getGlobalObjectInExpr(*CE.getOperand(0));
+}
+
 /// linkAliasBodies - Insert all of the aliases in Src into the Dest module.
 void ModuleLinker::linkAliasBodies() {
   for (Module::alias_iterator I = SrcM->alias_begin(), E = SrcM->alias_end();
@@ -1025,10 +1037,27 @@ void ModuleLinker::linkAliasBodies() {
       continue;
     if (Constant *Aliasee = I->getAliasee()) {
       GlobalAlias *DA = cast<GlobalAlias>(ValueMap[I]);
-      DA->setAliasee(MapValue(Aliasee, ValueMap, RF_None,
-                              &TypeMap, &ValMaterializer));
+      Constant *Val =
+          MapValue(Aliasee, ValueMap, RF_None, &TypeMap, &ValMaterializer);
+      DA->setAliasee(&getGlobalObjectInExpr(*Val));
     }
   }
+
+  // Any uses of DGV need to change to NewDA, with cast.
+  for (auto &Pair : ReplaceWithAlias) {
+    GlobalValue *DGV = Pair.first;
+    GlobalAlias *NewDA = Pair.second;
+
+    for (auto *User : DGV->users()) {
+      if (auto *GA = dyn_cast<GlobalAlias>(User)) {
+        if (GA == NewDA)
+          report_fatal_error("Linking these modules creates an alias cycle.");
+      }
+    }
+
+    DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDA, DGV->getType()));
+    DGV->eraseFromParent();
+  }
 }
 
 /// linkNamedMDNodes - Insert all of the named MDNodes in Src into the Dest

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Fri May 16 14:35:39 2014
@@ -2861,7 +2861,7 @@ bool GlobalOpt::OptimizeGlobalAliases(Mo
     if (!hasUsesToReplace(*J, Used, RenameTarget))
       continue;
 
-    J->replaceAllUsesWith(Aliasee);
+    J->replaceAllUsesWith(ConstantExpr::getBitCast(Aliasee, J->getType()));
     ++NumAliasesResolved;
     Changed = true;
 

Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Fri May 16 14:35:39 2014
@@ -1327,11 +1327,9 @@ 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());
   PointerType *PTy = G->getType();
-  GlobalAlias *GA =
-      new GlobalAlias(PTy->getElementType(), G->getLinkage(), "", BitcastF,
-                      G->getParent(), PTy->getAddressSpace());
+  auto *GA = new GlobalAlias(PTy->getElementType(), G->getLinkage(), "", F,
+                             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=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Fri May 16 14:35:39 2014
@@ -107,8 +107,8 @@ Module *llvm::CloneModule(const Module *
   for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
        I != E; ++I) {
     GlobalAlias *GA = cast<GlobalAlias>(VMap[I]);
-    if (const Constant *C = I->getAliasee())
-      GA->setAliasee(MapValue(C, VMap));
+    if (const GlobalObject *C = I->getAliasee())
+      GA->setAliasee(cast<GlobalObject>(MapValue(C, VMap)));
   }
 
   // And named metadata....

Removed: llvm/trunk/test/Assembler/2009-04-25-AliasGEP.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/2009-04-25-AliasGEP.ll?rev=209006&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/2009-04-25-AliasGEP.ll (original)
+++ llvm/trunk/test/Assembler/2009-04-25-AliasGEP.ll (removed)
@@ -1,8 +0,0 @@
-; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis
-; PR4066
-target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
-target triple = "i386-apple-darwin9"
-	%struct.i2c_device_id = type { }
- at w83l785ts_id = internal constant [0 x %struct.i2c_device_id] zeroinitializer, align 1		; <[0 x %struct.i2c_device_id]*> [#uses=1]
-
- at __mod_i2c_device_table = alias getelementptr ([0 x %struct.i2c_device_id]* @w83l785ts_id, i32 0, i32 0)		; <%struct.i2c_device_id*> [#uses=0]

Modified: llvm/trunk/test/Assembler/addrspacecast-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/addrspacecast-alias.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/addrspacecast-alias.ll (original)
+++ llvm/trunk/test/Assembler/addrspacecast-alias.ll Fri May 16 14:35:39 2014
@@ -1,6 +1,7 @@
-; RUN: llvm-as -disable-output %s
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
 
 ; Test that global aliases are allowed to be constant addrspacecast
 
 @i = internal addrspace(1) global i8 42
- at ia = alias internal i8 addrspace(2)* addrspacecast (i8 addrspace(1)* @i to i8 addrspace(2)*)
+ at ia = alias internal addrspace(2) i8 addrspace(3)*, i8 addrspace(1)* @i
+; CHECK: @ia = alias internal addrspace(2) i8 addrspace(3)*, i8 addrspace(1)* @i

Added: llvm/trunk/test/Assembler/alias-addrspace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/alias-addrspace.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/alias-addrspace.ll (added)
+++ llvm/trunk/test/Assembler/alias-addrspace.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,6 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+ at foo = global i32 42
+ at bar = alias internal addrspace(1) i32* @foo
+
+CHECK: error: A type is required if addrspace is given

Added: llvm/trunk/test/Assembler/alias-to-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/alias-to-alias.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/alias-to-alias.ll (added)
+++ llvm/trunk/test/Assembler/alias-to-alias.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,5 @@
+; RUN:  not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+; CHECK: Alias must point to function or variable
+
+ at b1 = alias i32* @c1
+ at c1 = alias i32* @b1

Added: llvm/trunk/test/Assembler/alias-to-alias2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/alias-to-alias2.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/alias-to-alias2.ll (added)
+++ llvm/trunk/test/Assembler/alias-to-alias2.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,7 @@
+; RUN:  not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+; CHECK: error: Alias is pointed by alias b1
+
+ at g = global i32 42
+
+ at b1 = alias i32* @c1
+ at c1 = alias i32* @g

Added: llvm/trunk/test/Assembler/alias-type.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/alias-type.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/alias-type.ll (added)
+++ llvm/trunk/test/Assembler/alias-type.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,6 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+ at foo = global i32 42
+ at bar = alias i32 @foo
+
+CHECK: error: An alias must have pointer type

Added: llvm/trunk/test/Bitcode/old-aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/old-aliases.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/old-aliases.ll (added)
+++ llvm/trunk/test/Bitcode/old-aliases.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,22 @@
+; RUN: llvm-dis < %s.bc | FileCheck %s
+
+; old-aliases.bc consist of this file assembled with an old llvm-as (3.5 trunk)
+; from when aliases contained a ConstantExpr.
+
+ at v1 = global i32 0
+; CHECK: @v1 = global i32 0
+
+ at v2 = global [1 x i32] zeroinitializer
+; CHECK: @v2 = global [1 x i32] zeroinitializer
+
+ at v3 = alias bitcast (i32* @v1 to i16*)
+; CHECK: @v3 = alias i16, i32* @v1
+
+ at v4 = alias getelementptr ([1 x i32]* @v2, i32 0, i32 0)
+; CHECK: @v4 = alias i32, [1 x i32]* @v2
+
+ at v5 = alias i32 addrspace(2)* addrspacecast (i32 addrspace(0)* @v1 to i32 addrspace(2)*)
+; CHECK: @v5 = alias addrspace(2) i32, i32* @v1
+
+ at v6 = alias i16* @v3
+; CHECK: @v6 = alias i16, i32* @v1

Added: llvm/trunk/test/Bitcode/old-aliases.ll.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/old-aliases.ll.bc?rev=209007&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/old-aliases.ll.bc (added) and llvm/trunk/test/Bitcode/old-aliases.ll.bc Fri May 16 14:35:39 2014 differ

Modified: llvm/trunk/test/CodeGen/ARM/aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/aliases.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/aliases.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/aliases.ll Fri May 16 14:35:39 2014
@@ -29,7 +29,7 @@ define i32 @foo_f() {
 
 @bar_i = alias internal i32* @bar
 
- at A = alias bitcast (i32* @bar to i64*)
+ at A = alias i64, i32* @bar
 
 define i32 @test() {
 entry:

Modified: llvm/trunk/test/CodeGen/X86/aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/aliases.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/aliases.ll (original)
+++ llvm/trunk/test/CodeGen/X86/aliases.ll Fri May 16 14:35:39 2014
@@ -22,7 +22,7 @@ define i32 @foo_f() {
 @bar_i = alias internal i32* @bar
 
 ; CHECK-DAG: .globl	A
- at A = alias bitcast (i32* @bar to i64*)
+ at A = alias i64, i32* @bar
 
 ; CHECK-DAG: .globl	bar_h
 ; CHECK-DAG: .hidden	bar_h

Modified: llvm/trunk/test/CodeGen/X86/dllexport-x86_64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dllexport-x86_64.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dllexport-x86_64.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dllexport-x86_64.ll Fri May 16 14:35:39 2014
@@ -66,7 +66,7 @@ define weak_odr dllexport void @weak1()
 
 ; CHECK: .globl alias3
 ; CHECK: alias3 = notExported
- at alias3 = dllexport alias void()* @alias
+ at alias3 = dllexport alias void()* @notExported
 
 ; CHECK: .weak weak_alias
 ; CHECK: weak_alias = f1

Modified: llvm/trunk/test/CodeGen/X86/dllexport.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dllexport.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dllexport.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dllexport.ll Fri May 16 14:35:39 2014
@@ -85,7 +85,7 @@ define weak_odr dllexport void @weak1()
 
 ; CHECK: .globl _alias3
 ; CHECK: _alias3 = _notExported
- at alias3 = dllexport alias void()* @alias
+ at alias3 = dllexport alias void()* @notExported
 
 ; CHECK: .weak _weak_alias
 ; CHECK: _weak_alias = _f1

Added: llvm/trunk/test/Feature/alias2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/alias2.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Feature/alias2.ll (added)
+++ llvm/trunk/test/Feature/alias2.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,19 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+ at v1 = global i32 0
+; CHECK: @v1 = global i32 0
+
+ at v2 = global [1 x i32] zeroinitializer
+; CHECK: @v2 = global [1 x i32] zeroinitializer
+
+ at v3 = alias i16, i32* @v1
+; CHECK: @v3 = alias i16, i32* @v1
+
+ at v4 = alias i32, [1 x i32]* @v2
+; CHECK: @v4 = alias i32, [1 x i32]* @v2
+
+ at v5 = alias addrspace(2) i32, i32* @v1
+; CHECK: @v5 = alias addrspace(2) i32, i32* @v1
+
+ at v6 = alias i16, i32* @v1
+; CHECK: @v6 = alias i16, i32* @v1

Modified: llvm/trunk/test/Feature/aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/aliases.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Feature/aliases.ll (original)
+++ llvm/trunk/test/Feature/aliases.ll Fri May 16 14:35:39 2014
@@ -7,7 +7,6 @@
 @bar = global i32 0
 @foo1 = alias i32* @bar
 @foo2 = alias i32* @bar
- at foo3 = alias i32* @foo2
 
 %FunTy = type i32()
 
@@ -15,11 +14,10 @@ define i32 @foo_f() {
   ret i32 0
 }
 @bar_f = alias weak_odr %FunTy* @foo_f
- at bar_ff = alias i32()* @bar_f
 
 @bar_i = alias internal i32* @bar
 
- at A = alias bitcast (i32* @bar to i64*)
+ at A = alias i64, i32* @bar
 
 define i32 @test() {
 entry:

Modified: llvm/trunk/test/Linker/Inputs/PR8300.b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/PR8300.b.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Linker/Inputs/PR8300.b.ll (original)
+++ llvm/trunk/test/Linker/Inputs/PR8300.b.ll Fri May 16 14:35:39 2014
@@ -1,7 +1,7 @@
 %foo = type { [8 x i8] }
 %bar = type { [9 x i8] }
 
- at zed = alias bitcast (void (%bar*)* @xyz to void (%foo*)*)
+ at zed = alias void (%foo*), void (%bar*)* @xyz
 
 define void @xyz(%bar* %this) {
 entry:

Added: llvm/trunk/test/Linker/Inputs/alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/alias.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/alias.ll (added)
+++ llvm/trunk/test/Linker/Inputs/alias.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,3 @@
+ at zed = global i32 42
+ at foo = alias i32* @zed
+ at foo2 = alias i16, i32* @zed

Added: llvm/trunk/test/Linker/Inputs/cycle.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/cycle.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/cycle.ll (added)
+++ llvm/trunk/test/Linker/Inputs/cycle.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,2 @@
+ at foo = alias i32* @bar
+ at bar = weak global i32 0

Added: llvm/trunk/test/Linker/alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/alias.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Linker/alias.ll (added)
+++ llvm/trunk/test/Linker/alias.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,16 @@
+; RUN: llvm-link %s %S/Inputs/alias.ll -S -o - | FileCheck %s
+; RUN: llvm-link %S/Inputs/alias.ll %s -S -o - | FileCheck %s
+
+ at foo = weak global i32 0
+; CHECK-DAG: @foo = alias i32* @zed
+
+ at bar = alias i32* @foo
+; CHECK-DAG: @bar = alias i32* @zed
+
+ at foo2 = weak global i32 0
+; CHECK-DAG: @foo2 = alias i16, i32* @zed
+
+ at bar2 = alias i32* @foo2
+; CHECK-DAG: @bar2 = alias i32* @zed
+
+; CHECK-DAG: @zed = global i32 42

Added: llvm/trunk/test/Linker/cycle.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/cycle.ll?rev=209007&view=auto
==============================================================================
--- llvm/trunk/test/Linker/cycle.ll (added)
+++ llvm/trunk/test/Linker/cycle.ll Fri May 16 14:35:39 2014
@@ -0,0 +1,7 @@
+; RUN: not llvm-link %s %S/Inputs/cycle.ll 2>&1 | FileCheck %s
+; RUN: not llvm-link %S/Inputs/cycle.ll %s 2>&1 | FileCheck %s
+
+; CHECK: Linking these modules creates an alias cycle
+
+ at foo = weak global i32 0
+ at bar = alias i32* @foo

Modified: llvm/trunk/test/Other/extract-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/extract-alias.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Other/extract-alias.ll (original)
+++ llvm/trunk/test/Other/extract-alias.ll Fri May 16 14:35:39 2014
@@ -14,7 +14,7 @@
 ; DELETE:      @zed = global i32 0
 ; DELETE:      @zeda0 = alias i32* @zed
 ; DELETE-NEXT: @a0foo = alias i32* ()* @foo
-; DELETE-NEXT: @a0a0bar = alias void ()* @a0bar
+; DELETE-NEXT: @a0a0bar = alias void ()* @bar
 ; DELETE-NEXT: @a0bar = alias void ()* @bar
 ; DELETE:      declare i32* @foo()
 ; DELETE:      define void @bar() {
@@ -25,7 +25,7 @@
 ; ALIAS: @zed = external global i32
 ; ALIAS: @zeda0 = alias i32* @zed
 
-; ALIASRE: @a0a0bar = alias void ()* @a0bar
+; ALIASRE: @a0a0bar = alias void ()* @bar
 ; ALIASRE: @a0bar = alias void ()* @bar
 ; ALIASRE: declare void @bar()
 
@@ -39,7 +39,7 @@ define i32* @foo() {
   ret i32* @zeda0
 }
 
- at a0a0bar = alias void ()* @a0bar
+ at a0a0bar = alias void ()* @bar
 
 @a0bar = alias void ()* @bar
 

Modified: llvm/trunk/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll (original)
+++ llvm/trunk/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll Fri May 16 14:35:39 2014
@@ -11,8 +11,8 @@
 @L1 = alias i32* @A
 ; CHECK: @L1 = alias i32* @A
 
- at L2 = alias internal i32* @L1
-; CHECK: @L2 = alias internal i32* @L1
+ at L2 = alias internal i32* @A
+; DEAD-NOT: @L2
 
- at L3 = alias i32* @L2
-; CHECK: @L3 = alias i32* @L2
+ at L3 = alias i32* @A
+; CHECK: @L3 = alias i32* @A

Modified: llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll Fri May 16 14:35:39 2014
@@ -2,7 +2,7 @@
 
 @g = global i32 0
 
- at a = alias bitcast (i32* @g to i8*)
+ at a = alias i8, i32* @g
 
 define void @f() {
 	%tmp = load i8* @a

Modified: llvm/trunk/test/Transforms/GlobalOpt/alias-resolve.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/alias-resolve.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/alias-resolve.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/alias-resolve.ll Fri May 16 14:35:39 2014
@@ -1,9 +1,9 @@
 ; RUN: opt < %s -globalopt -S | FileCheck %s
 
- at foo1 = alias void ()* @foo2
+ at foo1 = alias void ()* @bar2
 ; CHECK: @foo1 = alias void ()* @bar2
 
- at foo2 = alias void()* @bar1
+ at foo2 = alias void()* @bar2
 ; CHECK: @foo2 = alias void ()* @bar2
 
 @bar1  = alias void ()* @bar2

Modified: llvm/trunk/test/Transforms/InstCombine/bitcast-alias-function.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bitcast-alias-function.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/bitcast-alias-function.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/bitcast-alias-function.ll Fri May 16 14:35:39 2014
@@ -6,46 +6,46 @@ target datalayout = "e-p:32:32:32-i32:32
 ; Cases that should be bitcast
 
 ; Test cast between scalars with same bit sizes
- at alias_i32_to_f32 = alias bitcast (i32 (i32)* @func_i32 to float (float)*)
+ at alias_i32_to_f32 = alias float (float), i32 (i32)* @func_i32
 
 ; Test cast between vectors with same number of elements and bit sizes
- at alias_v2i32_to_v2f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <2 x float> (<2 x float>)*)
+ at alias_v2i32_to_v2f32 = alias <2 x float> (<2 x float>), <2 x i32> (<2 x i32>)* @func_v2i32
 
 ; Test cast from vector to scalar with same number of bits
- at alias_v2f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <2 x float> (<2 x float>)*)
+ at alias_v2f32_to_i64 = alias <2 x float> (<2 x float>), i64 (i64)* @func_i64
 
 ; Test cast from scalar to vector with same number of bits
- at alias_i64_to_v2f32 = alias bitcast (<2 x float> (<2 x float>)* @func_v2f32 to i64 (i64)*)
+ at alias_i64_to_v2f32 = alias  i64 (i64), <2 x float> (<2 x float>)* @func_v2f32
 
 ; Test cast between vectors of pointers
- at alias_v2i32p_to_v2i64p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to <2 x i64*> (<2 x i64*>)*)
+ at alias_v2i32p_to_v2i64p = alias <2 x i64*> (<2 x i64*>), <2 x i32*> (<2 x i32*>)* @func_v2i32p
 
 
 ; Cases that should be invalid and unchanged
 
 ; Test cast between scalars with different bit sizes
- at alias_i64_to_f32 = alias bitcast (i64 (i64)* @func_i64 to float (float)*)
+ at alias_i64_to_f32 = alias float (float), i64 (i64)* @func_i64
 
 ; Test cast between vectors with different bit sizes but the
 ; same number of elements
- at alias_v2i64_to_v2f32 = alias bitcast (<2 x i64> (<2 x i64>)* @func_v2i64 to <2 x float> (<2 x float>)*)
+ at alias_v2i64_to_v2f32 = alias <2 x float> (<2 x float>), <2 x i64> (<2 x i64>)* @func_v2i64
 
 ; Test cast between vectors with same number of bits and different
 ; numbers of elements
- at alias_v2i32_to_v4f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <4 x float> (<4 x float>)*)
+ at alias_v2i32_to_v4f32 = alias  <4 x float> (<4 x float>), <2 x i32> (<2 x i32>)* @func_v2i32
 
 ; Test cast between scalar and vector with different number of bits
- at alias_i64_to_v4f32 = alias bitcast (<4 x float> (<4 x float>)* @func_v4f32 to i64 (i64)*)
+ at alias_i64_to_v4f32 = alias i64 (i64), <4 x float> (<4 x float>)* @func_v4f32
 
 ; Test cast between vector and scalar with different number of bits
- at alias_v4f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x float> (<4 x float>)*)
+ at alias_v4f32_to_i64 = alias <4 x float> (<4 x float>), i64 (i64)* @func_i64
 
 ; Test cast from scalar to vector of pointers with same number of bits
 ; We don't know the pointer size at this point, so this can't be done
- at alias_i64_to_v2i32p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to i64 (i64)*)
+ at alias_i64_to_v2i32p = alias  i64 (i64), <2 x i32*> (<2 x i32*>)* @func_v2i32p
 
 ; Test cast between vector of pointers and scalar with different number of bits
- at alias_v4i32p_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x i32*> (<4 x i32*>)*)
+ at alias_v4i32p_to_i64 = alias <4 x i32*> (<4 x i32*>), i64 (i64)* @func_i64
 
 
 

Modified: llvm/trunk/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll (original)
+++ llvm/trunk/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll Fri May 16 14:35:39 2014
@@ -6,8 +6,8 @@
 @B = alias i32* @A
 ; CHECK: @B = alias internal i32* @A
 
- at C = alias i32* @B
-; CHECK: @C = alias internal i32* @B
+ at C = alias i32* @A
+; CHECK: @C = alias internal i32* @A
 
 define i32 @main() {
 	%tmp = load i32* @C

Removed: llvm/trunk/test/Verifier/aliasing-chain.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/aliasing-chain.ll?rev=209006&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/aliasing-chain.ll (original)
+++ llvm/trunk/test/Verifier/aliasing-chain.ll (removed)
@@ -1,6 +0,0 @@
-; RUN:  not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
-; CHECK: Aliasing chain should end with function or global variable
-; Test that alising chain does not create a cycle
-
- at b1 = alias i32* @c1
- at c1 = alias i32* @b1

Removed: llvm/trunk/test/Verifier/bitcast-alias-address-space.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/bitcast-alias-address-space.ll?rev=209006&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/bitcast-alias-address-space.ll (original)
+++ llvm/trunk/test/Verifier/bitcast-alias-address-space.ll (removed)
@@ -1,10 +0,0 @@
-; RUN: not llvm-as -disable-output %s 2>&1 | FileCheck %s
-
-; CHECK: error: invalid cast opcode for cast from 'i32 addrspace(2)*' to 'i32 addrspace(1)*'
-
-target datalayout = "e-p:32:32:32-p1:16:16:16-p2:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n8:16:32"
-
-
- at data = addrspace(2) global i32 27
-
- at illegal_alias_data = alias bitcast (i32 addrspace(2)* @data to i32 addrspace(1)*)

Modified: llvm/trunk/unittests/IR/ConstantsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ConstantsTest.cpp (original)
+++ llvm/trunk/unittests/IR/ConstantsTest.cpp Fri May 16 14:35:39 2014
@@ -268,6 +268,18 @@ TEST(ConstantsTest, ReplaceWithConstantT
   EXPECT_DEATH(Global->replaceAllUsesWith(GEP),
                "this->replaceAllUsesWith\\(expr\\(this\\)\\) is NOT valid!");
 }
+
+TEST(ConstantsTest, ReplaceInAliasTest) {
+  std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext()));
+
+  Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
+  auto *Global = cast<GlobalObject>(M->getOrInsertGlobal("dummy", Int32Ty));
+  auto *GA = new GlobalAlias(Int32Ty, GlobalValue::ExternalLinkage, "alias",
+                             Global, M.get());
+  EXPECT_DEATH(Global->replaceAllUsesWith(GA),
+               "replaceAliasUseWith cannot form an alias cycle");
+}
+
 #endif
 #endif
 

Modified: llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp?rev=209007&r1=209006&r2=209007&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/SpecialCaseList.cpp Fri May 16 14:35:39 2014
@@ -34,7 +34,7 @@ protected:
         M, ST, false, GlobalValue::ExternalLinkage, 0, Name);
   }
 
-  GlobalAlias *makeAlias(StringRef Name, GlobalValue *Aliasee) {
+  GlobalAlias *makeAlias(StringRef Name, GlobalObject *Aliasee) {
     return new GlobalAlias(Aliasee->getType()->getElementType(),
                            GlobalValue::ExternalLinkage, Name, Aliasee,
                            Aliasee->getParent());





More information about the llvm-commits mailing list