[flang-commits] [flang] [flang][OpenMP] Optionally get final symbol in Get(Argument|Object)Sy… (PR #196816)
via flang-commits
flang-commits at lists.llvm.org
Sun May 10 09:19:22 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
…mbol
Originally these functions returned the ultimate symbol for the one obtained from the argument or object. However, this may be somewhat unintuitive/unexpected, so instead return the original symbol, and add a flag to optionally return the ultimate one.
---
Full diff: https://github.com/llvm/llvm-project/pull/196816.diff
4 Files Affected:
- (modified) flang/include/flang/Semantics/openmp-utils.h (+4-2)
- (modified) flang/lib/Semantics/check-omp-loop.cpp (+2-10)
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+6-6)
- (modified) flang/lib/Semantics/openmp-utils.cpp (+15-6)
``````````diff
diff --git a/flang/include/flang/Semantics/openmp-utils.h b/flang/include/flang/Semantics/openmp-utils.h
index aab63df2e6e14..b694c02ab32bd 100644
--- a/flang/include/flang/Semantics/openmp-utils.h
+++ b/flang/include/flang/Semantics/openmp-utils.h
@@ -86,8 +86,10 @@ SourcedActionStmt GetActionStmt(const parser::Block &block);
std::string ThisVersion(unsigned version);
std::string TryVersion(unsigned version);
-const Symbol *GetObjectSymbol(const parser::OmpObject &object);
-const Symbol *GetArgumentSymbol(const parser::OmpArgument &argument);
+const Symbol *GetObjectSymbol(
+ const parser::OmpObject &object, bool ultimate = false);
+const Symbol *GetArgumentSymbol(
+ const parser::OmpArgument &argument, bool ultimate = false);
bool IsCommonBlock(const Symbol &sym);
bool IsExtendedListItem(const Symbol &sym);
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 50fbcc20a98aa..6ce4571d051e8 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -465,7 +465,7 @@ void OmpStructureChecker::CheckIterationVariables(
if (llvm::omp::isDataSharingAttributeClause(clauseId, version)) {
for (const parser::OmpObject &object :
parser::omp::GetOmpObjectList(clause)->v) {
- if (const Symbol *symbol{GetObjectSymbol(object)}) {
+ if (const Symbol *symbol{GetObjectSymbol(object, /*ultimate=*/true)}) {
auto maybeSource{parser::omp::GetObjectSource(object)};
assert(maybeSource && "Expecting object source");
dsa.insert(
@@ -507,19 +507,11 @@ void OmpStructureChecker::CheckIterationVariables(
"Loop iteration variable of an affected loop cannot be THREADPRIVATE"_err_en_US,
iv.ToString());
}
- // Get the symbol from the variable that was listed in a DSA clause.
- const Symbol *host{iv.symbol};
- while (host && !dsa.count(host)) {
- host = GetHostSymbol(*host);
- }
- if (!host) {
- continue;
- }
// Check conflict between a predetermined DSA and explicit DSA.
assert(iv.symbol->test(Symbol::Flag::OmpPreDetermined) &&
"Expecting affected iteration variable to have predetermined DSA");
if (iv.symbol->test(Symbol::Flag::OmpExplicit)) {
- auto range{dsa.equal_range(host)};
+ auto range{dsa.equal_range(&iv.symbol->GetUltimate())};
for (auto found{range.first}; found != range.second; ++found) {
llvm::omp::Clause id{found->second.clauseId};
if (!llvm::omp::isAllowedClauseForDirective(dirId, id, version)) {
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 022003a8e1728..d2f4b41cdf24d 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2051,7 +2051,7 @@ void OmpStructureChecker::CheckIndividualAllocateDirective(
continue;
}
- if (const Symbol *symbol{GetObjectSymbol(*object)}) {
+ if (const Symbol *symbol{GetObjectSymbol(*object, /*ultimate=*/true)}) {
if (!IsTypeParamInquiry(*symbol)) {
checkSymbol(*symbol, arg.source);
}
@@ -2084,7 +2084,7 @@ void OmpStructureChecker::CheckExecutableAllocateDirective(
hasEmptyList = true;
}
for (const parser::OmpArgument &arg : spec.Arguments().v) {
- if (auto *sym{GetArgumentSymbol(arg)}) {
+ if (auto *sym{GetArgumentSymbol(arg, /*ultimate=*/true)}) {
// Ignore these checks for structure members. They are not allowed
// in the first place, so don't tell the users that they need to
// be specified somewhere,
@@ -2215,7 +2215,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Allocate &x) {
if (auto *found{parser::omp::FindClause(spec, dsaClause)}) {
for (auto &object : GetOmpObjectList(*found)->v) {
if (auto *symbol{GetObjectSymbol(object)}) {
- privatized.insert(symbol);
+ privatized.insert(&symbol->GetUltimate());
}
}
}
@@ -2223,7 +2223,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Allocate &x) {
for (auto &object : GetOmpObjectList(x)->v) {
if (auto *symbol{GetObjectSymbol(object)}) {
- if (!privatized.count(symbol)) {
+ if (!privatized.count(&symbol->GetUltimate())) {
context_.Say(
GetObjectSource(object).value_or(GetContext().clauseSource),
"The ALLOCATE clause requires that '%s' must be listed in a private data-sharing attribute clause on the same directive"_err_en_US,
@@ -2321,7 +2321,7 @@ void OmpStructureChecker::Enter(const parser::OmpDeclareTargetDirective &x) {
// Check if arguments are extended-list-items.
for (const parser::OmpArgument &arg : x.v.Arguments().v) {
- const Symbol *symbol{GetArgumentSymbol(arg)};
+ const Symbol *symbol{GetArgumentSymbol(arg, /*ultimate=*/true)};
if (!symbol) {
context_.Say(arg.source,
"An argument to the DECLARE TARGET directive should be an extended-list-item"_err_en_US);
@@ -2568,7 +2568,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPAllocatorsConstruct &x) {
}
for (auto &object : DEREF(GetOmpObjectList(clause)).v) {
CheckVarIsNotPartOfAnotherVar(dirName.source, object);
- if (auto *symbol{GetObjectSymbol(object)}) {
+ if (auto *symbol{GetObjectSymbol(object, /*ultimate=*/true)}) {
if (IsStructureComponent(*symbol)) {
continue;
}
diff --git a/flang/lib/Semantics/openmp-utils.cpp b/flang/lib/Semantics/openmp-utils.cpp
index e837f8dca19f6..a1f8f1f797736 100644
--- a/flang/lib/Semantics/openmp-utils.cpp
+++ b/flang/lib/Semantics/openmp-utils.cpp
@@ -119,22 +119,31 @@ std::string TryVersion(unsigned version) {
return "try -fopenmp-version=" + std::to_string(version);
}
-const Symbol *GetObjectSymbol(const parser::OmpObject &object) {
+const Symbol *GetObjectSymbol(const parser::OmpObject &object, bool ultimate) {
// Some symbols may be missing if the resolution failed, e.g. when an
// undeclared name is used with implicit none.
if (auto *name{std::get_if<parser::Name>(&object.u)}) {
- return name->symbol ? &name->symbol->GetUltimate() : nullptr;
+ if (ultimate) {
+ return name->symbol ? &name->symbol->GetUltimate() : nullptr;
+ } else {
+ return name->symbol;
+ }
} else if (auto *desg{std::get_if<parser::Designator>(&object.u)}) {
- auto &last{GetLastName(*desg)};
- return last.symbol ? &GetLastName(*desg).symbol->GetUltimate() : nullptr;
+ const parser::Name &last{GetLastName(*desg)};
+ if (ultimate) {
+ return last.symbol ? &last.symbol->GetUltimate() : nullptr;
+ } else {
+ return last.symbol;
+ }
}
return nullptr;
}
-const Symbol *GetArgumentSymbol(const parser::OmpArgument &argument) {
+const Symbol *GetArgumentSymbol(
+ const parser::OmpArgument &argument, bool ultimate) {
if (auto *locator{std::get_if<parser::OmpLocator>(&argument.u)}) {
if (auto *object{std::get_if<parser::OmpObject>(&locator->u)}) {
- return GetObjectSymbol(*object);
+ return GetObjectSymbol(*object, ultimate);
}
}
return nullptr;
``````````
</details>
https://github.com/llvm/llvm-project/pull/196816
More information about the flang-commits
mailing list