Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
042d2f6
[flang] Draft of the work to look up COMMON declarations in the modules
eugeneepshteyn Oct 6, 2025
f31c976
Merge branch 'main' into 2-acc-common
eugeneepshteyn Oct 6, 2025
931b300
Try to handle use association, but didn't work, because no symbol
eugeneepshteyn Oct 9, 2025
0bfb06c
Merge branch 'main' into 2-acc-common
eugeneepshteyn Oct 9, 2025
86cb8b6
Searching for COMMON definition in top level modules
eugeneepshteyn Oct 9, 2025
f462bf5
Guard against null cb
eugeneepshteyn Oct 9, 2025
14ce6b6
Unit test
eugeneepshteyn Oct 9, 2025
8c344c3
Merge branch 'llvm:main' into 2-acc-common
eugeneepshteyn Oct 9, 2025
e00d8f5
Merge branch '2-acc-common' into 3-acc-common
eugeneepshteyn Oct 10, 2025
827f8f0
Merge branch 'llvm:main' into 3-acc-common
eugeneepshteyn Oct 12, 2025
430660f
Merge branch 'llvm:main' into 3-acc-common
eugeneepshteyn Oct 13, 2025
ff637dd
Updated Scope::FindCommonBlock() to be similar to Scope::FindSymbol()…
eugeneepshteyn Oct 13, 2025
9e19979
clang-format
eugeneepshteyn Oct 13, 2025
66028ef
Split FindCommonBlock() into FindCB() and FindCommonBlockInScopes(). …
eugeneepshteyn Oct 13, 2025
41336f1
Add USE association details to COMMON blocks
eugeneepshteyn Oct 13, 2025
eac75b7
Handle the case of redeclared COMMON block
eugeneepshteyn Oct 13, 2025
553a3c3
clang-format
eugeneepshteyn Oct 13, 2025
63662d8
Merge branch 'llvm:main' into 3-acc-common
eugeneepshteyn Oct 13, 2025
adcd69b
Merge branch 'llvm:main' into 2-acc-common
eugeneepshteyn Oct 13, 2025
74de636
Merge branch '3-acc-common' into 2-acc-common
eugeneepshteyn Oct 13, 2025
6527159
Merge branch 'llvm:main' into 3-acc-common
eugeneepshteyn Oct 16, 2025
c042379
Code review feedback + separated COMMON lists into COMMON in the curr…
eugeneepshteyn Oct 16, 2025
740894f
COMMON block uses renames. Extended test to using module chain
eugeneepshteyn Oct 16, 2025
ca82173
clang-format
eugeneepshteyn Oct 16, 2025
2474da0
Enabled creating of USE symbols from USE symbols of COMMON blocks
eugeneepshteyn Oct 16, 2025
68363d2
Merge branch 'llvm:main' into 3-acc-common
eugeneepshteyn Oct 16, 2025
5c84d48
clang-format
eugeneepshteyn Oct 16, 2025
cc4145c
Merge branch 'llvm:main' into 2-acc-common
eugeneepshteyn Oct 16, 2025
06b2a01
Merge branch '3-acc-common' into 2-acc-common
eugeneepshteyn Oct 16, 2025
8f802f7
Code review feedback
eugeneepshteyn Oct 16, 2025
b711009
Renamed to FindCommonBlockInVisibleScope()
eugeneepshteyn Oct 17, 2025
ee0cdde
clang-format
eugeneepshteyn Oct 17, 2025
5349a65
Merge branch 'llvm:main' into 2-acc-common
eugeneepshteyn Oct 17, 2025
b268f4e
Merge branch 'llvm:main' into 3-acc-common
eugeneepshteyn Oct 20, 2025
6c8e7a0
Code review feedback
eugeneepshteyn Oct 16, 2025
bab4e67
Renamed to FindCommonBlockInVisibleScope()
eugeneepshteyn Oct 17, 2025
ab01526
clang-format
eugeneepshteyn Oct 17, 2025
f2028c7
Code review feedback
eugeneepshteyn Oct 20, 2025
258050f
Merge branch 'llvm:main' into 3-acc-common
eugeneepshteyn Oct 20, 2025
adf6b5f
Merge branch 'llvm:main' into 2-acc-common
eugeneepshteyn Oct 20, 2025
86dc6a7
Merge branch '3-acc-common' into 2-acc-common
eugeneepshteyn Oct 20, 2025
acde775
clang-format
eugeneepshteyn Oct 20, 2025
abd2f40
[AddOrUpdateCommonBlockUse] Implemented selection of largest COMMON b…
eugeneepshteyn Oct 20, 2025
fc6beb7
[AddOrUpdateCommonBlockUse] Implemented selection of largest COMMON b…
eugeneepshteyn Oct 20, 2025
19c1534
clang-format
eugeneepshteyn Oct 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,17 +1695,23 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be more clear as if (name) { ..., I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return nullptr;
}
// Check the local and surrounding scopes first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only check the innermost BLOCK construct or subprogram, not any containing construct or host subprogram.

if (auto *cb{GetProgramUnitOrBlockConstructContaining(GetContext().scope)
.FindCommonBlock(name->source)}) {
name->symbol = cb;
return cb;
}
// Look for COMMON block in the modules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that this part makes sense? Do you have an example where NVF looks at non-USE-associated modules? You probably just want to look for a USE-associated common block in the enclosing scopes instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been very convenient to have a USE-associated common block available, but I don't see one created. With this program

module acc_decl
  implicit none
  integer a
  common /a_common/ a
!$acc declare create (/a_common/)
  data a/42/
end module acc_decl

program acc_decl_test
  use acc_decl
  implicit none

  a = 1
!$acc update device (/a_common/)
  a = 2
end program

... and -fdebug-dump-symbols I only see

  MainProgram scope: ACC_DECL_TEST size=0 alignment=1 sourceRange=72 bytes
    a (InDataStmt, InCommonBlock): Use from a in acc_decl

Perhaps this is the problem? Perhaps we should be creating USE-associated symbol from its use in !$acc update device (/a_common/)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so.

for (const Scope &childScope : context_.globalScope().children()) {
if (childScope.kind() == Scope::Kind::Module) {
if (auto *cb{childScope.FindCommonBlock(name->source)}) {
name->symbol = cb;
return cb;
}
}
}
return nullptr;
}
Expand Down Expand Up @@ -1755,8 +1761,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());
}
},
},
Expand Down
19 changes: 19 additions & 0 deletions flang/test/Semantics/OpenACC/acc-common.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenacc
module acc_common_decl
implicit none
integer a
common /a_common/ a
!$acc declare create (/a_common/)
data a/42/
end module acc_common_decl

program acc_decl_test
use acc_common_decl
implicit none

a = 1
!$acc update device (/a_common/)
a = 2
!ERROR: Could not find COMMON block 'a_common_bad' used in OpenACC directive
!$acc update device (/a_common_bad/)
end program