[PATCH] D97573: [OpenMP] Handle non-function context before checking for diagnostic emission
PremAnand Rao via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 26 12:30:20 PST 2021
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>())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97573.326768.patch
Type: text/x-patch
Size: 2577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210226/11e98e34/attachment.bin>
More information about the cfe-commits
mailing list