]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: Fix ICE on pr96024.f90 on big-endian hosts [PR96024]
authorJakub Jelinek <jakub@redhat.com>
Fri, 9 Jun 2023 07:10:29 +0000 (09:10 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 9 Jun 2023 07:10:29 +0000 (09:10 +0200)
The pr96024.f90 testcase ICEs on big-endian hosts.  The problem is
that length->val.integer is accessed after checking
length->expr_type == EXPR_CONSTANT, but it is a CHARACTER constant
which uses length->val.character union member instead and on big-endian
we end up reading constant 0x100000000 rather than some small number
on little-endian and if target doesn't have enough memory for 4 times
that (i.e. 16GB allocation), it ICEs.

2023-06-09  Jakub Jelinek  <jakub@redhat.com>

PR fortran/96024
* primary.cc (gfc_convert_to_structure_constructor): Only do
constant string ctor length verification and truncation/padding
if constant length has INTEGER type.

gcc/fortran/primary.cc

index 3099f82850c661edbb9a279d4e08e81e9d9e9ec6..0bb440b85a9165b3164b607c7af513e305657db0 100644 (file)
@@ -3188,10 +3188,11 @@ gfc_convert_to_structure_constructor (gfc_expr *e, gfc_symbol *sym, gfc_expr **c
        goto cleanup;
 
       /* For a constant string constructor, make sure the length is
-        correct; truncate of fill with blanks if needed.  */
+        correct; truncate or fill with blanks if needed.  */
       if (this_comp->ts.type == BT_CHARACTER && !this_comp->attr.allocatable
          && this_comp->ts.u.cl && this_comp->ts.u.cl->length
          && this_comp->ts.u.cl->length->expr_type == EXPR_CONSTANT
+         && this_comp->ts.u.cl->length->ts.type == BT_INTEGER
          && actual->expr->ts.type == BT_CHARACTER
          && actual->expr->expr_type == EXPR_CONSTANT)
        {