[flang-commits] [flang] e0d922e - [flang][OpenMP] Add source range to construct scopes (#179259)
via flang-commits
flang-commits at lists.llvm.org
Tue Feb 3 07:14:44 PST 2026
Author: Krzysztof Parzyszek
Date: 2026-02-03T09:01:29-06:00
New Revision: e0d922ee20e1948b2a1a2aa9689ceb14796d2a91
URL: https://github.com/llvm/llvm-project/commit/e0d922ee20e1948b2a1a2aa9689ceb14796d2a91
DIFF: https://github.com/llvm/llvm-project/commit/e0d922ee20e1948b2a1a2aa9689ceb14796d2a91.diff
LOG: [flang][OpenMP] Add source range to construct scopes (#179259)
Make sure to add the source range whenever we create a scope for an
OpenMP construct or a clause. This allows that scope to be located via
context.FindScope(source).
Added:
Modified:
flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
flang/lib/Semantics/resolve-names.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
index 83c2eda0a2dc7..a958ec9ba503c 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
@@ -479,8 +479,7 @@ void DataSharingProcessor::collectSymbols(
for (const semantics::Scope &child : scope->children())
collectScopes(&child);
};
- parser::CharBlock source =
- clauses.empty() ? getSource(semaCtx, eval) : clauses.front().source;
+ parser::CharBlock source = getSource(semaCtx, eval);
const semantics::Scope *curScope = nullptr;
if (!source.empty()) {
curScope = &semaCtx.FindScope(source);
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 16b76b72880c9..db84cc40c4283 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1569,6 +1569,8 @@ void AccVisitor::Post(const parser::OpenACCCombinedConstruct &x) { PopScope(); }
class OmpVisitor : public virtual DeclarationVisitor {
public:
void AddOmpSourceRange(const parser::CharBlock &);
+ void PushScopeWithSource(
+ Scope::Kind kind, parser::CharBlock source, Symbol *symbol = nullptr);
static bool NeedsScope(const parser::OmpBlockConstruct &);
static bool NeedsScope(const parser::OmpClause &);
@@ -1592,8 +1594,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
Post(static_cast<const parser::OmpDirectiveSpecification &>(x));
}
- bool Pre(const parser::OpenMPLoopConstruct &) {
- PushScope(Scope::Kind::OtherConstruct, nullptr);
+ bool Pre(const parser::OpenMPLoopConstruct &x) {
+ PushScopeWithSource(Scope::Kind::OtherConstruct, x.source);
return true;
}
void Post(const parser::OpenMPLoopConstruct &) { PopScope(); }
@@ -1637,8 +1639,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
}
bool Pre(const parser::OmpMapClause &);
- bool Pre(const parser::OpenMPSectionsConstruct &) {
- PushScope(Scope::Kind::OtherConstruct, nullptr);
+ bool Pre(const parser::OpenMPSectionsConstruct &x) {
+ PushScopeWithSource(Scope::Kind::OtherConstruct, x.source);
return true;
}
void Post(const parser::OpenMPSectionsConstruct &) { PopScope(); }
@@ -1744,7 +1746,7 @@ class OmpVisitor : public virtual DeclarationVisitor {
}
bool Pre(const parser::OmpClause &x) {
if (NeedsScope(x)) {
- PushScope(Scope::Kind::OtherClause, nullptr);
+ PushScopeWithSource(Scope::Kind::OtherClause, x.source);
}
return true;
}
@@ -1813,9 +1815,15 @@ void OmpVisitor::AddOmpSourceRange(const parser::CharBlock &source) {
currScope().AddSourceRange(source);
}
+void OmpVisitor::PushScopeWithSource(
+ Scope::Kind kind, parser::CharBlock source, Symbol *symbol) {
+ PushScope(kind, symbol);
+ currScope().AddSourceRange(source);
+}
+
bool OmpVisitor::Pre(const parser::OmpBlockConstruct &x) {
if (NeedsScope(x)) {
- PushScope(Scope::Kind::OtherConstruct, nullptr);
+ PushScopeWithSource(Scope::Kind::OtherConstruct, x.source);
}
return true;
}
More information about the flang-commits
mailing list