Skip to content

Commit 6e01016

Browse files
[OpenMP] Support for nothing in metadirective (#73690)
- Removed an unnecessary check that was preventing `nothing` to work properly inside `metadirective`.
1 parent 9eb80ab commit 6e01016

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,12 +2518,14 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
25182518

25192519
switch (DKind) {
25202520
case OMPD_nothing:
2521-
if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2522-
ParsedStmtContext())
2523-
Diag(Tok, diag::err_omp_immediate_directive)
2524-
<< getOpenMPDirectiveName(DKind) << 0;
25252521
ConsumeToken();
2526-
skipUntilPragmaOpenMPEnd(DKind);
2522+
// If we are parsing the directive within a metadirective, the directive
2523+
// ends with a ')'.
2524+
if (ReadDirectiveWithinMetadirective && Tok.is(tok::r_paren))
2525+
while (Tok.isNot(tok::annot_pragma_openmp_end))
2526+
ConsumeAnyToken();
2527+
else
2528+
skipUntilPragmaOpenMPEnd(DKind);
25272529
if (Tok.is(tok::annot_pragma_openmp_end))
25282530
ConsumeAnnotationToken();
25292531
break;

clang/test/OpenMP/metadirective_ast_print.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ void foo(void) {
6767
default(parallel for)
6868
for (int i = 0; i < 100; i++)
6969
;
70+
71+
#pragma omp metadirective when(implementation = {extension(match_all)} \
72+
: nothing) default(parallel for)
73+
for (int i = 0; i < 16; i++)
74+
;
75+
76+
#pragma omp metadirective when(implementation = {extension(match_any)} \
77+
: parallel) default(nothing)
78+
for (int i = 0; i < 16; i++)
79+
;
7080
}
7181

7282
// CHECK: void bar(void);
@@ -95,5 +105,7 @@ void foo(void) {
95105
// CHECK-NEXT: for (int j = 0; j < 16; j++)
96106
// CHECK-AMDGCN: #pragma omp teams distribute parallel for
97107
// CHECK-AMDGCN-NEXT: for (int i = 0; i < 100; i++)
108+
// CHECK: for (int i = 0; i < 16; i++)
109+
// CHECK: for (int i = 0; i < 16; i++)
98110

99111
#endif

clang/test/OpenMP/metadirective_empty.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ void func() {
1414
:) default(parallel for)
1515
for (int i = 0; i < N; i++)
1616
;
17+
18+
#pragma omp metadirective when(implementation = {vendor(llvm)} \
19+
:nothing) default(parallel for)
20+
for (int i = 0; i < N; i++)
21+
;
1722
}
1823

1924
// CHECK-LABEL: void @_Z4funcv()
2025
// CHECK: entry:
2126
// CHECK: [[I:%.+]] = alloca i32,
27+
// CHECK: [[I1:%.+]] = alloca i32,
2228
// CHECK: store i32 0, ptr [[I]],
2329
// CHECK: br label %[[FOR_COND:.+]]
2430
// CHECK: [[FOR_COND]]:
@@ -33,6 +39,20 @@ void func() {
3339
// CHECK: store i32 [[INC]], ptr [[I]],
3440
// CHECK: br label %[[FOR_COND]],
3541
// CHECK: [[FOR_END]]:
42+
// CHECK: store i32 0, ptr [[I1]],
43+
// CHECK: br label %[[FOR_COND1:.+]]
44+
// CHECK: [[FOR_COND1]]:
45+
// CHECK: [[TWO:%.+]] = load i32, ptr [[I1]],
46+
// CHECK: [[CMP1:%.+]] = icmp slt i32 [[TWO]], 1000
47+
// CHECK: br i1 [[CMP1]], label %[[FOR_BODY1:.+]], label %[[FOR_END1:.+]]
48+
// CHECK: [[FOR_BODY1]]:
49+
// CHECK: br label %[[FOR_INC1:.+]]
50+
// CHECK: [[FOR_INC1]]:
51+
// CHECK: [[THREE:%.+]] = load i32, ptr [[I1]],
52+
// CHECK: [[INC1:%.+]] = add nsw i32 [[THREE]], 1
53+
// CHECK: store i32 [[INC1]], ptr [[I1]],
54+
// CHECK: br label %[[FOR_COND1]],
55+
// CHECK: [[FOR_END1]]:
3656
// CHECK: ret void
3757
// CHECK: }
3858

clang/test/OpenMP/nothing_messages.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ int mixed() {
1212
x=d;
1313
}
1414

15-
// expected-error@+2 {{#pragma omp nothing' cannot be an immediate substatement}}
1615
if(!x)
1716
#pragma omp nothing
1817
x=d;

0 commit comments

Comments
 (0)