Skip to content

Commit

Permalink
[SYCL][NFC] Fix Static Analyzer bugs (intel#14349)
Browse files Browse the repository at this point in the history
This patch fixes two possible null pointer dereferences issues:

1. In CodeGenModule::Release(): Dereferencing a pointer that might be
       nullptr RD->getAttr() when calling getAspectsMD().

    2. In Sema::ActOnFinishFunctionBody(): Passing null pointer FD to
       hasAttr, which dereferences it.

Signed-off-by: Soumi Manna <soumi.manna@intel.com>

---------

Signed-off-by: Soumi Manna <soumi.manna@intel.com>
  • Loading branch information
smanna12 authored Jul 1, 2024
1 parent bdd9437 commit 2ac6184
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,9 +1380,9 @@ void CodeGenModule::Release() {
for (const auto &Type : TypesWithAspects) {
StringRef Name = Type.first;
const RecordDecl *RD = Type.second;
AspectsMD->addOperand(getAspectsMD(Context, TheModule.getContext(),
Name,
RD->getAttr<SYCLUsesAspectsAttr>()));
if (const auto *Attr = RD->getAttr<SYCLUsesAspectsAttr>())
AspectsMD->addOperand(
getAspectsMD(Context, TheModule.getContext(), Name, Attr));
}
}

Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16542,16 +16542,19 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
DiscardCleanupsInEvaluationContext();
}

if (FD && ((LangOpts.OpenMP && (LangOpts.OpenMPIsTargetDevice ||
!LangOpts.OMPTargetTriples.empty())) ||
LangOpts.CUDA || LangOpts.SYCLIsDevice)) {
if (!FD)
return dcl;

if ((LangOpts.OpenMP &&
(LangOpts.OpenMPIsTargetDevice || !LangOpts.OMPTargetTriples.empty())) ||
LangOpts.CUDA || LangOpts.SYCLIsDevice) {
auto ES = getEmissionStatus(FD);
if (ES == Sema::FunctionEmissionStatus::Emitted ||
ES == Sema::FunctionEmissionStatus::Unknown)
DeclsToCheckForDeferredDiags.insert(FD);
}

if (FD && !FD->isDeleted())
if (!FD->isDeleted())
checkTypeSupport(FD->getType(), FD->getLocation(), FD);

// Handle free functions.
Expand Down

0 comments on commit 2ac6184

Please sign in to comment.