Skip to content

Commit 823f2b2

Browse files
authored
[SYCL][NFC] Fix bug with dereference null return value (#7294)
Reported by static analyzer tool: Dereference null return value If the function actually returns a null value, a null pointer dereference will occur. In <unnamed>::SyclKernelPointerHandler::leaveArray(clang::FieldDecl *, clang::QualType, clang::QualType): Return value of function which returns null is dereferenced without checking bool leaveArray(FieldDecl *FD, QualType ArrayTy, QualType ET) final { QualType ModifiedArrayElement = ModifiedArrayElementsOrArray.pop_back_val(); // returned_null: getAsConstantArrayType returns nullptr (checked 73 out of 88 times). // var_assigned: Assigning: CAT = nullptr return value from getAsConstantArrayType. const ConstantArrayType *CAT = SemaRef.getASTContext().getAsConstantArrayType(ArrayTy); // Dereference null return value (NULL_RETURNS) // dereference: Dereferencing a pointer that might be nullptr CAT when calling getSizeExpr. QualType ModifiedArray = SemaRef.getASTContext().getConstantArrayType( ModifiedArrayElement, CAT->getSize(), const_cast<Expr *>(CAT->getSizeExpr()), CAT->getSizeModifier(), CAT->getIndexTypeCVRQualifiers()); This patch adds assert to resolve the bug. Signed-off-by: Soumi Manna <[email protected]> Signed-off-by: Soumi Manna <[email protected]>
1 parent 998fd91 commit 823f2b2

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,7 @@ class SyclKernelPointerHandler : public SyclKernelFieldHandler {
20872087

20882088
const ConstantArrayType *CAT =
20892089
SemaRef.getASTContext().getAsConstantArrayType(ArrayTy);
2090+
assert(CAT && "Should only be called on constant-size array.");
20902091
QualType ModifiedArray = SemaRef.getASTContext().getConstantArrayType(
20912092
ModifiedArrayElement, CAT->getSize(),
20922093
const_cast<Expr *>(CAT->getSizeExpr()), CAT->getSizeModifier(),

0 commit comments

Comments
 (0)