https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127682
Bug ID: 127682
Summary: Rules on volatile dummy arrays ignoring polymorphic
arguments
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: mikael at gcc dot gnu.org
Target Milestone: ---
The compiler uses this excerpt from compare_parameter (interface.cc) to check
the F2023 rules about volatile dummy arguments (C1548 and C1549):
2836 /* F2008, C1239/C1240. */
2837 if (actual->expr_type == EXPR_VARIABLE
2838 && (actual->symtree->n.sym->attr.asynchronous
2839 || actual->symtree->n.sym->attr.volatile_)
2840 && (formal->attr.asynchronous || formal->attr.volatile_)
2841 && actual->rank && formal->as
2842 && !gfc_is_simply_contiguous (actual, true, false)
2843 && ((formal->as->type != AS_ASSUMED_SHAPE
2844 && formal->as->type != AS_ASSUMED_RANK &&
!formal->attr.pointer)
2845 || formal->attr.contiguous))
2846 {
2847 if (where)
2848 gfc_error ("Dummy argument %qs has to be a pointer,
assumed-shape or "
2849 "assumed-rank array without CONTIGUOUS attribute -
as actual"
2850 " argument at %L is not simply contiguous and both
are "
2851 "ASYNCHRONOUS or VOLATILE", formal->name,
&actual->where);
2852 return false;
2853 }
The problem is this doesn't match with polymorphic formal arguments.
Here is a testcase:
program prog
implicit none
integer, parameter :: n = 5
type :: t1
integer :: c1
end type
type, extends(t1) :: t2
integer :: c2
end type
type(t2), volatile :: x(n)
call sub1(x%t1)
call sub2(x%t1)
call sub3(x%t1)
call sub4(x%t1)
contains
subroutine sub1(a)
class(t1), volatile :: a(n)
end subroutine
subroutine sub2(a)
class(t1), volatile :: a(*)
end subroutine
subroutine sub3(a)
class(t1), volatile, contiguous :: a(:)
end subroutine
subroutine sub4(a)
class(t1), volatile, contiguous :: a(..)
end subroutine
end program
I expect all four cases to be rejected because they don't respect the
conditions.
For reference the condition C1548(R1524) is:
> If an actual argument is a nonpointer array that has the ASYNCHRONOUS or
> VOLATILE attribute but is not simply contiguous (9.5.4), and the corresponding
> dummy argument has either the ASYNCHRONOUS or VOLATILE attribute, but does not
> have the VALUE attribute, that dummy argument shall be assumed-shape or
> assumed-rank and shall not have the CONTIGUOUS attribute.
C1549 is similar for pointers, permitting additionally a pointer dummy.