Author: kzhuravl
Date: Tue Mar 21 13:55:39 2017
New Revision: 298420

URL: http://llvm.org/viewvc/llvm-project?rev=298420&view=rev
Log:
Fix array sizes where address space is not yet known

For variables in generic address spaces, for example:

```
unsigned char V[6442450944];
...
```

the address space is not yet known when we get into
*getConstantArrayType*, it is 0. AMDGCN target's
address space 0 has 32 bits pointers, so when we
call *getPointerWidth* with 0, the array size is
trimmed to 32 bits, which is not right.

Differential Revision: https://reviews.llvm.org/D30845

Added:
    cfe/trunk/test/CodeGenOpenCL/amdgcn-large-globals.cl
Modified:
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=298420&r1=298419&r2=298420&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Mar 21 13:55:39 2017
@@ -2692,8 +2692,7 @@ QualType ASTContext::getConstantArrayTyp
   // Convert the array size into a canonical width matching the pointer size 
for
   // the target.
   llvm::APInt ArySize(ArySizeIn);
-  ArySize =
-    ArySize.zextOrTrunc(Target->getPointerWidth(getTargetAddressSpace(EltTy)));
+  ArySize = ArySize.zextOrTrunc(Target->getMaxPointerWidth());
 
   llvm::FoldingSetNodeID ID;
   ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, IndexTypeQuals);

Added: cfe/trunk/test/CodeGenOpenCL/amdgcn-large-globals.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgcn-large-globals.cl?rev=298420&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/amdgcn-large-globals.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/amdgcn-large-globals.cl Tue Mar 21 13:55:39 
2017
@@ -0,0 +1,12 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -S -emit-llvm 
-o - %s | FileCheck %s
+
+// CHECK: @One = common local_unnamed_addr addrspace(1) global [6442450944 x 
i8] zeroinitializer, align 1
+unsigned char One[6442450944];
+// CHECK: @Two = common local_unnamed_addr addrspace(1) global [6442450944 x 
i32] zeroinitializer, align 4
+global unsigned int Two[6442450944];
+ 
+kernel void large_globals(unsigned int id) {
+  One[id] = id;
+  Two[id + 1] = id + 1;
+}


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to