Skip to content

Commit

Permalink
[SYCL][NFC] Fix static code analysis concerns (#5189)
Browse files Browse the repository at this point in the history
Found via a static-analysis tool:
Suspicious dereference of pointer in function call before NULL check

Inside checkAllowedSYCLInitializer() in SemaSYCL.cpp file:

    const Expr *Init = VD->getInit();
    bool ValueDependent = Init->isValueDependent(); --> 'Init' is dereferenced by being passed as argument 0 to function "isValueDependent
    bool isConstantInit =
       Init && !ValueDependent && Init->isConstantInitializer(Context, false);  --> 'Init' is checked for NULL here

This patch adds NULL value checking for 'Init' expression.

Signed-off-by: Soumi Manna <[email protected]>
  • Loading branch information
smanna12 authored Dec 21, 2021
1 parent a56c6e6 commit 8c5b701
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4148,7 +4148,7 @@ bool Sema::checkAllowedSYCLInitializer(VarDecl *VD) {
return true;

const Expr *Init = VD->getInit();
bool ValueDependent = Init->isValueDependent();
bool ValueDependent = Init && Init->isValueDependent();
bool isConstantInit =
Init && !ValueDependent && Init->isConstantInitializer(Context, false);
if (!VD->isConstexpr() && Init && !ValueDependent && !isConstantInit)
Expand Down

0 comments on commit 8c5b701

Please sign in to comment.