Skip to content

Commit ab04989

Browse files
authored
[flang][OpenMP] Reorganize ALLOCATE-related semantic checks (#165719)
For ALLOCATORS and executable ALLOCATE first perform list item checks in the context of an individual ALLOCATE clause or directive respectively, then perform "global" checks, e.g. whether all list items are present on the ALLOCATE statement. These changes allowed to simplify the checks for presence on ALLOCATE statement and the use of a predefined allocator. Additionally, allow variable list item lists to be empty, add a test for the related spec restriction. This is a first step towards unifying OpenMPDeclarativeAllocate and OpenMPExecutableAllocate into a single directive.
1 parent ca19ab9 commit ab04989

File tree

17 files changed

+327
-258
lines changed

17 files changed

+327
-258
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5155,7 +5155,7 @@ struct OpenMPThreadprivate {
51555155
struct OpenMPDeclarativeAllocate {
51565156
TUPLE_CLASS_BOILERPLATE(OpenMPDeclarativeAllocate);
51575157
CharBlock source;
5158-
std::tuple<Verbatim, OmpObjectList, OmpClauseList> t;
5158+
std::tuple<Verbatim, std::optional<OmpObjectList>, OmpClauseList> t;
51595159
};
51605160

51615161
struct OpenMPDeclarativeConstruct {

flang/include/flang/Semantics/openmp-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const parser::OmpObject *GetArgumentObject(const parser::OmpArgument &argument);
7272
bool IsCommonBlock(const Symbol &sym);
7373
bool IsExtendedListItem(const Symbol &sym);
7474
bool IsVariableListItem(const Symbol &sym);
75+
bool IsTypeParamInquiry(const Symbol &sym);
76+
bool IsStructureComponent(const Symbol &sym);
7577
bool IsVarOrFunctionRef(const MaybeExpr &expr);
7678

7779
bool IsMapEnteringType(parser::OmpMapType::Value type);

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,11 +2045,12 @@ TYPE_PARSER(sourced(construct<OpenMPCriticalConstruct>(
20452045
OmpBlockConstructParser{llvm::omp::Directive::OMPD_critical})))
20462046

20472047
// 2.11.3 Executable Allocate directive
2048-
TYPE_PARSER(
2049-
sourced(construct<OpenMPExecutableAllocate>(verbatim("ALLOCATE"_tok),
2050-
maybe(parenthesized(Parser<OmpObjectList>{})), Parser<OmpClauseList>{},
2051-
maybe(nonemptyList(Parser<OpenMPDeclarativeAllocate>{})) / endOmpLine,
2052-
statement(allocateStmt))))
2048+
TYPE_PARSER(sourced(construct<OpenMPExecutableAllocate>(
2049+
verbatim("ALLOCATE"_tok), maybe(parenthesized(Parser<OmpObjectList>{})),
2050+
Parser<OmpClauseList>{},
2051+
maybe(nonemptyList(startOmpLine >> Parser<OpenMPDeclarativeAllocate>{})) /
2052+
endOmpLine,
2053+
statement(allocateStmt))))
20532054

20542055
// 2.8.2 Declare Simd construct
20552056
TYPE_PARSER(sourced(construct<OpenMPDeclareSimdConstruct>(
@@ -2079,7 +2080,8 @@ TYPE_PARSER(sourced( //
20792080
// 2.11.3 Declarative Allocate directive
20802081
TYPE_PARSER(
20812082
sourced(construct<OpenMPDeclarativeAllocate>(verbatim("ALLOCATE"_tok),
2082-
parenthesized(Parser<OmpObjectList>{}), Parser<OmpClauseList>{})) /
2083+
maybe(parenthesized(Parser<OmpObjectList>{})),
2084+
Parser<OmpClauseList>{})) /
20832085
lookAhead(endOmpLine / !statement(allocateStmt)))
20842086

20852087
// Assumes Construct

flang/lib/Parser/unparse.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,9 +2502,7 @@ class UnparseVisitor {
25022502
void Unparse(const OpenMPDeclarativeAllocate &x) {
25032503
BeginOpenMP();
25042504
Word("!$OMP ALLOCATE");
2505-
Put(" (");
2506-
Walk(std::get<OmpObjectList>(x.t));
2507-
Put(")");
2505+
Walk(" (", std::get<std::optional<OmpObjectList>>(x.t), ")");
25082506
Walk(std::get<OmpClauseList>(x.t));
25092507
Put("\n");
25102508
EndOpenMP();

0 commit comments

Comments
 (0)