[flang-commits] [flang] [flang][openacc] Warn about misplaced end loop directive and ignore it (PR #69512)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Wed Oct 18 13:27:19 PDT 2023
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/69512
Instead of raising an error for a misplaced `end loop directive`, just warn about it and ignore it. This directive is an extension and is optional.
>From 38acd6a6415da641299b003e75e054249f6b5c50 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 17 Oct 2023 08:43:44 -0700
Subject: [PATCH] [flang][openacc] Warn about misplaced end loop directive and
ignore it
---
flang/include/flang/Parser/dump-parse-tree.h | 1 +
flang/include/flang/Parser/parse-tree.h | 7 ++++++-
flang/lib/Lower/OpenACC.cpp | 3 +++
flang/lib/Parser/openacc-parsers.cpp | 6 +++++-
flang/lib/Semantics/check-acc-structure.cpp | 4 ++++
flang/lib/Semantics/check-acc-structure.h | 1 +
flang/test/Semantics/OpenACC/acc-error.f90 | 14 ++++++++++++++
7 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index e7d74dda71a20cf..494e54faa64c841 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -568,6 +568,7 @@ class ParseTreeDumper {
NODE(parser, OpenACCCombinedConstruct)
NODE(parser, OpenACCConstruct)
NODE(parser, OpenACCDeclarativeConstruct)
+ NODE(parser, OpenACCEndConstruct)
NODE(parser, OpenACCLoopConstruct)
NODE(parser, OpenACCRoutineConstruct)
NODE(parser, OpenACCStandaloneDeclarativeConstruct)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index cb4bb59bf312c7c..130c49eddd5e219 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4254,6 +4254,11 @@ struct OpenACCLoopConstruct {
t;
};
+struct OpenACCEndConstruct {
+ WRAPPER_CLASS_BOILERPLATE(OpenACCEndConstruct, llvm::acc::Directive);
+ CharBlock source;
+};
+
struct OpenACCStandaloneConstruct {
TUPLE_CLASS_BOILERPLATE(OpenACCStandaloneConstruct);
CharBlock source;
@@ -4264,7 +4269,7 @@ struct OpenACCConstruct {
UNION_CLASS_BOILERPLATE(OpenACCConstruct);
std::variant<OpenACCBlockConstruct, OpenACCCombinedConstruct,
OpenACCLoopConstruct, OpenACCStandaloneConstruct, OpenACCCacheConstruct,
- OpenACCWaitConstruct, OpenACCAtomicConstruct>
+ OpenACCWaitConstruct, OpenACCAtomicConstruct, OpenACCEndConstruct>
u;
};
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index faa5164f52573ce..96556529589ac22 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -3356,6 +3356,9 @@ void Fortran::lower::genOpenACCConstruct(
[&](const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
genACC(converter, eval, atomicConstruct);
},
+ [&](const Fortran::parser::OpenACCEndConstruct &) {
+ // No op
+ },
},
accConstruct.u);
}
diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index 75aeffd29f92f10..bd5dcd8405e8f9f 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -235,6 +235,9 @@ TYPE_PARSER(startAccLine >>
sourced(construct<OpenACCDeclarativeConstruct>(
Parser<OpenACCRoutineConstruct>{})))))
+TYPE_PARSER(sourced(construct<OpenACCEndConstruct>(
+ "END"_tok >> "LOOP"_tok >> pure(llvm::acc::Directive::ACCD_loop))))
+
// OpenACC constructs
TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
startAccLine >>
@@ -246,7 +249,8 @@ TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
Parser<OpenACCStandaloneConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCCacheConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCWaitConstruct>{}),
- construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}))))
+ construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}),
+ construct<OpenACCConstruct>(Parser<OpenACCEndConstruct>{}))))
TYPE_PARSER(startAccLine >>
sourced(construct<AccEndCombinedDirective>(sourced("END"_tok >>
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 3c9e89940d23784..85d065a34f2e8ed 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -660,6 +660,10 @@ void AccStructureChecker::Enter(const parser::AccClause::Link &x) {
CheckMultipleOccurrenceInDeclare(x.v, llvm::acc::Clause::ACCC_link);
}
+void AccStructureChecker::Enter(const parser::OpenACCEndConstruct &x) {
+ context_.Say(x.source, "Misplaced OpenACC end directive"_warn_en_US);
+}
+
void AccStructureChecker::Enter(const parser::Module &) {
declareSymbols.clear();
}
diff --git a/flang/lib/Semantics/check-acc-structure.h b/flang/lib/Semantics/check-acc-structure.h
index 8b87b8ddc502f3f..2a09b7a39395d16 100644
--- a/flang/lib/Semantics/check-acc-structure.h
+++ b/flang/lib/Semantics/check-acc-structure.h
@@ -63,6 +63,7 @@ class AccStructureChecker
void Enter(const parser::OpenACCCacheConstruct &);
void Leave(const parser::OpenACCCacheConstruct &);
void Enter(const parser::AccAtomicUpdate &);
+ void Enter(const parser::OpenACCEndConstruct &);
// Clauses
void Leave(const parser::AccClauseList &);
diff --git a/flang/test/Semantics/OpenACC/acc-error.f90 b/flang/test/Semantics/OpenACC/acc-error.f90
index b1c3b7784742992..69ee59f97ec6b30 100644
--- a/flang/test/Semantics/OpenACC/acc-error.f90
+++ b/flang/test/Semantics/OpenACC/acc-error.f90
@@ -13,3 +13,17 @@ subroutine test(a, n)
!ERROR: expected OpenACC directive
!$acc p
end subroutine
+
+subroutine test2(a, n)
+ integer :: a(n)
+ integer :: i
+
+ !$acc parallel
+ !$acc loop
+ DO i = 1, n
+ END DO
+ !$acc end parallel
+ !WARN: Misplaced OpenACC end directive
+ !$acc end loop
+
+end subroutine
More information about the flang-commits
mailing list