[clang] ba3f853 - [OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'
Mike Rice via cfe-commits
cfe-commits at lists.llvm.org
Wed May 25 10:34:28 PDT 2022
Author: Mike Rice
Date: 2022-05-25T10:34:07-07:00
New Revision: ba3f85390bde10eab1cbdb68f744b8f5ab31859b
URL: https://github.com/llvm/llvm-project/commit/ba3f85390bde10eab1cbdb68f744b8f5ab31859b
DIFF: https://github.com/llvm/llvm-project/commit/ba3f85390bde10eab1cbdb68f744b8f5ab31859b.diff
LOG: [OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'
Warns when end-of-file is reached without seeing all matching
'omp end declare target' directives. The diagnostic shows the
location of the related begin directive.
Differential Revision: https://reviews.llvm.org/D126331
Added:
clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_target_messages.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2969e24e3baf8..6dfe5af6ecfa3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11001,6 +11001,9 @@ def err_omp_append_args_with_varargs : Error<
"'append_args' is not allowed with varargs functions">;
def err_openmp_vla_in_task_untied : Error<
"variable length arrays are not supported in OpenMP tasking regions with 'untied' clause">;
+def warn_omp_unterminated_declare_target : Warning<
+ "expected '#pragma omp end declare target' at end of file to match '#pragma omp %0'">,
+ InGroup<SourceUsesOpenMP>;
} // end of OpenMP category
let CategoryName = "Related Result Type Issue" in {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9cbbeadc3d74b..bd7a809e40474 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10769,6 +10769,10 @@ class Sema final {
/// encountered.
void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);
+ /// Report unterminated 'omp declare target' or 'omp begin declare target' at
+ /// the end of a compilation unit.
+ void DiagnoseUnterminatedOpenMPDeclareTarget();
+
/// Searches for the provided declaration name for OpenMP declare target
/// directive.
NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope,
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index ce104f377730c..ad2cb62a18f0c 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1157,6 +1157,7 @@ void Sema::ActOnEndOfTranslationUnit() {
DiagnoseUnterminatedPragmaAlignPack();
DiagnoseUnterminatedPragmaAttribute();
+ DiagnoseUnterminatedOpenMPDeclareTarget();
// All delayed member exception specs should be checked or we end up accepting
// incompatible declarations.
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 1fdb7df1feea4..fdb7658f77bda 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -22101,6 +22101,14 @@ void Sema::ActOnFinishedOpenMPDeclareTargetContext(
ActOnOpenMPDeclareTargetName(It.first, It.second.Loc, It.second.MT, DTCI);
}
+void Sema::DiagnoseUnterminatedOpenMPDeclareTarget() {
+ if (DeclareTargetNesting.empty())
+ return;
+ DeclareTargetContextInfo &DTCI = DeclareTargetNesting.back();
+ Diag(DTCI.Loc, diag::warn_omp_unterminated_declare_target)
+ << getOpenMPDirectiveName(DTCI.Kind);
+}
+
NamedDecl *Sema::lookupOpenMPDeclareTargetName(Scope *CurScope,
CXXScopeSpec &ScopeSpec,
const DeclarationNameInfo &Id) {
diff --git a/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h b/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
new file mode 100644
index 0000000000000..ddb60d562de15
--- /dev/null
+++ b/clang/test/OpenMP/Inputs/unterminated_declare_target_include.h
@@ -0,0 +1,3 @@
+// expected-warning at +1 {{expected '#pragma omp end declare target' at end of file to match '#pragma omp declare target'}}
+#pragma omp declare target
+void zxy();
diff --git a/clang/test/OpenMP/declare_target_messages.cpp b/clang/test/OpenMP/declare_target_messages.cpp
index 31185881e192b..7e7cc60e75e35 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -6,6 +6,9 @@
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5,host5 -fopenmp-simd -fopenmp-is-device -fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 -o - %s
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -DTESTEND=1 -o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -I%S/Inputs -DTESTENDINC=1 -o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5 -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
@@ -228,5 +231,12 @@ int MultiDevTy;
#pragma omp declare target to(MultiDevTy) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} omp5-error {{'device_type(host)' does not match previously specified 'device_type(any)' for the same declaration}} omp51-error {{'device_type(host)' does not match previously specified 'device_type(any)' for the same declaration}}
#pragma omp declare target to(MultiDevTy) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} omp5-error {{'device_type(nohost)' does not match previously specified 'device_type(any)' for the same declaration}} // omp51-error {{'device_type(nohost)' does not match previously specified 'device_type(any)' for the same declaration}}
-// TODO: Issue an error message error {{expected '#pragma omp end declare target'}} note {{to match this '#pragma omp declare target'}}
+#if TESTENDINC
+#include "unterminated_declare_target_include.h"
+#elif TESTEND
+// expected-warning at +1 {{expected '#pragma omp end declare target' at end of file to match '#pragma omp declare target'}}
#pragma omp declare target
+#else
+// expected-warning at +1 {{expected '#pragma omp end declare target' at end of file to match '#pragma omp begin declare target'}}
+#pragma omp begin declare target
+#endif
More information about the cfe-commits
mailing list