]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fortran: fix argument checking of intrinsics C_SIZEOF, C_F_POINTER [PR106500]
authorHarald Anlauf <anlauf@gmx.de>
Tue, 9 Apr 2024 21:07:59 +0000 (23:07 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 10 Apr 2024 16:44:05 +0000 (18:44 +0200)
commitded646c91d2c0fb908faf6fa8fe1df0d7df49d16
tree98123a17738d5bb96e99365e1427d14f56374c54
parent912753cc5f18d786e334dd425469fa7f93155661
Fortran: fix argument checking of intrinsics C_SIZEOF, C_F_POINTER [PR106500]

The interpretation of the F2018 standard regarding valid arguments to the
intrinsic C_SIZEOF(X) was clarified in an edit to 18-007r1:

  https://j3-fortran.org/doc/year/22/22-101r1.txt

loosening restrictions and giving examples.  The F2023 text has:

! F2023:18.2.3.8  C_SIZEOF (X)
!
!   X shall be a data entity with interoperable type and type parameters,
!   and shall not be an assumed-size array, an assumed-rank array that
!   is associated with an assumed-size array, an unallocated allocatable
!   variable, or a pointer that is not associated.

where

! 3.41 data entity
!   data object, result of the evaluation of an expression, or the
!   result of the execution of a function reference

Update the checking code for interoperable arguments accordingly, and extend
to reject functions returning pointer as FPTR argument to C_F_POINTER.

gcc/fortran/ChangeLog:

PR fortran/106500
* check.cc (is_c_interoperable): Fix checks for C_SIZEOF.
(gfc_check_c_f_pointer): Reject function returning a pointer as FPTR,
and improve an error message.

gcc/testsuite/ChangeLog:

PR fortran/106500
* gfortran.dg/c_sizeof_6.f90: Remove wrong dg-error.
* gfortran.dg/sizeof_2.f90: Adjust pattern.
* gfortran.dg/c_f_pointer_tests_9.f90: New test.
* gfortran.dg/c_sizeof_7.f90: New test.
gcc/fortran/check.cc
gcc/testsuite/gfortran.dg/c_f_pointer_tests_9.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/c_sizeof_6.f90
gcc/testsuite/gfortran.dg/c_sizeof_7.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/sizeof_2.f90