Browse Source

CUDA: give correct address space to globals declared in functions

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162787 91177308-0d34-0410-b5e6-96231b3b80d8
Peter Collingbourne 13 years ago
parent
commit
1aba7783ad
2 changed files with 7 additions and 1 deletions
  1. 3 1
      lib/CodeGen/CGDecl.cpp
  2. 4 0
      test/CodeGenCUDA/address-spaces.cu

+ 3 - 1
lib/CodeGen/CGDecl.cpp

@@ -184,12 +184,14 @@ CodeGenFunction::CreateStaticVarDecl(const VarDecl &D,
     Name = GetStaticDeclName(*this, D, Separator);
 
   llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty);
+  unsigned AddrSpace =
+   CGM.GetGlobalVarAddressSpace(&D, CGM.getContext().getTargetAddressSpace(Ty));
   llvm::GlobalVariable *GV =
     new llvm::GlobalVariable(CGM.getModule(), LTy,
                              Ty.isConstant(getContext()), Linkage,
                              CGM.EmitNullConstant(D.getType()), Name, 0,
                              llvm::GlobalVariable::NotThreadLocal,
-                             CGM.getContext().getTargetAddressSpace(Ty));
+                             AddrSpace);
   GV->setAlignment(getContext().getDeclAlign(&D).getQuantity());
   if (Linkage != llvm::GlobalValue::InternalLinkage)
     GV->setVisibility(CurFn->getVisibility());

+ 4 - 0
test/CodeGenCUDA/address-spaces.cu

@@ -20,5 +20,9 @@ __device__ void foo() {
 
   // CHECK: load i32* bitcast (i32 addrspace(3)* @k to i32*)
   k++;
+
+  static int li;
+  // CHECK: load i32 addrspace(1)* @_ZZ3foovE2li
+  li++;
 }