Skip to content

[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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,9 @@ 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 ||
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/Inputs/declare_target_include.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma omp declare target
#pragma omp begin declare target
void zyx();
#pragma omp end declare target
28 changes: 14 additions & 14 deletions clang/test/OpenMP/declare_target_ast_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand All @@ -144,15 +144,15 @@ 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()
#pragma omp end declare target
// 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()
Expand All @@ -161,15 +161,15 @@ 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()
#pragma omp end declare target
// 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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
24 changes: 12 additions & 12 deletions clang/test/OpenMP/declare_target_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -156,15 +156,15 @@ 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

template<>
float bla2() { return 1.0; }

#pragma omp declare target
#pragma omp begin declare target
void blub2() {
bla2<float>();
bla2<int>();
Expand All @@ -179,7 +179,7 @@ void t2() {
}
}

#pragma omp declare target
#pragma omp begin declare target
void abc();
#pragma omp end declare target
void cba();
Expand All @@ -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;
Expand Down Expand Up @@ -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);}();
Expand All @@ -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
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();}
Expand Down Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/target_ast_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down