-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[OpenMP-5.2] deprecate delimited form of 'declare target' #145854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang Author: Urvi Rav (ravurvi20) ChangesAccording to OpenMP 5.2 (Section 7.8.2), the directive name
Full diff: https://github.com/llvm/llvm-project/pull/145854.diff 6 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6c30da376dafb..3b55980f57c03 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1571,6 +1571,9 @@ def err_omp_declare_target_multiple : Error<
"%0 appears multiple times in clauses on the same declare target directive">;
def err_omp_declare_target_indirect_device_type: Error<
"only 'device_type(any)' clause is allowed with indirect clause">;
+def warn_omp_deprecated_declare_target_delimited_form :
+ Warning<"the delimited form of '#pragma omp declare target' without clauses is deprecated; use '#pragma omp begin declare target' instead">,
+ InGroup<Deprecated>;
def err_omp_expected_clause: Error<
"expected at least one clause on '#pragma omp %0' directive">;
def err_omp_mapper_illegal_identifier : Error<
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index f694ae1d0d112..d7efc0bb8bc90 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2309,6 +2309,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
SourceLocation DTLoc = ConsumeAnyToken();
bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
SemaOpenMP::DeclareTargetContextInfo DTCI(DKind, DTLoc);
+ if (DKind == OMPD_declare_target && !HasClauses && getLangOpts().OpenMP >= 52)
+ Diag(DTLoc, diag::warn_omp_deprecated_declare_target_delimited_form);
if (HasClauses)
ParseOMPDeclareTargetClauses(DTCI);
bool HasImplicitMappings = DKind == OMPD_begin_declare_target ||
diff --git a/clang/test/OpenMP/Inputs/declare_target_include.h b/clang/test/OpenMP/Inputs/declare_target_include.h
index b74cd00819db3..6a6a01ab81526 100644
--- a/clang/test/OpenMP/Inputs/declare_target_include.h
+++ b/clang/test/OpenMP/Inputs/declare_target_include.h
@@ -1,3 +1,3 @@
-#pragma omp declare target
+#pragma omp begin declare target
void zyx();
#pragma omp end declare target
diff --git a/clang/test/OpenMP/declare_target_ast_print.cpp b/clang/test/OpenMP/declare_target_ast_print.cpp
index 27d7a9fe21e52..68f73d5433595 100644
--- a/clang/test/OpenMP/declare_target_ast_print.cpp
+++ b/clang/test/OpenMP/declare_target_ast_print.cpp
@@ -133,7 +133,7 @@ int out_decl_target = 0;
// CHECK: void lambda()
// CHECK: #pragma omp end declare target{{$}}
-#pragma omp declare target
+#pragma omp begin declare target
void lambda () {
#ifdef __cpp_lambdas
(void)[&] { ++out_decl_target; };
@@ -144,7 +144,7 @@ void lambda () {
};
#pragma omp end declare target
-#pragma omp declare target
+#pragma omp begin declare target
// CHECK: #pragma omp declare target{{$}}
void foo() {}
// CHECK-NEXT: void foo()
@@ -152,7 +152,7 @@ void foo() {}
// CHECK: #pragma omp end declare target{{$}}
extern "C" {
-#pragma omp declare target
+#pragma omp begin declare target
// CHECK: #pragma omp declare target
void foo_c() {}
// CHECK-NEXT: void foo_c()
@@ -161,7 +161,7 @@ void foo_c() {}
}
extern "C++" {
-#pragma omp declare target
+#pragma omp begin declare target
// CHECK: #pragma omp declare target
void foo_cpp() {}
// CHECK-NEXT: void foo_cpp()
@@ -169,7 +169,7 @@ void foo_cpp() {}
// CHECK: #pragma omp end declare target
}
-#pragma omp declare target
+#pragma omp begin declare target
template <class T>
struct C {
// CHECK: template <class T> struct C {
@@ -262,7 +262,7 @@ int c1, c2, c3;
// CHECK: #pragma omp end declare target{{$}}
struct SSSt {
-#pragma omp declare target
+#pragma omp begin declare target
static int a;
int b;
#pragma omp end declare target
@@ -276,7 +276,7 @@ struct SSSt {
template <class T>
struct SSSTt {
-#pragma omp declare target
+#pragma omp begin declare target
static T a;
int b;
#pragma omp end declare target
@@ -288,7 +288,7 @@ struct SSSTt {
// CHECK: #pragma omp end declare target
// CHECK: int b;
-#pragma omp declare target
+#pragma omp begin declare target
template <typename T>
T baz() { return T(); }
#pragma omp end declare target
@@ -310,7 +310,7 @@ int baz() { return 1; }
// CHECK: }
// CHECK: #pragma omp end declare target
-#pragma omp declare target
+#pragma omp begin declare target
#include "declare_target_include.h"
void xyz();
#pragma omp end declare target
@@ -322,8 +322,8 @@ int baz() { return 1; }
// CHECK: void xyz();
// CHECK: #pragma omp end declare target
-#pragma omp declare target
- #pragma omp declare target
+#pragma omp begin declare target
+ #pragma omp begin declare target
void abc();
#pragma omp end declare target
void cba();
@@ -336,7 +336,7 @@ int baz() { return 1; }
// CHECK: void cba();
// CHECK: #pragma omp end declare target
-#pragma omp declare target
+#pragma omp begin declare target
int abc1() { return 1; }
#if _OPENMP >= 202111
#pragma omp declare target enter(abc1) device_type(nohost)
@@ -352,7 +352,7 @@ int abc1() { return 1; }
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp end declare target
-#pragma omp declare target
+#pragma omp begin declare target
int inner_link;
#pragma omp declare target link(inner_link)
#pragma omp end declare target
@@ -396,7 +396,7 @@ int main (int argc, char **argv) {
// CHECK-NEXT: #pragma omp end declare target
// Do not expect anything here since the region is empty.
-#pragma omp declare target
+#pragma omp begin declare target
#pragma omp end declare target
#endif
diff --git a/clang/test/OpenMP/declare_target_messages.cpp b/clang/test/OpenMP/declare_target_messages.cpp
index 4aa4d686eaaf3..26c47ecfb36b0 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -53,7 +53,7 @@ __thread int t;
// omp52-error@+2 {{expected '(' after 'declare target'}}
// omp45-to-51-error@+1 {{expected '(' after 'declare target'}}
#pragma omp declare target .
-
+// omp52-or-later-warning@+1 {{the delimited form of '#pragma omp declare target' without clauses is deprecated; use '#pragma omp begin declare target' instead}}
#pragma omp declare target
void f();
// omp60-warning@+3 {{extra tokens at the end of '#pragma omp end declare_target' are ignored}}
@@ -156,7 +156,7 @@ typedef int sint;
template <typename T>
T bla1() { return 0; }
-#pragma omp declare target
+#pragma omp begin declare target
template <typename T>
T bla2() { return 0; }
#pragma omp end declare target
@@ -164,7 +164,7 @@ T bla2() { return 0; }
template<>
float bla2() { return 1.0; }
-#pragma omp declare target
+#pragma omp begin declare target
void blub2() {
bla2<float>();
bla2<int>();
@@ -179,7 +179,7 @@ void t2() {
}
}
-#pragma omp declare target
+#pragma omp begin declare target
void abc();
#pragma omp end declare target
void cba();
@@ -188,13 +188,13 @@ void cba();
// omp45-to-51-error@+1 {{unexpected OpenMP directive '#pragma omp end declare target'}}
#pragma omp end declare target
-#pragma omp declare target
-#pragma omp declare target
+#pragma omp begin declare target
+#pragma omp begin declare target
void def();
#pragma omp end declare target
void fed();
-#pragma omp declare target
+#pragma omp begin declare target
// expected-note@+1 {{defined as threadprivate or thread local}}
#pragma omp threadprivate(a)
extern int b;
@@ -239,7 +239,7 @@ void foo(int p) {
q();
c();
}
-#pragma omp declare target
+#pragma omp begin declare target
void foo1() {
// omp5-or-later-var-note@+1 {{variable 'z' is captured here}}
[&](){ (void)(b+z);}();
@@ -258,7 +258,7 @@ int C::method() {
}
struct S {
-#pragma omp declare target
+#pragma omp begin declare target
int v;
#pragma omp end declare target
};
@@ -293,7 +293,7 @@ int main (int argc, char **argv) {
}
namespace {
-#pragma omp declare target
+#pragma omp begin declare target
int x;
}
#pragma omp end declare target
@@ -347,7 +347,7 @@ void host3() {host1();} // dev5-error {{function with 'device_type(host)' is not
// omp52-or-later-error@+1 {{expected at least one 'enter', 'link' or 'indirect' clause}}
#pragma omp declare target to(host3)
-#pragma omp declare target
+#pragma omp begin declare target
void any1() {any();}
// dev5-error@+1 {{function with 'device_type(host)' is not available on device}}
void any2() {host1();}
@@ -411,7 +411,7 @@ struct target{
// expected-warning@+1 {{declaration is not declared in any declare target region}}
static target S;
-#pragma omp declare target
+#pragma omp begin declare target
// expected-note@+1 {{used here}}
int target_var = variable;
// expected-note@+1 {{used here}}
diff --git a/clang/test/OpenMP/target_ast_print.cpp b/clang/test/OpenMP/target_ast_print.cpp
index ec6cf2130d7a5..db838f30511ab 100644
--- a/clang/test/OpenMP/target_ast_print.cpp
+++ b/clang/test/OpenMP/target_ast_print.cpp
@@ -367,7 +367,7 @@ extern const omp_allocator_handle_t omp_thread_mem_alloc;
void foo() {}
-#pragma omp declare target
+#pragma omp begin declare target
void bar() {}
#pragma omp end declare target
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
986ba4f
to
d78360e
Compare
According to OpenMP 5.2 (Section 7.8.2), the directive name
declare target
may be used as a synonym forbegin declare target
only when no clauses are specified. This clause-less delimited form is now deprecated and should emit a deprecation warning.