Skip to content

Commit 86ab870

Browse files
committed
Use OmpDirectiveName as OmpDirectiveNameModifier
1 parent 25b1b4b commit 86ab870

File tree

7 files changed

+36
-19
lines changed

7 files changed

+36
-19
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ class ParseTreeDumper {
587587
NODE(OmpFromClause, Modifier)
588588
NODE(parser, OmpExpectation)
589589
NODE_ENUM(OmpExpectation, Value)
590-
NODE(parser, OmpDirectiveNameModifier)
591590
NODE(parser, OmpHoldsClause)
592591
NODE(parser, OmpIfClause)
593592
NODE(OmpIfClause, Modifier)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,9 +3807,7 @@ struct OmpDeviceModifier {
38073807
// [*] The IF clause is allowed on CANCEL in OpenMP 4.5, but only without
38083808
// the directive-name-modifier. For the sake of uniformity CANCEL can be
38093809
// considered a valid value in 4.5 as well.
3810-
struct OmpDirectiveNameModifier {
3811-
WRAPPER_CLASS_BOILERPLATE(OmpDirectiveNameModifier, llvm::omp::Directive);
3812-
};
3810+
using OmpDirectiveNameModifier = OmpDirectiveName;
38133811

38143812
// Ref: [5.1:205-209], [5.2:166-168]
38153813
//
@@ -4509,6 +4507,8 @@ struct OmpDirectiveSpecification {
45094507
llvm::omp::Directive DirId() const { //
45104508
return std::get<OmpDirectiveName>(t).v;
45114509
}
4510+
const OmpClauseList &Clauses() const;
4511+
45124512
std::tuple<OmpDirectiveName, std::optional<std::list<OmpArgument>>,
45134513
std::optional<OmpClauseList>>
45144514
t;

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,7 @@ TYPE_PARSER(sourced(construct<OmpFromClause::Modifier>(
505505
TYPE_PARSER(sourced(
506506
construct<OmpGrainsizeClause::Modifier>(Parser<OmpPrescriptiveness>{})))
507507

508-
TYPE_PARSER(
509-
sourced(construct<OmpIfClause::Modifier>(unwrap(OmpDirectiveNameParser{}))))
508+
TYPE_PARSER(sourced(construct<OmpIfClause::Modifier>(OmpDirectiveNameParser{})))
510509

511510
TYPE_PARSER(sourced(construct<OmpInReductionClause::Modifier>(
512511
Parser<OmpReductionIdentifier>{})))

flang/lib/Parser/parse-tree.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,12 @@ namespace Fortran::parser {
336336
llvm::omp::Clause OmpClause::Id() const {
337337
return std::visit([](auto &&s) { return getClauseIdForClass(s); }, u);
338338
}
339+
340+
const OmpClauseList &OmpDirectiveSpecification::Clauses() const {
341+
static OmpClauseList empty{std::move(decltype(OmpClauseList::v){})};
342+
if (auto &clauses = std::get<std::optional<OmpClauseList>>(t)) {
343+
return *clauses;
344+
}
345+
return empty;
346+
}
339347
} // namespace Fortran::parser

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,18 +625,28 @@ void OmpStructureChecker::CheckHintClause(
625625
}
626626

627627
void OmpStructureChecker::Enter(const parser::OmpDirectiveSpecification &x) {
628-
PushContextAndClauseSets(x.source, x.DirId());
628+
// OmpDirectiveSpecification exists on its own only in METADIRECTIVE.
629+
// In other cases it's a part of other constructs that handle directive
630+
// context stack by themselves.
631+
if (GetDirectiveNest(MetadirectiveNest)) {
632+
PushContextAndClauseSets(
633+
std::get<parser::OmpDirectiveName>(x.t).source, x.DirId());
634+
}
629635
}
630636

631637
void OmpStructureChecker::Leave(const parser::OmpDirectiveSpecification &) {
632-
dirContext_.pop_back();
638+
if (GetDirectiveNest(MetadirectiveNest)) {
639+
dirContext_.pop_back();
640+
}
633641
}
634642

635643
void OmpStructureChecker::Enter(const parser::OmpMetadirectiveDirective &x) {
644+
EnterDirectiveNest(MetadirectiveNest);
636645
PushContextAndClauseSets(x.source, llvm::omp::Directive::OMPD_metadirective);
637646
}
638647

639648
void OmpStructureChecker::Leave(const parser::OmpMetadirectiveDirective &) {
649+
ExitDirectiveNest(MetadirectiveNest);
640650
dirContext_.pop_back();
641651
}
642652

flang/lib/Semantics/check-omp-structure.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ class OmpStructureChecker
326326
TargetNest,
327327
DeclarativeNest,
328328
ContextSelectorNest,
329-
LastType = ContextSelectorNest,
329+
MetadirectiveNest,
330+
LastType = MetadirectiveNest,
330331
};
331332
int directiveNest_[LastType + 1] = {0};
332333

flang/test/Parser/OpenMP/if-clause.f90

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ program openmp_parse_if
1111

1212
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target update
1313
! CHECK-NEXT: OmpClause -> If -> OmpIfClause
14-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = target update
14+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target update
1515
!$omp target update if(target update: cond) to(i)
1616

1717
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target enter data
1818
! CHECK: OmpClause -> If -> OmpIfClause
19-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = target enter data
19+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target enter data
2020
!$omp target enter data map(to: i) if(target enter data: cond)
2121

2222
! CHECK: OmpSimpleStandaloneDirective -> llvm::omp::Directive = target exit data
2323
! CHECK: OmpClause -> If -> OmpIfClause
24-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = target exit data
24+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target exit data
2525
!$omp target exit data map(from: i) if(target exit data: cond)
2626

2727
! CHECK: OmpBlockDirective -> llvm::omp::Directive = target data
2828
! CHECK: OmpClause -> If -> OmpIfClause
29-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = target data
29+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target data
3030
!$omp target data map(tofrom: i) if(target data: cond)
3131
!$omp end target data
3232

3333
! CHECK: OmpLoopDirective -> llvm::omp::Directive = target teams distribute parallel do simd
3434
! CHECK: OmpClause -> If -> OmpIfClause
35-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = target
35+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = target
3636
! CHECK: OmpClause -> If -> OmpIfClause
37-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = teams
37+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = teams
3838
! CHECK: OmpClause -> If -> OmpIfClause
39-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = parallel
39+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = parallel
4040
! CHECK: OmpClause -> If -> OmpIfClause
41-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = simd
41+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = simd
4242
!$omp target teams distribute parallel do simd if(target: cond) &
4343
!$omp& if(teams: cond) if(parallel: cond) if(simd: cond)
4444
do i = 1, 10
@@ -47,13 +47,13 @@ program openmp_parse_if
4747

4848
! CHECK: OmpBlockDirective -> llvm::omp::Directive = task
4949
! CHECK-NEXT: OmpClause -> If -> OmpIfClause
50-
! CHECK-NEXT: OmpDirectiveNameModifier -> llvm::omp::Directive = task
50+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = task
5151
!$omp task if(task: cond)
5252
!$omp end task
5353

5454
! CHECK: OmpLoopDirective -> llvm::omp::Directive = taskloop
5555
! CHECK-NEXT: OmpClause -> If -> OmpIfClause
56-
! CHECK-NEXT: DirectiveNameModifier -> llvm::omp::Directive = taskloop
56+
! CHECK-NEXT: OmpDirectiveName -> llvm::omp::Directive = taskloop
5757
!$omp taskloop if(taskloop: cond)
5858
do i = 1, 10
5959
end do

0 commit comments

Comments
 (0)