[llvm] r186767 - Disallow global aliases to bitcast between address spaces

Matt Arsenault Matthew.Arsenault at amd.com
Sat Jul 20 10:46:05 PDT 2013


Author: arsenm
Date: Sat Jul 20 12:46:05 2013
New Revision: 186767

URL: http://llvm.org/viewvc/llvm-project?rev=186767&view=rev
Log:
Disallow global aliases to bitcast between address spaces

Added:
    llvm/trunk/test/Verifier/bitcast-alias-address-space.ll
Modified:
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=186767&r1=186766&r2=186767&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Sat Jul 20 12:46:05 2013
@@ -498,18 +498,29 @@ void Verifier::visitGlobalAlias(GlobalAl
           "Alias and aliasee types should match!", &GA);
   Assert1(!GA.hasUnnamedAddr(), "Alias cannot have unnamed_addr!", &GA);
 
-  if (!isa<GlobalValue>(GA.getAliasee())) {
-    const ConstantExpr *CE = dyn_cast<ConstantExpr>(GA.getAliasee());
+  Constant *Aliasee = GA.getAliasee();
+
+  if (!isa<GlobalValue>(Aliasee)) {
+    ConstantExpr *CE = dyn_cast<ConstantExpr>(Aliasee);
     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);
+
+    if (CE->getOpcode() == Instruction::BitCast) {
+      unsigned SrcAS = CE->getOperand(0)->getType()->getPointerAddressSpace();
+      unsigned DstAS = CE->getType()->getPointerAddressSpace();
+
+      Assert1(SrcAS == DstAS,
+              "Alias bitcasts cannot be between different address spaces",
+              &GA);
+    }
   }
 
-  const GlobalValue* Aliasee = GA.resolveAliasedGlobal(/*stopOnWeak*/ false);
-  Assert1(Aliasee,
+  const GlobalValue* Resolved = GA.resolveAliasedGlobal(/*stopOnWeak*/ false);
+  Assert1(Resolved,
           "Aliasing chain should end with function or global variable", &GA);
 
   visitGlobalValue(GA);

Added: 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=186767&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/bitcast-alias-address-space.ll (added)
+++ llvm/trunk/test/Verifier/bitcast-alias-address-space.ll Sat Jul 20 12:46:05 2013
@@ -0,0 +1,8 @@
+; RUN: not llvm-as -verify -disable-output %s
+
+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)*)





More information about the llvm-commits mailing list