summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2019-08-21 07:33:40 +0000
committerHans Wennborg <hans@hanshq.net>2019-08-21 07:33:40 +0000
commit20170d09023b802bdb378f8c65c78742d0a0ca74 (patch)
tree09a81376aa7671a307d791b7b1a8bd314f92c657
parent116ea3bb7a5fadc78fec76e9449013902bf19242 (diff)
Merging r369251:
------------------------------------------------------------------------ r369251 | stulova | 2019-08-19 13:43:16 +0200 (Mon, 19 Aug 2019) | 10 lines [OpenCL] Fix addr space deduction for pointers/references to arrays. Rewrite the logic for detecting if we are deducing addr space of a pointee type to take into account special logic for arrays. For pointers/references to arrays we can have any number of parentheses expressions as well as nested pointers. Differential Revision: https://reviews.llvm.org/D66137 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_90@369499 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaType.cpp18
-rw-r--r--test/SemaOpenCLCXX/address-space-deduction.cl22
2 files changed, 38 insertions, 2 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 29acf6177e..2b9d06814d 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -7390,8 +7390,22 @@ static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State,
bool IsPointee =
ChunkIndex > 0 &&
(D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer ||
- D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer ||
- D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference);
+ D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference ||
+ D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer);
+ // For pointers/references to arrays the next chunk is always an array
+ // followed by any number of parentheses.
+ if (!IsPointee && ChunkIndex > 1) {
+ auto AdjustedCI = ChunkIndex - 1;
+ if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Array)
+ AdjustedCI--;
+ // Skip over all parentheses.
+ while (AdjustedCI > 0 &&
+ D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Paren)
+ AdjustedCI--;
+ if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Pointer ||
+ D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Reference)
+ IsPointee = true;
+ }
bool IsFuncReturnType =
ChunkIndex > 0 &&
D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function;
diff --git a/test/SemaOpenCLCXX/address-space-deduction.cl b/test/SemaOpenCLCXX/address-space-deduction.cl
index 0b64b5cdec..ac6b2cabbd 100644
--- a/test/SemaOpenCLCXX/address-space-deduction.cl
+++ b/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -78,3 +78,25 @@ __kernel void test() {
int foo[10];
xxx(&foo[0]);
}
+
+// Addr space for pointer/reference to an array
+//CHECK: FunctionDecl {{.*}} t1 'void (const __generic float (&)[2])'
+void t1(const float (&fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t2 'void (const __generic float (*)[2])'
+void t2(const float (*fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t3 'void (__generic float (((*)))[2])'
+void t3(float(((*fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t4 'void (__generic float (((*__generic *)))[2])'
+void t4(float(((**fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t5 'void (__generic float (*__generic (*))[2])'
+void t5(float (*(*fYZ))[2]);
+
+__kernel void k() {
+ __local float x[2];
+ __local float(*p)[2];
+ t1(x);
+ t2(&x);
+ t3(&x);
+ t4(&p);
+ t5(&p);
+}