[flang-commits] [flang] [flang][OpenACC] Relax COMMON block usage restriction in OpenACC directives (PR #162659)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Thu Oct 9 09:16:55 PDT 2025
https://github.com/eugeneepshteyn updated https://github.com/llvm/llvm-project/pull/162659
>From 042d2f66bd632fb5d83df0ca4d5c0a3ede031c1c Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Mon, 6 Oct 2025 05:51:32 -0400
Subject: [PATCH 1/4] [flang] Draft of the work to look up COMMON declarations
in the modules for ACC directives.
---
flang/lib/Semantics/resolve-directives.cpp | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 18fc63814d973..eefd19f3ac6a9 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1695,17 +1695,13 @@ void AccAttributeVisitor::Post(const parser::Name &name) {
Symbol *AccAttributeVisitor::ResolveAccCommonBlockName(
const parser::Name *name) {
- if (auto *prev{name
- ? GetContext().scope.parent().FindCommonBlock(name->source)
- : nullptr}) {
- name->symbol = prev;
- return prev;
- }
- // Check if the Common Block is declared in the current scope
- if (auto *commonBlockSymbol{
- name ? GetContext().scope.FindCommonBlock(name->source) : nullptr}) {
- name->symbol = commonBlockSymbol;
- return commonBlockSymbol;
+ if (!name) {
+ return nullptr;
+ }
+ if (auto *cb{GetProgramUnitOrBlockConstructContaining(GetContext().scope)
+ .FindCommonBlock(name->source)}) {
+ name->symbol = cb;
+ return cb;
}
return nullptr;
}
>From 931b300841960e8c33c4c1351fdeb0ec1916f329 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Thu, 9 Oct 2025 06:30:51 -0400
Subject: [PATCH 2/4] Try to handle use association, but didn't work, because
no symbol
---
flang/lib/Semantics/resolve-directives.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index eefd19f3ac6a9..583f69dca6bbf 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1703,6 +1703,12 @@ Symbol *AccAttributeVisitor::ResolveAccCommonBlockName(
name->symbol = cb;
return cb;
}
+ if (auto *cb{GetContext().scope.FindSymbol(name->source)}) {
+ if (auto *sym{&cb->GetUltimate()}; sym && sym->has<CommonBlockDetails>()) {
+ name->symbol = sym;
+ return sym;
+ }
+ }
return nullptr;
}
>From 86cb8b62c9c546f4e5c909a2500e4e8563bd2839 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Thu, 9 Oct 2025 09:54:23 -0400
Subject: [PATCH 3/4] Searching for COMMON definition in top level modules
---
flang/lib/Semantics/resolve-directives.cpp | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 583f69dca6bbf..a7fcc4d46e4a5 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1698,15 +1698,18 @@ Symbol *AccAttributeVisitor::ResolveAccCommonBlockName(
if (!name) {
return nullptr;
}
+ // Check the local and surrounding scopes first
if (auto *cb{GetProgramUnitOrBlockConstructContaining(GetContext().scope)
.FindCommonBlock(name->source)}) {
name->symbol = cb;
return cb;
}
- if (auto *cb{GetContext().scope.FindSymbol(name->source)}) {
- if (auto *sym{&cb->GetUltimate()}; sym && sym->has<CommonBlockDetails>()) {
- name->symbol = sym;
- return sym;
+ // Look for COMMON block in the modules
+ for (const Scope &childScope : context_.globalScope().children()) {
+ if (childScope.kind() == Scope::Kind::Module) {
+ auto *cb{childScope.FindCommonBlock(name->source)};
+ name->symbol = cb;
+ return cb;
}
}
return nullptr;
@@ -1757,8 +1760,8 @@ void AccAttributeVisitor::ResolveAccObject(
}
} else {
context_.Say(name.source,
- "COMMON block must be declared in the same scoping unit "
- "in which the OpenACC directive or clause appears"_err_en_US);
+ "Could not find COMMON block '%s' used in OpenACC directive"_err_en_US,
+ name.ToString());
}
},
},
>From f462bf5d170e4bbd82cd46d963baef9077985982 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Thu, 9 Oct 2025 12:16:44 -0400
Subject: [PATCH 4/4] Guard against null cb
---
flang/lib/Semantics/resolve-directives.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index a7fcc4d46e4a5..44cfb75e06164 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1707,9 +1707,10 @@ Symbol *AccAttributeVisitor::ResolveAccCommonBlockName(
// Look for COMMON block in the modules
for (const Scope &childScope : context_.globalScope().children()) {
if (childScope.kind() == Scope::Kind::Module) {
- auto *cb{childScope.FindCommonBlock(name->source)};
- name->symbol = cb;
- return cb;
+ if (auto *cb{childScope.FindCommonBlock(name->source)}) {
+ name->symbol = cb;
+ return cb;
+ }
}
}
return nullptr;
More information about the flang-commits
mailing list