From ee60d39cdd63716df89009037af4eaabe3c788fe Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 2 Jan 2014 20:55:01 +0000 Subject: [PATCH] Allow addrspacecast in global aliases git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198349 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Globals.cpp | 3 ++- lib/IR/Verifier.cpp | 4 +++- test/Assembler/addrspacecast-alias.ll | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/Assembler/addrspacecast-alias.ll diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index da3b02a0fa6..cc42351f100 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -237,7 +237,8 @@ GlobalValue *GlobalAlias::getAliasedGlobal() { return GV; ConstantExpr *CE = cast(C); - assert((CE->getOpcode() == Instruction::BitCast || + assert((CE->getOpcode() == Instruction::BitCast || + CE->getOpcode() == Instruction::AddrSpaceCast || CE->getOpcode() == Instruction::GetElementPtr) && "Unsupported aliasee"); diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 35b786ecf27..44c66c9062f 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -550,9 +550,11 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) { ConstantExpr *CE = dyn_cast(Aliasee); Assert1(CE && (CE->getOpcode() == Instruction::BitCast || + CE->getOpcode() == Instruction::AddrSpaceCast || CE->getOpcode() == Instruction::GetElementPtr) && isa(CE->getOperand(0)), - "Aliasee should be either GlobalValue or bitcast of GlobalValue", + "Aliasee should be either GlobalValue, bitcast or " + "addrspacecast of GlobalValue", &GA); if (CE->getOpcode() == Instruction::BitCast) { diff --git a/test/Assembler/addrspacecast-alias.ll b/test/Assembler/addrspacecast-alias.ll new file mode 100644 index 00000000000..6623a25d184 --- /dev/null +++ b/test/Assembler/addrspacecast-alias.ll @@ -0,0 +1,6 @@ +; RUN: llvm-as -disable-output %s + +; Test that global aliases are allowed to be constant addrspacecast + +@i = internal addrspace(1) global i8 42 +@ia = alias internal i8 addrspace(2)* addrspacecast (i8 addrspace(1)* @i to i8 addrspace(2)*)