Skip to content

Commit e1d8db7

Browse files
authored
[SYCL][NFC] Fix static code analysis concerns (#2789)
Found via a static-analysis tool: 1. Inside leaveStruct() RecordDecl *RD = Ty->getAsRecordDecl(); ---> Pointer 'RD' may be NULL if (!RD->hasAttr<SYCLRequiresDecompositionAttr>()) ----> will be dereferenced here 2. Inside visitRecord() function, Pointer 'RecordTy->getAsRecordDecl()' returned from call to function 'getAsRecordDecl' at line “if (RecordTy->getAsRecordDecl()->hasAttr<SYCLRequiresDecompositionAttr>()) {“ may be NULL and will be dereferenced at same line. This patch fixes null pointer dereference issues in SemaSYCL.cpp file. Signed-off-by: Soumi Manna <[email protected]>
1 parent 4d15c28 commit e1d8db7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,9 @@ void KernelObjVisitor::visitRecord(const CXXRecordDecl *Owner, ParentTy &Parent,
12141214
const CXXRecordDecl *Wrapper,
12151215
QualType RecordTy,
12161216
HandlerTys &... Handlers) {
1217-
if (RecordTy->getAsRecordDecl()->hasAttr<SYCLRequiresDecompositionAttr>()) {
1217+
RecordDecl *RD = RecordTy->getAsRecordDecl();
1218+
assert(RD && "should not be null.");
1219+
if (RD->hasAttr<SYCLRequiresDecompositionAttr>()) {
12181220
// If this container requires decomposition, we have to visit it as
12191221
// 'complex', so all handlers are called in this case with the 'complex'
12201222
// case.
@@ -1583,6 +1585,7 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
15831585
bool leaveStruct(const CXXRecordDecl *, FieldDecl *, QualType Ty) final {
15841586
if (CollectionStack.pop_back_val()) {
15851587
RecordDecl *RD = Ty->getAsRecordDecl();
1588+
assert(RD && "should not be null.");
15861589
if (!RD->hasAttr<SYCLRequiresDecompositionAttr>())
15871590
RD->addAttr(SYCLRequiresDecompositionAttr::CreateImplicit(
15881591
SemaRef.getASTContext()));
@@ -1601,6 +1604,7 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
16011604
QualType Ty) final {
16021605
if (CollectionStack.pop_back_val()) {
16031606
RecordDecl *RD = Ty->getAsRecordDecl();
1607+
assert(RD && "should not be null.");
16041608
if (!RD->hasAttr<SYCLRequiresDecompositionAttr>())
16051609
RD->addAttr(SYCLRequiresDecompositionAttr::CreateImplicit(
16061610
SemaRef.getASTContext()));

0 commit comments

Comments
 (0)