Skip to content

Commit 8055c0f

Browse files
ravurvi20urvi-rav
andauthored
[OpenMP-5.2] deprecate delimited form of 'declare target' (#145854)
According to OpenMP 5.2 (Section 7.8.2), the directive name `declare target` may be used as a synonym for `begin declare target` only when no clauses are specified. This clause-less delimited form is now deprecated and should emit a deprecation warning. ``` // Deprecated usage (should trigger warning): #pragma omp declare target // deprecated in OpenMP 5.2 void foo1() { } #pragma omp end declare target // Valid usage with clause (should not trigger warning): #pragma omp declare target enter(foo2) void foo2() { } ``` ``` // Recommended replacement for deprecated delimited form: #pragma omp begin declare target void foo() { } #pragma omp end declare target ``` --------- Co-authored-by: urvi-rav <urvi.rav@hpe.com>
1 parent adcd1bb commit 8055c0f

File tree

7 files changed

+35
-28
lines changed

7 files changed

+35
-28
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ OpenMP Support
12351235
- Fixed mapping of arrays of structs containing nested structs with user defined
12361236
mappers, by using compiler-generated default mappers for the outer structs for
12371237
such maps.
1238+
- Deprecation warning has been emitted for deprecated delimited form of ``declare target``.
12381239

12391240
Improvements
12401241
^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ def err_omp_declare_target_multiple : Error<
15741574
"%0 appears multiple times in clauses on the same declare target directive">;
15751575
def err_omp_declare_target_indirect_device_type: Error<
15761576
"only 'device_type(any)' clause is allowed with indirect clause">;
1577+
def warn_omp_deprecated_declare_target_delimited_form :
1578+
Warning<"the delimited form of '#pragma omp declare target' without clauses is deprecated; use '#pragma omp begin declare target' instead">,
1579+
InGroup<Deprecated>;
15771580
def err_omp_expected_clause: Error<
15781581
"expected at least one clause on '#pragma omp %0' directive">;
15791582
def err_omp_mapper_illegal_identifier : Error<

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,9 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
21902190
SourceLocation DTLoc = ConsumeAnyToken();
21912191
bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
21922192
SemaOpenMP::DeclareTargetContextInfo DTCI(DKind, DTLoc);
2193+
if (DKind == OMPD_declare_target && !HasClauses &&
2194+
getLangOpts().OpenMP >= 52)
2195+
Diag(DTLoc, diag::warn_omp_deprecated_declare_target_delimited_form);
21932196
if (HasClauses)
21942197
ParseOMPDeclareTargetClauses(DTCI);
21952198
bool HasImplicitMappings = DKind == OMPD_begin_declare_target ||
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#pragma omp declare target
1+
#pragma omp begin declare target
22
void zyx();
33
#pragma omp end declare target

clang/test/OpenMP/declare_target_ast_print.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int out_decl_target = 0;
133133
// CHECK: void lambda()
134134
// CHECK: #pragma omp end declare target{{$}}
135135

136-
#pragma omp declare target
136+
#pragma omp begin declare target
137137
void lambda () {
138138
#ifdef __cpp_lambdas
139139
(void)[&] { ++out_decl_target; };
@@ -144,15 +144,15 @@ void lambda () {
144144
};
145145
#pragma omp end declare target
146146

147-
#pragma omp declare target
147+
#pragma omp begin declare target
148148
// CHECK: #pragma omp declare target{{$}}
149149
void foo() {}
150150
// CHECK-NEXT: void foo()
151151
#pragma omp end declare target
152152
// CHECK: #pragma omp end declare target{{$}}
153153

154154
extern "C" {
155-
#pragma omp declare target
155+
#pragma omp begin declare target
156156
// CHECK: #pragma omp declare target
157157
void foo_c() {}
158158
// CHECK-NEXT: void foo_c()
@@ -161,15 +161,15 @@ void foo_c() {}
161161
}
162162

163163
extern "C++" {
164-
#pragma omp declare target
164+
#pragma omp begin declare target
165165
// CHECK: #pragma omp declare target
166166
void foo_cpp() {}
167167
// CHECK-NEXT: void foo_cpp()
168168
#pragma omp end declare target
169169
// CHECK: #pragma omp end declare target
170170
}
171171

172-
#pragma omp declare target
172+
#pragma omp begin declare target
173173
template <class T>
174174
struct C {
175175
// CHECK: template <class T> struct C {
@@ -262,7 +262,7 @@ int c1, c2, c3;
262262
// CHECK: #pragma omp end declare target{{$}}
263263

264264
struct SSSt {
265-
#pragma omp declare target
265+
#pragma omp begin declare target
266266
static int a;
267267
int b;
268268
#pragma omp end declare target
@@ -276,7 +276,7 @@ struct SSSt {
276276

277277
template <class T>
278278
struct SSSTt {
279-
#pragma omp declare target
279+
#pragma omp begin declare target
280280
static T a;
281281
int b;
282282
#pragma omp end declare target
@@ -288,7 +288,7 @@ struct SSSTt {
288288
// CHECK: #pragma omp end declare target
289289
// CHECK: int b;
290290

291-
#pragma omp declare target
291+
#pragma omp begin declare target
292292
template <typename T>
293293
T baz() { return T(); }
294294
#pragma omp end declare target
@@ -310,7 +310,7 @@ int baz() { return 1; }
310310
// CHECK: }
311311
// CHECK: #pragma omp end declare target
312312

313-
#pragma omp declare target
313+
#pragma omp begin declare target
314314
#include "declare_target_include.h"
315315
void xyz();
316316
#pragma omp end declare target
@@ -322,8 +322,8 @@ int baz() { return 1; }
322322
// CHECK: void xyz();
323323
// CHECK: #pragma omp end declare target
324324

325-
#pragma omp declare target
326-
#pragma omp declare target
325+
#pragma omp begin declare target
326+
#pragma omp begin declare target
327327
void abc();
328328
#pragma omp end declare target
329329
void cba();
@@ -336,7 +336,7 @@ int baz() { return 1; }
336336
// CHECK: void cba();
337337
// CHECK: #pragma omp end declare target
338338

339-
#pragma omp declare target
339+
#pragma omp begin declare target
340340
int abc1() { return 1; }
341341
#if _OPENMP >= 202111
342342
#pragma omp declare target enter(abc1) device_type(nohost)
@@ -352,7 +352,7 @@ int abc1() { return 1; }
352352
// CHECK-NEXT: }
353353
// CHECK-NEXT: #pragma omp end declare target
354354

355-
#pragma omp declare target
355+
#pragma omp begin declare target
356356
int inner_link;
357357
#pragma omp declare target link(inner_link)
358358
#pragma omp end declare target
@@ -396,7 +396,7 @@ int main (int argc, char **argv) {
396396
// CHECK-NEXT: #pragma omp end declare target
397397

398398
// Do not expect anything here since the region is empty.
399-
#pragma omp declare target
399+
#pragma omp begin declare target
400400
#pragma omp end declare target
401401

402402
#endif

clang/test/OpenMP/declare_target_messages.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ __thread int t;
5353
// omp52-error@+2 {{expected '(' after 'declare target'}}
5454
// omp45-to-51-error@+1 {{expected '(' after 'declare target'}}
5555
#pragma omp declare target .
56-
56+
// omp52-or-later-warning@+1 {{the delimited form of '#pragma omp declare target' without clauses is deprecated; use '#pragma omp begin declare target' instead}}
5757
#pragma omp declare target
5858
void f();
5959
// omp60-warning@+3 {{extra tokens at the end of '#pragma omp end declare_target' are ignored}}
@@ -156,15 +156,15 @@ typedef int sint;
156156
template <typename T>
157157
T bla1() { return 0; }
158158

159-
#pragma omp declare target
159+
#pragma omp begin declare target
160160
template <typename T>
161161
T bla2() { return 0; }
162162
#pragma omp end declare target
163163

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

167-
#pragma omp declare target
167+
#pragma omp begin declare target
168168
void blub2() {
169169
bla2<float>();
170170
bla2<int>();
@@ -179,7 +179,7 @@ void t2() {
179179
}
180180
}
181181

182-
#pragma omp declare target
182+
#pragma omp begin declare target
183183
void abc();
184184
#pragma omp end declare target
185185
void cba();
@@ -188,13 +188,13 @@ void cba();
188188
// omp45-to-51-error@+1 {{unexpected OpenMP directive '#pragma omp end declare target'}}
189189
#pragma omp end declare target
190190

191-
#pragma omp declare target
192-
#pragma omp declare target
191+
#pragma omp begin declare target
192+
#pragma omp begin declare target
193193
void def();
194194
#pragma omp end declare target
195195
void fed();
196196

197-
#pragma omp declare target
197+
#pragma omp begin declare target
198198
// expected-note@+1 {{defined as threadprivate or thread local}}
199199
#pragma omp threadprivate(a)
200200
extern int b;
@@ -239,7 +239,7 @@ void foo(int p) {
239239
q();
240240
c();
241241
}
242-
#pragma omp declare target
242+
#pragma omp begin declare target
243243
void foo1() {
244244
// omp5-or-later-var-note@+1 {{variable 'z' is captured here}}
245245
[&](){ (void)(b+z);}();
@@ -258,7 +258,7 @@ int C::method() {
258258
}
259259

260260
struct S {
261-
#pragma omp declare target
261+
#pragma omp begin declare target
262262
int v;
263263
#pragma omp end declare target
264264
};
@@ -293,7 +293,7 @@ int main (int argc, char **argv) {
293293
}
294294

295295
namespace {
296-
#pragma omp declare target
296+
#pragma omp begin declare target
297297
int x;
298298
}
299299
#pragma omp end declare target
@@ -347,7 +347,7 @@ void host3() {host1();} // dev5-error {{function with 'device_type(host)' is not
347347
// omp52-or-later-error@+1 {{expected at least one 'enter', 'link' or 'indirect' clause}}
348348
#pragma omp declare target to(host3)
349349

350-
#pragma omp declare target
350+
#pragma omp begin declare target
351351
void any1() {any();}
352352
// dev5-error@+1 {{function with 'device_type(host)' is not available on device}}
353353
void any2() {host1();}
@@ -411,7 +411,7 @@ struct target{
411411
// expected-warning@+1 {{declaration is not declared in any declare target region}}
412412
static target S;
413413

414-
#pragma omp declare target
414+
#pragma omp begin declare target
415415
// expected-note@+1 {{used here}}
416416
int target_var = variable;
417417
// expected-note@+1 {{used here}}

clang/test/OpenMP/target_ast_print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ extern const omp_allocator_handle_t omp_thread_mem_alloc;
367367

368368
void foo() {}
369369

370-
#pragma omp declare target
370+
#pragma omp begin declare target
371371
void bar() {}
372372
#pragma omp end declare target
373373

0 commit comments

Comments
 (0)