From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id CD5B33858C20; Fri, 9 Jun 2023 07:58:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD5B33858C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686297511; bh=JrMT3wqFtsdVYSFcnNHjVgcJfenWrMTjj23c3SVynL8=; h=From:To:Subject:Date:From; b=LGr5JxpYv1GkLITTuSF0DWJe6f/tINH1cZ73ZeJShbjwENVsgzfEQ1HTE9r985h1x aCWffRda4iyDaFpebIF5tXZyJ4AhMRqxuA+F+NbsoYsMFyZoNKU/aKz+BSUC9S3b1b susmW9AsZdqLq7sIR+hn83/+Jmt7ZiedTLEo4YeM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9687] fortran: Fix ICE on pr96024.f90 on big-endian hosts [PR96024] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 887f903ab05ddcac498247384734efbc6cf45147 X-Git-Newrev: bc4adb88611cb17280ab15ac4e13ab1d05b11825 Message-Id: <20230609075831.CD5B33858C20@sourceware.org> Date: Fri, 9 Jun 2023 07:58:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bc4adb88611cb17280ab15ac4e13ab1d05b11825 commit r12-9687-gbc4adb88611cb17280ab15ac4e13ab1d05b11825 Author: Jakub Jelinek Date: Fri Jun 9 09:10:29 2023 +0200 fortran: Fix ICE on pr96024.f90 on big-endian hosts [PR96024] 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 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. (cherry picked from commit 4cf6e322adc19f927859e0a5edfa93cec4b8c844) Diff: --- gcc/fortran/primary.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index e48ba755c8a..1ae6a12e0b7 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -3196,10 +3196,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) {