From cde89e48b23f80899225e91b3eedf3b6e7388d8d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 25 Apr 2009 21:23:19 +0000 Subject: [PATCH] Allow aliasee to be a GEP or bitcast instead of just a bitcast. 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 llvm-svn: 70079 --- llvm/lib/VMCore/AsmWriter.cpp | 12 ++++++------ llvm/lib/VMCore/Verifier.cpp | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp index f007c7645cc0..742931e8fd80 100644 --- a/llvm/lib/VMCore/AsmWriter.cpp +++ b/llvm/lib/VMCore/AsmWriter.cpp @@ -1317,12 +1317,12 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) { Out << ' '; PrintLLVMName(Out, GA); } else { - const ConstantExpr *CE = 0; - if ((CE = dyn_cast(Aliasee)) && - (CE->getOpcode() == Instruction::BitCast)) { - writeOperand(CE, false); - } else - assert(0 && "Unsupported aliasee"); + const ConstantExpr *CE = cast(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); diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index df9aceec0241..5e1137f32db2 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -427,7 +427,9 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) { if (!isa(GA.getAliasee())) { const ConstantExpr *CE = dyn_cast(GA.getAliasee()); - Assert1(CE && CE->getOpcode() == Instruction::BitCast && + Assert1(CE && + (CE->getOpcode() == Instruction::BitCast || + CE->getOpcode() == Instruction::GetElementPtr) && isa(CE->getOperand(0)), "Aliasee should be either GlobalValue or bitcast of GlobalValue", &GA);