Skip to content

Commit 2f54c83

Browse files
VijayKandiahgithub-actions[bot]
authored andcommitted
Automerge: [flang][cuda] Skip implicit managed/unified attribution for COMMON objects (#209855)
Objects in Fortran `COMMON` blocks may not carry `ATTRIBUTES(MANAGED)` or `ATTRIBUTES(UNIFIED)`. The implicit attribution added in [#209292](llvm/llvm-project#209292) did not account for this, causing a spurious semantic error when a pointer in a `COMMON` block was implicitly attributed. This change adds a `!object->commonBlock()` guard to `SetImplicitCUDADataAttr` so that COMMON members are left unattributed.
2 parents 100d966 + 77e9b8c commit 2f54c83

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

flang/lib/Semantics/resolve-names.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10616,7 +10616,8 @@ void DeclarationVisitor::SetImplicitCUDADataAttr(Symbol &symbol) {
1061610616
// program, or component) so generic resolution still selects the
1061710617
// unified specific; fall back to Managed elsewhere (module scope,
1061810618
// device subprograms), which uses the same allocator.
10619-
if (cudaEnabled && (cudaManaged || cudaUnified)) {
10619+
// COMMON objects may not carry managed/unified attributes.
10620+
if (cudaEnabled && (cudaManaged || cudaUnified) && !object->commonBlock()) {
1062010621
const Scope &owner{symbol.owner()};
1062110622
const bool unifiedAllowed{!IsCUDADeviceContext(&owner) &&
1062210623
(owner.IsDerivedType() || owner.kind() == Scope::Kind::MainProgram ||

flang/test/Lower/CUDA/cuda-implicit-managed-alloc.cuf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ contains
2121
real, allocatable :: loc_arr(:)
2222
real, pointer :: loc_ptr(:)
2323
end subroutine
24+
subroutine common_sub()
25+
real, pointer :: com_ptr(:)
26+
common /blk/ com_ptr
27+
end subroutine
2428
end module
2529

2630
program p
@@ -34,6 +38,10 @@ end program
3438
! MAN: hlfir.declare {{.*}} {data_attr = #cuf.cuda<managed>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMmFmod_subEloc_arr"}
3539
! MAN: hlfir.declare {{.*}} {data_attr = #cuf.cuda<managed>, fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMmFmod_subEloc_ptr"}
3640

41+
! COMMON-block pointer: unattributed, CUDA attributes may not appear in COMMON.
42+
! UNI: hlfir.declare {{.*}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMmFcommon_subEcom_ptr"}
43+
! MAN: hlfir.declare {{.*}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMmFcommon_subEcom_ptr"}
44+
3745
! Main-program local: Unified under -gpu=unified, Managed under
3846
! -gpu=managed.
3947
! UNI: hlfir.declare {{.*}} {data_attr = #cuf.cuda<unified>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFEprog_arr"}

0 commit comments

Comments
 (0)