[PATCH] D119761: [OpenMP]Fix parsing of OpenMP directive nested in a metadirective
Mike Rice via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 14 16:33:23 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG83a407d176f8: [OpenMP]Fix parsing of OpenMP directive nested in a metadirective (authored by mikerice).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119761/new/
https://reviews.llvm.org/D119761
Files:
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/metadirective_ast_print.c
Index: clang/test/OpenMP/metadirective_ast_print.c
===================================================================
--- clang/test/OpenMP/metadirective_ast_print.c
+++ clang/test/OpenMP/metadirective_ast_print.c
@@ -47,6 +47,16 @@
: parallel) default(parallel for)
for (int i = 0; i < 100; i++)
;
+
+// Test metadirective with nested OpenMP directive.
+ int array[16];
+ #pragma omp metadirective when(user = {condition(1)} \
+ : parallel for)
+ for (int i = 0; i < 16; i++) {
+ #pragma omp simd
+ for (int j = 0; j < 16; j++)
+ array[i] = i;
+ }
}
// CHECK: void bar();
@@ -69,5 +79,9 @@
// CHECK-NEXT: for (int i = 0; i < 100; i++)
// CHECK: #pragma omp parallel
// CHECK-NEXT: for (int i = 0; i < 100; i++)
+// CHECK: #pragma omp parallel for
+// CHECK-NEXT: for (int i = 0; i < 16; i++) {
+// CHECK-NEXT: #pragma omp simd
+// CHECK-NEXT: for (int j = 0; j < 16; j++)
#endif
Index: clang/lib/Parse/ParseOpenMP.cpp
===================================================================
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -2451,9 +2451,8 @@
/// for simd' | 'target teams distribute simd' | 'masked' {clause}
/// annot_pragma_openmp_end
///
-StmtResult
-Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
- static bool ReadDirectiveWithinMetadirective = false;
+StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
+ ParsedStmtContext StmtCtx, bool ReadDirectiveWithinMetadirective) {
if (!ReadDirectiveWithinMetadirective)
assert(Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp) &&
"Not an OpenMP directive!");
@@ -2615,9 +2614,9 @@
}
// Parse Directive
- ReadDirectiveWithinMetadirective = true;
- Directive = ParseOpenMPDeclarativeOrExecutableDirective(StmtCtx);
- ReadDirectiveWithinMetadirective = false;
+ Directive = ParseOpenMPDeclarativeOrExecutableDirective(
+ StmtCtx,
+ /*ReadDirectiveWithinMetadirective=*/true);
break;
}
break;
Index: clang/include/clang/Parse/Parser.h
===================================================================
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -3291,8 +3291,10 @@
/// Parses declarative or executable directive.
///
/// \param StmtCtx The context in which we're parsing the directive.
- StmtResult
- ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx);
+ /// \param ReadDirectiveWithinMetadirective true if directive is within a
+ /// metadirective and therefore ends on the closing paren.
+ StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
+ ParsedStmtContext StmtCtx, bool ReadDirectiveWithinMetadirective = false);
/// Parses clause of kind \a CKind for directive of a kind \a Kind.
///
/// \param DKind Kind of current directive.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119761.408666.patch
Type: text/x-patch
Size: 2982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220215/6e7241ea/attachment.bin>
More information about the cfe-commits
mailing list