Allow aliasee to be a GEP or bitcast instead of just a bitcast.
authorChris Lattner <sabre@nondot.org>
Sat, 25 Apr 2009 21:23:19 +0000 (21:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 25 Apr 2009 21:23:19 +0000 (21:23 +0000)
The real fix for this whole mess is to require the operand of the
alias to be a *GlobalValue* (not a general constant, including
constant exprs) but allow the operand and the alias type to be
unrelated.

This fixes PR4066

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70079 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AsmWriter.cpp
lib/VMCore/Verifier.cpp

index f007c7645cc017dd1a2e775d5dc929be2ec4259e..742931e8fd8044cb18d61ce32e7b5dd9a3f65e61 100644 (file)
@@ -1317,12 +1317,12 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
     Out << ' ';
     PrintLLVMName(Out, GA);
   } else {
-    const ConstantExpr *CE = 0;
-    if ((CE = dyn_cast<ConstantExpr>(Aliasee)) &&
-        (CE->getOpcode() == Instruction::BitCast)) {
-      writeOperand(CE, false);    
-    } else
-      assert(0 && "Unsupported aliasee");
+    const ConstantExpr *CE = cast<ConstantExpr>(Aliasee);
+    // The only valid GEP is an all zero GEP.
+    assert((CE->getOpcode() == Instruction::BitCast ||
+            CE->getOpcode() == Instruction::GetElementPtr) &&
+           "Unsupported aliasee");
+    writeOperand(CE, false);
   }
   
   printInfoComment(*GA);
index df9aceec024148ae5c8fea6f19cd5d653a577c1c..5e1137f32db2949c3e6cab26c56758fa8c443b03 100644 (file)
@@ -427,7 +427,9 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) {
 
   if (!isa<GlobalValue>(GA.getAliasee())) {
     const ConstantExpr *CE = dyn_cast<ConstantExpr>(GA.getAliasee());
-    Assert1(CE && CE->getOpcode() == Instruction::BitCast &&
+    Assert1(CE && 
+            (CE->getOpcode() == Instruction::BitCast ||
+             CE->getOpcode() == Instruction::GetElementPtr) &&
             isa<GlobalValue>(CE->getOperand(0)),
             "Aliasee should be either GlobalValue or bitcast of GlobalValue",
             &GA);