Skip to content

Commit 16662ce

Browse files
committed
Check for loosely-strictured block instead of maintaining a flag
1 parent 040a19d commit 16662ce

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ class ParseTreeDumper {
713713
NODE(parser, OmpEndDirective)
714714
NODE(parser, OpenMPAtomicConstruct)
715715
NODE(parser, OpenMPBlockConstruct)
716-
NODE_ENUM(OpenMPBlockConstruct, Flags)
717716
NODE(parser, OpenMPCancelConstruct)
718717
NODE(parser, OpenMPCancellationPointConstruct)
719718
NODE(parser, OpenMPConstruct)

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4783,25 +4783,15 @@ struct OmpEndDirective : public OmpDirectiveSpecification {
47834783
// Common base class for block-associated constructs.
47844784
struct OmpBlockConstruct {
47854785
TUPLE_CLASS_BOILERPLATE(OmpBlockConstruct);
4786-
ENUM_CLASS(Flags, None, MissingMandatoryEndDirective);
4787-
4788-
/// Constructor with defualt value for Flags.
4789-
OmpBlockConstruct(OmpBeginDirective &&begin, Block &&block,
4790-
std::optional<OmpEndDirective> &&end)
4791-
: t(std::move(begin), std::move(block), std::move(end), Flags::None) {}
4792-
47934786
const OmpBeginDirective &BeginDir() const {
47944787
return std::get<OmpBeginDirective>(t);
47954788
}
47964789
const std::optional<OmpEndDirective> &EndDir() const {
47974790
return std::get<std::optional<OmpEndDirective>>(t);
47984791
}
4799-
bool isMissingMandatoryEndDirecitive() const {
4800-
return std::get<Flags>(t) == Flags::MissingMandatoryEndDirective;
4801-
}
48024792

48034793
CharBlock source;
4804-
std::tuple<OmpBeginDirective, Block, std::optional<OmpEndDirective>, Flags> t;
4794+
std::tuple<OmpBeginDirective, Block, std::optional<OmpEndDirective>> t;
48054795
};
48064796

48074797
struct OmpMetadirectiveDirective {

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,6 @@ struct OmpBlockConstructParser {
14741474
constexpr OmpBlockConstructParser(llvm::omp::Directive dir) : dir_(dir) {}
14751475

14761476
std::optional<resultType> Parse(ParseState &state) const {
1477-
using Flags = OmpBlockConstruct::Flags;
14781477
if (auto &&begin{OmpBeginDirectiveParser(dir_).Parse(state)}) {
14791478
if (auto &&body{attempt(StrictlyStructuredBlockParser{}).Parse(state)}) {
14801479
// Try strictly-structured block with an optional end-directive
@@ -1503,8 +1502,7 @@ struct OmpBlockConstructParser {
15031502
return OmpBlockConstruct{OmpBeginDirective(std::move(*begin)),
15041503
std::move(*body),
15051504
llvm::transformOptional(std::move(*end),
1506-
[](auto &&s) { return OmpEndDirective(std::move(s)); }),
1507-
endPresent ? Flags::None : Flags::MissingMandatoryEndDirective};
1505+
[](auto &&s) { return OmpEndDirective(std::move(s)); })};
15081506
}
15091507
}
15101508
return std::nullopt;

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,23 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
788788

789789
// Missing mandatory end block: this is checked in semantics because that
790790
// makes it easier to control the error messages.
791-
if (x.isMissingMandatoryEndDirecitive()) {
791+
// The end block is mandatory when the construct is not applied to a strictly
792+
// structured block (aka it is applied to a loosely structured block). In
793+
// other words, the body doesn't contain exactly one parser::BlockConstruct.
794+
auto isStrictlyStructuredBlock{[](const parser::Block &block) -> bool {
795+
if (block.size() != 1) {
796+
return false;
797+
}
798+
const parser::ExecutionPartConstruct &contents{block.front()};
799+
auto *executableConstruct{
800+
std::get_if<parser::ExecutableConstruct>(&contents.u)};
801+
if (!executableConstruct) {
802+
return false;
803+
}
804+
return std::holds_alternative<common::Indirection<parser::BlockConstruct>>(
805+
executableConstruct->u);
806+
}};
807+
if (!endSpec && !isStrictlyStructuredBlock(block)) {
792808
context_.Say(
793809
x.BeginDir().source, "Expected OpenMP end directive"_err_en_US);
794810
}

0 commit comments

Comments
 (0)