Bind(c): Improve error checking in CFI_* functions
authorSandra Loosemore <sandra@codesourcery.com>
Thu, 15 Jul 2021 15:48:45 +0000 (08:48 -0700)
committerSandra Loosemore <sandra@codesourcery.com>
Wed, 28 Jul 2021 04:24:26 +0000 (21:24 -0700)
commite78480ad0983cf75813af5e02d68cdad09e441e9
tree119e874fc8e6152a726c45033abd0db054219327
parentb4a9bc7856ee1d3ff98b04402334a362540af2cf
Bind(c): Improve error checking in CFI_* functions

This patch adds additional run-time checking for invalid arguments to
CFI_establish and CFI_setpointer.  It also changes existing messages
throughout the CFI_* functions to use PRIiPTR to format CFI_index_t
values instead of casting them to int and using %d (which may not work
on targets where int is a smaller type), simplifies wording of some
messages, and fixes issues with capitalization, typos, and the like.
Additionally some coding standards problems such as >80 character lines
are addressed.

2021-07-24  Sandra Loosemore  <sandra@codesourcery.com>

PR libfortran/101317

libgfortran/
* runtime/ISO_Fortran_binding.c: Include <inttypes.h>.
(CFI_address): Tidy error messages and comments.
(CFI_allocate): Likewise.
(CFI_deallocate): Likewise.
(CFI_establish): Likewise.  Add new checks for validity of
elem_len when it's used, plus type argument and extents.
(CFI_is_contiguous): Tidy error messages and comments.
(CFI_section): Likewise.  Refactor some repetitive code to
make it more understandable.
(CFI_select_part): Likewise.
(CFI_setpointer): Likewise.  Check that source is not an
unallocated allocatable array or an assumed-size array.

gcc/testsuite/
* gfortran.dg/ISO_Fortran_binding_17.f90: Fix typo in error
message patterns.
gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.f90
libgfortran/runtime/ISO_Fortran_binding.c