Skip to content

Commit e0d922e

Browse files
authored
[flang][OpenMP] Add source range to construct scopes (llvm#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).
1 parent 2f4cca6 commit e0d922e

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,7 @@ void DataSharingProcessor::collectSymbols(
479479
for (const semantics::Scope &child : scope->children())
480480
collectScopes(&child);
481481
};
482-
parser::CharBlock source =
483-
clauses.empty() ? getSource(semaCtx, eval) : clauses.front().source;
482+
parser::CharBlock source = getSource(semaCtx, eval);
484483
const semantics::Scope *curScope = nullptr;
485484
if (!source.empty()) {
486485
curScope = &semaCtx.FindScope(source);

flang/lib/Semantics/resolve-names.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,8 @@ void AccVisitor::Post(const parser::OpenACCCombinedConstruct &x) { PopScope(); }
15691569
class OmpVisitor : public virtual DeclarationVisitor {
15701570
public:
15711571
void AddOmpSourceRange(const parser::CharBlock &);
1572+
void PushScopeWithSource(
1573+
Scope::Kind kind, parser::CharBlock source, Symbol *symbol = nullptr);
15721574

15731575
static bool NeedsScope(const parser::OmpBlockConstruct &);
15741576
static bool NeedsScope(const parser::OmpClause &);
@@ -1592,8 +1594,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
15921594
Post(static_cast<const parser::OmpDirectiveSpecification &>(x));
15931595
}
15941596

1595-
bool Pre(const parser::OpenMPLoopConstruct &) {
1596-
PushScope(Scope::Kind::OtherConstruct, nullptr);
1597+
bool Pre(const parser::OpenMPLoopConstruct &x) {
1598+
PushScopeWithSource(Scope::Kind::OtherConstruct, x.source);
15971599
return true;
15981600
}
15991601
void Post(const parser::OpenMPLoopConstruct &) { PopScope(); }
@@ -1637,8 +1639,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
16371639
}
16381640
bool Pre(const parser::OmpMapClause &);
16391641

1640-
bool Pre(const parser::OpenMPSectionsConstruct &) {
1641-
PushScope(Scope::Kind::OtherConstruct, nullptr);
1642+
bool Pre(const parser::OpenMPSectionsConstruct &x) {
1643+
PushScopeWithSource(Scope::Kind::OtherConstruct, x.source);
16421644
return true;
16431645
}
16441646
void Post(const parser::OpenMPSectionsConstruct &) { PopScope(); }
@@ -1744,7 +1746,7 @@ class OmpVisitor : public virtual DeclarationVisitor {
17441746
}
17451747
bool Pre(const parser::OmpClause &x) {
17461748
if (NeedsScope(x)) {
1747-
PushScope(Scope::Kind::OtherClause, nullptr);
1749+
PushScopeWithSource(Scope::Kind::OtherClause, x.source);
17481750
}
17491751
return true;
17501752
}
@@ -1813,9 +1815,15 @@ void OmpVisitor::AddOmpSourceRange(const parser::CharBlock &source) {
18131815
currScope().AddSourceRange(source);
18141816
}
18151817

1818+
void OmpVisitor::PushScopeWithSource(
1819+
Scope::Kind kind, parser::CharBlock source, Symbol *symbol) {
1820+
PushScope(kind, symbol);
1821+
currScope().AddSourceRange(source);
1822+
}
1823+
18161824
bool OmpVisitor::Pre(const parser::OmpBlockConstruct &x) {
18171825
if (NeedsScope(x)) {
1818-
PushScope(Scope::Kind::OtherConstruct, nullptr);
1826+
PushScopeWithSource(Scope::Kind::OtherConstruct, x.source);
18191827
}
18201828
return true;
18211829
}

0 commit comments

Comments
 (0)