Skip to content

Commit 96bfb05

Browse files
authored
[SYCL][NFC] Fix bug with dereference null return value (#7275)
Reported by static analyzer tool. Dereference null return value: In <unnamed>::SyclKernelBodyCreator::enterArray(clang::FieldDecl *, clang::QualType, clang::QualType): Return value of function which returns null is dereferenced without checking bool enterArray(FieldDecl *FD, QualType ArrayType, QualType ElementType) final { // returned_null: getAsConstantArrayType returns nullptr // identity_transfer: Member function call this->SemaRef->getASTContext()->getAsConstantArrayType(ArrayType)->getSize() // returns an offset off this->SemaRef->getASTContext()->getAsConstantArrayType(ArrayType) (this). // Dereference null return value (NULL_RETURNS) dereference: Dereferencing a pointer that might be nullptr this->SemaRef->getASTContext()->getAsConstantArrayType(ArrayType)->getSize() when calling getZExtValue uint64_t ArraySize = SemaRef.getASTContext() .getAsConstantArrayType(ArrayType) ->getSize() .getZExtValue(); addCollectionInitListExpr(ArrayType, ArraySize); ArrayInfos.emplace_back(getFieldEntity(FD, ArrayType), 0); This patch updates the codes to resolve the bug. Signed-off-by: Soumi Manna <[email protected]> Signed-off-by: Soumi Manna <[email protected]>
1 parent a39c855 commit 96bfb05

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,10 +3497,10 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
34973497

34983498
bool enterArray(FieldDecl *FD, QualType ArrayType,
34993499
QualType ElementType) final {
3500-
uint64_t ArraySize = SemaRef.getASTContext()
3501-
.getAsConstantArrayType(ArrayType)
3502-
->getSize()
3503-
.getZExtValue();
3500+
const ConstantArrayType *CAT =
3501+
SemaRef.getASTContext().getAsConstantArrayType(ArrayType);
3502+
assert(CAT && "Should only be called on constant-size array.");
3503+
uint64_t ArraySize = CAT->getSize().getZExtValue();
35043504
addCollectionInitListExpr(ArrayType, ArraySize);
35053505
ArrayInfos.emplace_back(getFieldEntity(FD, ArrayType), 0);
35063506

0 commit comments

Comments
 (0)