| 
 | 1 | +From 523775f96742e6f099b3498b6606b7250c0af841 Mon Sep 17 00:00:00 2001  | 
 | 2 | +From: Sven van Haastregt < [email protected]>  | 
 | 3 | +Date: Tue, 1 Dec 2020 11:33:10 +0000  | 
 | 4 | +Subject: [PATCH] [OpenCL] Allow pointer-to-pointer kernel args beyond CL 1.2  | 
 | 5 | + | 
 | 6 | +The restriction on pointer-to-pointer kernel arguments has been  | 
 | 7 | +relaxed in OpenCL 2.0.  Apply the same address space restrictions for  | 
 | 8 | +pointer argument types to the inner pointer types.  | 
 | 9 | + | 
 | 10 | +Differential Revision: https://reviews.llvm.org/D92091  | 
 | 11 | +---  | 
 | 12 | + clang/lib/Sema/SemaDecl.cpp                   | 29 ++++++++++++++-----  | 
 | 13 | + .../SemaOpenCL/invalid-kernel-parameters.cl   | 17 ++++++++++-  | 
 | 14 | + 2 files changed, 38 insertions(+), 8 deletions(-)  | 
 | 15 | + | 
 | 16 | +/*========================== begin_copyright_notice ============================  | 
 | 17 | + | 
 | 18 | +Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.  | 
 | 19 | +See https://llvm.org/LICENSE.txt for license information.  | 
 | 20 | +SPDX-License-Identifier: Apache-2.0 with LLVM-exception  | 
 | 21 | + | 
 | 22 | +============================= end_copyright_notice ===========================*/  | 
 | 23 | + | 
 | 24 | +diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp  | 
 | 25 | +index 9c282a73e0ed..2116b3f7b78e 100644  | 
 | 26 | +--- a/clang/lib/Sema/SemaDecl.cpp  | 
 | 27 | ++++ b/clang/lib/Sema/SemaDecl.cpp  | 
 | 28 | +@@ -8591,12 +8591,21 @@ static bool isOpenCLSizeDependentType(ASTContext &C, QualType Ty) {  | 
 | 29 | + static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT) {  | 
 | 30 | +   if (PT->isPointerType()) {  | 
 | 31 | +     QualType PointeeType = PT->getPointeeType();  | 
 | 32 | +-    if (PointeeType->isPointerType())  | 
 | 33 | +-      return PtrPtrKernelParam;  | 
 | 34 | +     if (PointeeType.getAddressSpace() == LangAS::opencl_generic ||  | 
 | 35 | +         PointeeType.getAddressSpace() == LangAS::opencl_private ||  | 
 | 36 | +         PointeeType.getAddressSpace() == LangAS::Default)  | 
 | 37 | +       return InvalidAddrSpacePtrKernelParam;  | 
 | 38 | ++  | 
 | 39 | ++    if (PointeeType->isPointerType()) {  | 
 | 40 | ++      // This is a pointer to pointer parameter.  | 
 | 41 | ++      // Recursively check inner type.  | 
 | 42 | ++      OpenCLParamType ParamKind = getOpenCLKernelParameterType(S, PointeeType);  | 
 | 43 | ++      if (ParamKind == InvalidAddrSpacePtrKernelParam ||  | 
 | 44 | ++          ParamKind == InvalidKernelParam)  | 
 | 45 | ++        return ParamKind;  | 
 | 46 | ++  | 
 | 47 | ++      return PtrPtrKernelParam;  | 
 | 48 | ++    }  | 
 | 49 | +     return PtrKernelParam;  | 
 | 50 | +   }  | 
 | 51 | +   | 
 | 52 | +@@ -8649,11 +8658,17 @@ static void checkIsValidOpenCLKernelParameter(  | 
 | 53 | +   | 
 | 54 | +   switch (getOpenCLKernelParameterType(S, PT)) {  | 
 | 55 | +   case PtrPtrKernelParam:  | 
 | 56 | +-    // OpenCL v1.2 s6.9.a:  | 
 | 57 | +-    // A kernel function argument cannot be declared as a  | 
 | 58 | +-    // pointer to a pointer type.  | 
 | 59 | +-    S.Diag(Param->getLocation(), diag::err_opencl_ptrptr_kernel_param);  | 
 | 60 | +-    D.setInvalidType();  | 
 | 61 | ++    // OpenCL v3.0 s6.11.a:  | 
 | 62 | ++    // A kernel function argument cannot be declared as a pointer to a pointer  | 
 | 63 | ++    // type. [...] This restriction only applies to OpenCL C 1.2 or below.  | 
 | 64 | ++    if (S.getLangOpts().OpenCLVersion < 120 &&  | 
 | 65 | ++        !S.getLangOpts().OpenCLCPlusPlus) {  | 
 | 66 | ++      S.Diag(Param->getLocation(), diag::err_opencl_ptrptr_kernel_param);  | 
 | 67 | ++      D.setInvalidType();  | 
 | 68 | ++      return;  | 
 | 69 | ++    }  | 
 | 70 | ++  | 
 | 71 | ++    ValidTypes.insert(PT.getTypePtr());  | 
 | 72 | +     return;  | 
 | 73 | +   | 
 | 74 | +   case InvalidAddrSpacePtrKernelParam:  | 
0 commit comments