pmrao created this revision. pmrao added reviewers: ABataev, bader, erichkeane, jdoerfert. Herald added subscribers: guansong, yaxunl. pmrao requested review of this revision. Herald added a subscriber: sstefan1. Herald added a project: clang.
Ensure that we are in a function declaration context before checking the diagnostic emission status, to avoid dereferencing a NULL function declaration. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D97573 Files: clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/simd_null_pointer_access.cpp Index: clang/test/OpenMP/simd_null_pointer_access.cpp =================================================================== --- /dev/null +++ clang/test/OpenMP/simd_null_pointer_access.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fopenmp-simd -fsycl -fsycl-is-device -triple spir64 -verify -fsyntax-only %s + +// Test that in the presence of SYCL options, that null function +// declarations are accounted for when checking to emit diagnostics. + +// expected-no-diagnostics + +__thread void *x; Index: clang/lib/Sema/SemaOpenMP.cpp =================================================================== --- clang/lib/Sema/SemaOpenMP.cpp +++ clang/lib/Sema/SemaOpenMP.cpp @@ -1939,20 +1939,23 @@ FunctionDecl *FD) { assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && "Expected OpenMP host compilation."); - FunctionEmissionStatus FES = getEmissionStatus(FD); + SemaDiagnosticBuilder::Kind Kind = SemaDiagnosticBuilder::K_Nop; - switch (FES) { - case FunctionEmissionStatus::Emitted: - Kind = SemaDiagnosticBuilder::K_Immediate; - break; - case FunctionEmissionStatus::Unknown: - Kind = SemaDiagnosticBuilder::K_Deferred; - break; - case FunctionEmissionStatus::TemplateDiscarded: - case FunctionEmissionStatus::OMPDiscarded: - case FunctionEmissionStatus::CUDADiscarded: - Kind = SemaDiagnosticBuilder::K_Nop; - break; + if (FD) { + FunctionEmissionStatus FES = getEmissionStatus(FD); + switch (FES) { + case FunctionEmissionStatus::Emitted: + Kind = SemaDiagnosticBuilder::K_Immediate; + break; + case FunctionEmissionStatus::Unknown: + Kind = SemaDiagnosticBuilder::K_Deferred; + break; + case FunctionEmissionStatus::TemplateDiscarded: + case FunctionEmissionStatus::OMPDiscarded: + case FunctionEmissionStatus::CUDADiscarded: + Kind = SemaDiagnosticBuilder::K_Nop; + break; + } } return SemaDiagnosticBuilder(Kind, Loc, DiagID, FD, *this); Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -18339,6 +18339,8 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD, bool Final) { + assert(FD && "Expected non-null FunctionDecl"); + // SYCL functions can be template, so we check if they have appropriate // attribute prior to checking if it is a template. if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelAttr>())
Index: clang/test/OpenMP/simd_null_pointer_access.cpp =================================================================== --- /dev/null +++ clang/test/OpenMP/simd_null_pointer_access.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fopenmp-simd -fsycl -fsycl-is-device -triple spir64 -verify -fsyntax-only %s + +// Test that in the presence of SYCL options, that null function +// declarations are accounted for when checking to emit diagnostics. + +// expected-no-diagnostics + +__thread void *x; Index: clang/lib/Sema/SemaOpenMP.cpp =================================================================== --- clang/lib/Sema/SemaOpenMP.cpp +++ clang/lib/Sema/SemaOpenMP.cpp @@ -1939,20 +1939,23 @@ FunctionDecl *FD) { assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && "Expected OpenMP host compilation."); - FunctionEmissionStatus FES = getEmissionStatus(FD); + SemaDiagnosticBuilder::Kind Kind = SemaDiagnosticBuilder::K_Nop; - switch (FES) { - case FunctionEmissionStatus::Emitted: - Kind = SemaDiagnosticBuilder::K_Immediate; - break; - case FunctionEmissionStatus::Unknown: - Kind = SemaDiagnosticBuilder::K_Deferred; - break; - case FunctionEmissionStatus::TemplateDiscarded: - case FunctionEmissionStatus::OMPDiscarded: - case FunctionEmissionStatus::CUDADiscarded: - Kind = SemaDiagnosticBuilder::K_Nop; - break; + if (FD) { + FunctionEmissionStatus FES = getEmissionStatus(FD); + switch (FES) { + case FunctionEmissionStatus::Emitted: + Kind = SemaDiagnosticBuilder::K_Immediate; + break; + case FunctionEmissionStatus::Unknown: + Kind = SemaDiagnosticBuilder::K_Deferred; + break; + case FunctionEmissionStatus::TemplateDiscarded: + case FunctionEmissionStatus::OMPDiscarded: + case FunctionEmissionStatus::CUDADiscarded: + Kind = SemaDiagnosticBuilder::K_Nop; + break; + } } return SemaDiagnosticBuilder(Kind, Loc, DiagID, FD, *this); Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -18339,6 +18339,8 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD, bool Final) { + assert(FD && "Expected non-null FunctionDecl"); + // SYCL functions can be template, so we check if they have appropriate // attribute prior to checking if it is a template. if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelAttr>())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits