diff options
| author | Konstantin Zhuravlyov <kzhuravl_dev@outlook.com> | 2017-03-21 18:55:39 +0000 |
|---|---|---|
| committer | Konstantin Zhuravlyov <kzhuravl_dev@outlook.com> | 2017-03-21 18:55:39 +0000 |
| commit | 9c1e310c16659deb3984df16376263471a129400 (patch) | |
| tree | ba221a00d452e66ce5f7692587f8e9801b797d00 | |
| parent | ed44af6c61709cce5eb0144aea2f1053c8e4bca9 (diff) | |
| download | bcm5719-llvm-9c1e310c16659deb3984df16376263471a129400.tar.gz bcm5719-llvm-9c1e310c16659deb3984df16376263471a129400.zip | |
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
llvm-svn: 298420
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 3 | ||||
| -rw-r--r-- | clang/test/CodeGenOpenCL/amdgcn-large-globals.cl | 12 |
2 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e8f98929de6..071537a051c 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2692,8 +2692,7 @@ QualType ASTContext::getConstantArrayType(QualType EltTy, // 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); diff --git a/clang/test/CodeGenOpenCL/amdgcn-large-globals.cl b/clang/test/CodeGenOpenCL/amdgcn-large-globals.cl new file mode 100644 index 00000000000..ea9ea618a48 --- /dev/null +++ b/clang/test/CodeGenOpenCL/amdgcn-large-globals.cl @@ -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; +} |

