[flang-commits] [flang] 9b49392 - [Flang] Handle the source (scopes) for some OpenMP constructs (#109097)
via flang-commits
flang-commits at lists.llvm.org
Mon Oct 21 00:37:51 PDT 2024
Author: Thirumalai Shaktivel
Date: 2024-10-21T13:07:48+05:30
New Revision: 9b49392d6edcdfcc59304350ebd4196be5180d4a
URL: https://github.com/llvm/llvm-project/commit/9b49392d6edcdfcc59304350ebd4196be5180d4a
DIFF: https://github.com/llvm/llvm-project/commit/9b49392d6edcdfcc59304350ebd4196be5180d4a.diff
LOG: [Flang] Handle the source (scopes) for some OpenMP constructs (#109097)
Fixes: https://github.com/llvm/llvm-project/issues/82943
Fixes: https://github.com/llvm/llvm-project/issues/82942
Fixes: https://github.com/llvm/llvm-project/issues/85593
Added:
flang/test/Semantics/OpenMP/atomic06-empty.f90
flang/test/Semantics/OpenMP/declare-simd-empty.f90
flang/test/Semantics/OpenMP/threadprivate08-empty.f90
Modified:
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Semantics/resolve-names.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 8634c522cf343a..52c7529369dfb5 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -657,33 +657,36 @@ TYPE_PARSER(construct<OmpEndAtomic>(startOmpLine >> "END ATOMIC"_tok))
// OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] READ [MEMORY-ORDER-CLAUSE-LIST]
TYPE_PARSER("ATOMIC" >>
- construct<OmpAtomicRead>(Parser<OmpAtomicClauseList>{} / maybe(","_tok),
- verbatim("READ"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine,
- statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine)))
+ sourced(construct<OmpAtomicRead>(
+ Parser<OmpAtomicClauseList>{} / maybe(","_tok), verbatim("READ"_tok),
+ Parser<OmpAtomicClauseList>{} / endOmpLine, statement(assignmentStmt),
+ maybe(Parser<OmpEndAtomic>{} / endOmpLine))))
// OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] CAPTURE [MEMORY-ORDER-CLAUSE-LIST]
TYPE_PARSER("ATOMIC" >>
- construct<OmpAtomicCapture>(Parser<OmpAtomicClauseList>{} / maybe(","_tok),
- verbatim("CAPTURE"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine,
- statement(assignmentStmt), statement(assignmentStmt),
- Parser<OmpEndAtomic>{} / endOmpLine))
+ sourced(construct<OmpAtomicCapture>(
+ Parser<OmpAtomicClauseList>{} / maybe(","_tok), verbatim("CAPTURE"_tok),
+ Parser<OmpAtomicClauseList>{} / endOmpLine, statement(assignmentStmt),
+ statement(assignmentStmt), Parser<OmpEndAtomic>{} / endOmpLine)))
// OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] UPDATE [MEMORY-ORDER-CLAUSE-LIST]
TYPE_PARSER("ATOMIC" >>
- construct<OmpAtomicUpdate>(Parser<OmpAtomicClauseList>{} / maybe(","_tok),
- verbatim("UPDATE"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine,
- statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine)))
+ sourced(construct<OmpAtomicUpdate>(
+ Parser<OmpAtomicClauseList>{} / maybe(","_tok), verbatim("UPDATE"_tok),
+ Parser<OmpAtomicClauseList>{} / endOmpLine, statement(assignmentStmt),
+ maybe(Parser<OmpEndAtomic>{} / endOmpLine))))
// OMP ATOMIC [atomic-clause-list]
-TYPE_PARSER(construct<OmpAtomic>(verbatim("ATOMIC"_tok),
+TYPE_PARSER(sourced(construct<OmpAtomic>(verbatim("ATOMIC"_tok),
Parser<OmpAtomicClauseList>{} / endOmpLine, statement(assignmentStmt),
- maybe(Parser<OmpEndAtomic>{} / endOmpLine)))
+ maybe(Parser<OmpEndAtomic>{} / endOmpLine))))
// OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] WRITE [MEMORY-ORDER-CLAUSE-LIST]
TYPE_PARSER("ATOMIC" >>
- construct<OmpAtomicWrite>(Parser<OmpAtomicClauseList>{} / maybe(","_tok),
- verbatim("WRITE"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine,
- statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine)))
+ sourced(construct<OmpAtomicWrite>(
+ Parser<OmpAtomicClauseList>{} / maybe(","_tok), verbatim("WRITE"_tok),
+ Parser<OmpAtomicClauseList>{} / endOmpLine, statement(assignmentStmt),
+ maybe(Parser<OmpEndAtomic>{} / endOmpLine))))
// Atomic Construct
TYPE_PARSER(construct<OpenMPAtomicConstruct>(Parser<OmpAtomicRead>{}) ||
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 2fa5b75e073b63..030dbc5ea0f02f 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1530,6 +1530,23 @@ class OmpVisitor : public virtual DeclarationVisitor {
void Post(const parser::OpenMPDeclarativeAllocate &) {
SkipImplicitTyping(false);
}
+ bool Pre(const parser::OpenMPDeclarativeConstruct &x) {
+ AddOmpSourceRange(x.source);
+ return true;
+ }
+ void Post(const parser::OpenMPDeclarativeConstruct &) {
+ messageHandler().set_currStmtSource(std::nullopt);
+ }
+ bool Pre(const parser::OpenMPAtomicConstruct &x) {
+ return common::visit(common::visitors{[&](const auto &u) -> bool {
+ AddOmpSourceRange(u.source);
+ return true;
+ }},
+ x.u);
+ }
+ void Post(const parser::OpenMPAtomicConstruct &) {
+ messageHandler().set_currStmtSource(std::nullopt);
+ }
};
bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) {
diff --git a/flang/test/Semantics/OpenMP/atomic06-empty.f90 b/flang/test/Semantics/OpenMP/atomic06-empty.f90
new file mode 100644
index 00000000000000..226e8d1bb91a5b
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/atomic06-empty.f90
@@ -0,0 +1,6 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+! Test the source code starting with omp syntax
+
+!$omp atomic write
+i = 123
+end
diff --git a/flang/test/Semantics/OpenMP/declare-simd-empty.f90 b/flang/test/Semantics/OpenMP/declare-simd-empty.f90
new file mode 100644
index 00000000000000..b61fb53730a23d
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/declare-simd-empty.f90
@@ -0,0 +1,6 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+! Test the source code starting with omp syntax
+
+!$omp declare simd
+integer :: x
+end
diff --git a/flang/test/Semantics/OpenMP/threadprivate08-empty.f90 b/flang/test/Semantics/OpenMP/threadprivate08-empty.f90
new file mode 100644
index 00000000000000..38a855dceb8366
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/threadprivate08-empty.f90
@@ -0,0 +1,5 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+! Test the source code starting with omp syntax
+
+!$omp threadprivate(a)
+end
More information about the flang-commits
mailing list