Skip to content

Commit 9fe0bd6

Browse files
authored
[SYCL] Fix static code analysis concerns in processSYCLKernel (#2976)
Found via a static-analysis tool inside processSYCLKernel(): Pointer 'CRD' returned from call to function 'getPointeeCXXRecordDecl' may be NULL at line below: const CXXRecordDecl *CRD = (KernelParamTy->isReferenceType() ? KernelParamTy->getPointeeCXXRecordDecl() : KernelParamTy->getAsCXXRecordDecl()); for (auto *Method : CRD->methods()) --> will be dereferenced here This patch fixes null pointer dereference issue inside SemaTemplateInstantiateDecl.cpp file. Signed-off-by: Soumi Manna <[email protected]>
1 parent 156eaaa commit 9fe0bd6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6297,6 +6297,12 @@ static void processSYCLKernel(Sema &S, FunctionDecl *FD, MangleContext &MC) {
62976297
const CXXRecordDecl *CRD = (KernelParamTy->isReferenceType()
62986298
? KernelParamTy->getPointeeCXXRecordDecl()
62996299
: KernelParamTy->getAsCXXRecordDecl());
6300+
if (!CRD) {
6301+
S.Diag(FD->getLocation(), diag::err_sycl_kernel_not_function_object);
6302+
FD->setInvalidDecl();
6303+
return;
6304+
}
6305+
63006306
for (auto *Method : CRD->methods())
63016307
if (Method->getOverloadedOperator() == OO_Call &&
63026308
!Method->hasAttr<AlwaysInlineAttr>())

clang/test/SemaSYCL/kernel-not-functor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fsycl -fsycl-is-host -fsyntax-only -verify %s
23

34
template <typename Name, typename F>
45
__attribute__((sycl_kernel)) void kernel(F kernelFunc) {

0 commit comments

Comments
 (0)