[flang-commits] [flang] [flang][cuda] Propagate CUDA attrs from parent variable to component deallocs (PR #220059)
Vijay Kandiah via flang-commits
flang-commits at lists.llvm.org
Mon Aug 31 13:46:42 PDT 2026
VijayKandiah wrote:
> Can you check whether the parent attribute overrides the component's own attribute here?
>
> ```fortran
> module m
> type :: t
> real(8), device, allocatable :: d(:)
> end type
> end module
>
> subroutine s()
> use m
> type(t), managed, allocatable :: x(:)
> allocate(x(1))
> allocate(x(1)%d(10))
> deallocate(x(1)%d)
> end subroutine
> ```
>
> Here `d` has its own `device` attribute and the parent `x` is `managed`. The ALLOCATE uses `d`'s own attribute, since `genSimpleAllocation` only looks at the parent when the object has no attribute of its own. The new DEALLOCATE code looks at the parent first, so I think it would pick `managed` — allocating with one allocator and freeing with another.
>
> Could both sides use the same precedence?
Good point, this was a mismatch. `unwrapSymbol` returns the component, but `getCUDAAttrParentSymbol` walks past it to the parent, and I was passing that result unconditionally, so on your example `ALLOCATE` used device from `d` while `DEALLOCATE` used managed from `x`.
This is fixed in the latest commit by gating the parent lookup on the same condition `genSimpleAllocation` uses, so the object's own attribute wins and the parent is consulted only when it has none. Added test `component_attr_wins_over_parent` covering your case.
https://github.com/llvm/llvm-project/pull/220059
More information about the flang-commits
mailing list