Fortran: Fix Bind(C) char-len check, add ptr-contiguous check
authorTobias Burnus <tobias@codesourcery.com>
Fri, 3 Sep 2021 14:28:04 +0000 (16:28 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 3 Sep 2021 14:28:04 +0000 (16:28 +0200)
commit943c65c4494145e993af43c821c82000013c6375
tree260660a474fe8e3b4acd60cbbe450c874890f3c1
parent2fcfc03459a907c0237ea6e2c6e4ce4871034bed
Fortran: Fix Bind(C) char-len check, add ptr-contiguous check

Add F2018, 18.3.6 (5), pointer + contiguous is not permitted
check for dummies in BIND(C) procs.

Fix misreading of F2018, 18.3.4/18.3.5 + 18.3.6 (5) regarding
character dummies passed as byte stream to a bind(C) dummy arg:
Per F2018, 18.3.1 only len=1 is interoperable (since F2003).
F2008 added 'constant expression' for vars (F2018, 18.3.4/18.3.5),
applicable to dummy args per F2018, C1554. I misread this such
that len > 1 is permitted if len is a constant expr.

While the latter would work as character len=1 a(10) and len=2 a(5)
have the same storage sequence and len is fixed, it is still invalid.
Hence, it is now rejected again.

gcc/fortran/ChangeLog:

* decl.c (gfc_verify_c_interop_param): Reject pointer with
CONTIGUOUS attributes as dummy arg. Reject character len > 1
when passed as byte stream.

gcc/testsuite/ChangeLog:

* gfortran.dg/bind_c_char_6.f90: Update dg-error.
* gfortran.dg/bind_c_char_7.f90: Likewise.
* gfortran.dg/bind_c_char_8.f90: Likewise.
* gfortran.dg/iso_c_binding_char_1.f90: Likewise.
* gfortran.dg/pr32599.f03: Likewise.
* gfortran.dg/bind_c_char_9.f90: Comment testcase bits which are
implementable but not valid F2018.
* gfortran.dg/bind_c_contiguous.f90: New test.
gcc/fortran/decl.c
gcc/testsuite/gfortran.dg/bind_c_char_6.f90
gcc/testsuite/gfortran.dg/bind_c_char_7.f90
gcc/testsuite/gfortran.dg/bind_c_char_8.f90
gcc/testsuite/gfortran.dg/bind_c_char_9.f90
gcc/testsuite/gfortran.dg/bind_c_contiguous.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/iso_c_binding_char_1.f90
gcc/testsuite/gfortran.dg/pr32599.f03