]> granicus.if.org Git - clang/commitdiff
CUDA: give correct address space to globals declared in functions
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 28 Aug 2012 20:37:10 +0000 (20:37 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 28 Aug 2012 20:37:10 +0000 (20:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162787 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGenCUDA/address-spaces.cu

index 35d1a623a833b5084ee87aae998306281290d71c..b9489e3f0409b02cb0ac29e655ce88e026420f54 100644 (file)
@@ -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());
index 61d4d6b6ba48d89cb5ce7bbd3d2bf07479396bce..15e49205b6aba15d299fd9b54fceba7f65cc769c 100644 (file)
@@ -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++;
 }