diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -18341,6 +18341,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()) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/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); diff --git a/clang/test/OpenMP/simd_null_pointer_access.cpp b/clang/test/OpenMP/simd_null_pointer_access.cpp new file mode 100644 --- /dev/null +++ b/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;