Skip to content

Commit df45f00

Browse files
authored
[SYCL][NFC] Fix static code analysis concerns (#2531)
Found via a static-analysis tool: 1. Pointer 'NewDeclAttr' returned from call to function 'getAttr<clang::SYCLIntelMaxWorkGroupSizeAttr>' at line 3218 may be NULL and will be dereferenced at line 3220. 2. Pointer 'NewDeclAttr' returned from call to function 'getAttr<clang::ReqdWorkGroupSizeAttr>' at line 3218 may be NULL and will be dereferenced at line 3220. 3. Pointer 'OldDeclAttr' returned from call to function 'getAttr<clang::ReqdWorkGroupSizeAttr>' at line 3219 may be NULL and will be dereferenced at line 3220. 4. Pointer 'OldDeclAttr' returned from call to function 'getAttr<clang::SYCLIntelMaxWorkGroupSizeAttr>' at line 3219 may be NULL and will be dereferenced at line 3220. This patch fixes null pointer dereference issues in SemaDecl.cpp file by adding early return if (!NewDeclAttr || !OldDeclAttr) Signed-off-by: Soumi Manna <soumi.manna@intel.com>
1 parent efe6331 commit df45f00

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,8 +3215,12 @@ static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD,
32153215
template <typename AttributeType>
32163216
static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New,
32173217
FunctionDecl *Old) {
3218-
AttributeType *NewDeclAttr = New->getAttr<AttributeType>();
3219-
AttributeType *OldDeclAttr = Old->getAttr<AttributeType>();
3218+
const auto *NewDeclAttr = New->getAttr<AttributeType>();
3219+
const auto *OldDeclAttr = Old->getAttr<AttributeType>();
3220+
3221+
if (!NewDeclAttr || !OldDeclAttr)
3222+
return;
3223+
32203224
if ((NewDeclAttr->getXDim() != OldDeclAttr->getXDim()) ||
32213225
(NewDeclAttr->getYDim() != OldDeclAttr->getYDim()) ||
32223226
(NewDeclAttr->getZDim() != OldDeclAttr->getZDim())) {
@@ -3302,12 +3306,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
33023306
}
33033307
}
33043308

3305-
if (New->hasAttr<ReqdWorkGroupSizeAttr>() &&
3306-
Old->hasAttr<ReqdWorkGroupSizeAttr>())
33073309
checkDimensionsAndSetDiagnostics<ReqdWorkGroupSizeAttr>(*this, New, Old);
33083310

3309-
if (New->hasAttr<SYCLIntelMaxWorkGroupSizeAttr>() &&
3310-
Old->hasAttr<SYCLIntelMaxWorkGroupSizeAttr>())
33113311
checkDimensionsAndSetDiagnostics<SYCLIntelMaxWorkGroupSizeAttr>(*this, New,
33123312
Old);
33133313

0 commit comments

Comments
 (0)