]> gcc.gnu.org Git - gcc.git/commit
fortran: Fix up gfc_typename CHARACTER length handling [PR97768]
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Nov 2020 07:27:38 +0000 (08:27 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 11 Nov 2020 11:01:13 +0000 (12:01 +0100)
commitf7c2be50afa7935d3a05e3c7761e69d8b539da5b
tree885f8eb4d303292988732682198b58692bf4deae
parenta50729951f1973f4ba66c0f7e79fdd71bb1e4ef2
fortran: Fix up gfc_typename CHARACTER length handling [PR97768]

The first testcase below ICEs when f951 is 32-bit (or 64-bit big-endian).
The problem is that ex->ts.u.cl && ex->ts.u.cl->length are both non-NULL,
but ex->ts.u.cl->length->expr_type is not EXPR_CONSTANT, but EXPR_FUNCTION.
value.function.actual and value.function.name are in that case pointers,
but value._mp_alloc and value._mp_size are 4 byte integers no matter what.
So, in 64-bit little-endian the function returns most of the time incorrect
CHARACTER(0) because the most significant 32 bits of the
value.function.actual pointer are likely 0.
Anyway, the following patch is an attempt to get all the cases right.
Uses ex->value.character.length only for ex->expr_type == EXPR_CONSTANT
(i.e. CHARACTER literals), handles the deferred lengths, assumed lengths,
known constant lengths and finally if the length is something other,
just doesn't print it, i.e. prints just CHARACTER (for default kind)
or CHARACTER(KIND=4) (for e.g. kind 4).

2020-11-11  Jakub Jelinek  <jakub@redhat.com>

PR fortran/97768
gcc/fortran/
* misc.c (gfc_typename): Use ex->value.character.length only if
ex->expr_type == EXPR_CONSTANT.  If ex->ts.deferred, print : instead
of length.  If ex->ts.u.cl && ex->ts.u.cl->length == NULL, print *
instead of length.  Otherwise if character length is non-constant,
print just CHARACTER or CHARACTER(KIND=N).
gcc/testsuite/
* gfortran.dg/pr97768_1.f90: New test.
* gfortran.dg/pr97768_2.f90: New test.

(cherry picked from commit 81372618277bfae682434fcdc80b311ee6007476)
gcc/fortran/misc.c
gcc/testsuite/gfortran.dg/pr97768_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr97768_2.f90 [new file with mode: 0644]
This page took 0.069547 seconds and 5 git commands to generate.