https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112316
Bug ID: 112316 Summary: [13 Regression] Fix for PR87477 rejects valid code with a bogus error about pointer assignment and causes an ICE Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: trnka at scm dot com Target Milestone: --- Current releases/gcc-13 rejects the following testcase (compiled simply using gfortran -c test-bogus-pointer-arg-error.f90): ===== test-bogus-pointer-arg-error.f90 ===== module BogusPointerArgError implicit none type :: AType end type contains subroutine A () class(AType), allocatable :: x allocate(x) call B (x) end subroutine subroutine B (y) class(AType), intent(in) :: y end subroutine subroutine C (z) class(AType), intent(in) :: z(:) associate (xxx => z(1)) end associate end subroutine end module ========== 14 | call B (x) | 1 Error: Actual argument for ‘y’ at (1) must be a pointer or a valid target for the dummy pointer in a pointer assignment statement Apparently, both the associate block in C (which is never called) and routines A and B need to be present to trigger the issue. It also seems to only happen when "x" is polymorphic (class(AType)). A related testcase is also rejected, this time with an ICE: ===== test-ICE-get_descriptor_field.f90 ===== module AModule implicit none private public AType type, abstract :: AType contains generic, public :: assignment(=) => Assign procedure, private :: Assign end type AType contains subroutine Assign(lhs, rhs) class(AType), intent(inout) :: lhs class(AType), intent(in) :: rhs end subroutine end module AModule module ICEGetDescriptorField use AModule implicit none contains subroutine Foo (x) class(AType), intent(in) :: x(:) class(AType), allocatable :: y associate (xxx => x(1)) y = xxx end associate end subroutine end module ICEGetDescriptorField ========== test-ICE-get_descriptor_field.f90:38:16: 38 | y = xxx | 1 internal compiler error: in gfc_get_descriptor_field, at fortran/trans-array.cc:245 This time, AType needs to be in a separate module and have a defined assignment to trigger the bug. Both issues bisect to the following commit. Reverting this change on top of current releases/gcc-13 makes both issues go away. (GCC 14 is likely also affected, not tested.) https://gcc.gnu.org/g:d6997a5aab7aaa325946a6283bfee8ac2bd9f540 commit r13-7761-gd6997a5aab7aaa325946a6283bfee8ac2bd9f540 Author: Paul Thomas <pa...@gcc.gnu.org> Date: Sun Aug 27 09:51:32 2023 +0100 Fortran: Fix some problems blocking associate meta-bug [PR87477]