Allow addrspacecast in global aliases
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Thu, 2 Jan 2014 20:55:01 +0000 (20:55 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Thu, 2 Jan 2014 20:55:01 +0000 (20:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198349 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Globals.cpp
lib/IR/Verifier.cpp
test/Assembler/addrspacecast-alias.ll [new file with mode: 0644]

index da3b02a0fa6d62fb1253f2287b7a3822dd3b314b..cc42351f10095591787826ce58042843d75de7da 100644 (file)
@@ -237,7 +237,8 @@ GlobalValue *GlobalAlias::getAliasedGlobal() {
     return GV;
 
   ConstantExpr *CE = cast<ConstantExpr>(C);
-  assert((CE->getOpcode() == Instruction::BitCast || 
+  assert((CE->getOpcode() == Instruction::BitCast ||
+          CE->getOpcode() == Instruction::AddrSpaceCast ||
           CE->getOpcode() == Instruction::GetElementPtr) &&
          "Unsupported aliasee");
   
index 35b786ecf271c5072a7107342f13eb6f3fcaf33b..44c66c9062f06e9bd49264946528e2920d8be865 100644 (file)
@@ -550,9 +550,11 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) {
     ConstantExpr *CE = dyn_cast<ConstantExpr>(Aliasee);
     Assert1(CE &&
             (CE->getOpcode() == Instruction::BitCast ||
+             CE->getOpcode() == Instruction::AddrSpaceCast ||
              CE->getOpcode() == Instruction::GetElementPtr) &&
             isa<GlobalValue>(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 (file)
index 0000000..6623a25
--- /dev/null
@@ -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)*)