The master branch has been updated by Jerry DeLisle <[email protected]>:
https://gcc.gnu.org/g:d49facb09dfc467069b71a24b8a1de470dc472d1
commit r17-6520-gd49facb09dfc467069b71a24b8a1de470dc472d1
On 11/20/26 12:46 PM, Jerry D wrote:
This one is an oldie. I plan to commit soon unless objections.
Regards
Jerry
On 11/14/26 5:29 PM, Jerry DeLisle wrote:
See attached patch. gfortran represents a polymorphic associate name by
a class container, and gfc_variable_attr gave the associate name that
container's POINTER attribute. In a TYPE IS block the associate name
refers to the selector through the hidden _data component, which is
always a pointer, so the TARGET check also saw a pointer. The patch
clears POINTER and ALLOCATABLE for every associate name except that of
SELECT RANK, and looks through _data to the selector for TARGET. Trunk
reports four of the seven errors in the new test pr54322.f90; with the
patch it reports all seven, at the same lines as flang.
The fix is in gfc_variable_attr in primary.cc; the rest is tests.
associate_42.f90 pointer-assigned the associate name. It now
pointer-assigns obj%p after END ASSOCIATE rather than inside the
block, because inside the block END ASSOCIATE undoes the assignment
(PR128735). select_type_30.f03 passed an associate name to a POINTER
dummy, which is valid only if the dummy is INTENT(IN).
Regression tested on x86_64.
OK for mainline?
Regards,
Jerry
---
fortran: [PR54322] Associate names are neither POINTER nor ALLOCATABLE
An associate name has neither the POINTER nor the ALLOCATABLE attribute,
and has the TARGET attribute only if the selector is a variable with the
TARGET or POINTER attribute (F2023 11.1.3.3). gfortran gave a
polymorphic associate name the POINTER attribute of its class container,
so it accepted pointer assignment to the associate name and, in a TYPE
IS block, pointer assignment to it from a selector that was neither
TARGET nor POINTER.
Clear POINTER and ALLOCATABLE for an associate name other than that of
SELECT RANK, and take TARGET from a SELECT TYPE selector rather than
from the _data component that narrows it. Two tests relied on the old
behavior: associate_42.f90 pointer-assigned an associate name, and
select_type_30.f03 passed one to a POINTER dummy without INTENT(IN).
Assisted-by: Claude Opus 5.5
PR fortran/54322
gcc/fortran/ChangeLog:
* primary.cc (gfc_variable_attr): Clear POINTER and ALLOCATABLE for
an associate name, except for SELECT RANK. Take TARGET from a
SELECT TYPE selector rather than from its _data component.
gcc/testsuite/ChangeLog:
* gfortran.dg/associate_42.f90: Pointer-assign the selector, not
the associate name.
* gfortran.dg/select_type_30.f03: Make the POINTER dummy
INTENT(IN).
* gfortran.dg/pr54322.f90: New test.