From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 389523858D35; Tue, 1 Feb 2022 20:37:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 389523858D35 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6977] Fortran: error recovery when simplifying EOSHIFT X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/master X-Git-Oldrev: 95ac5635409606386259d2ff21fb61738858ca4a X-Git-Newrev: 447047a8f95c6bf4b1873f390c833e91aa8af18c Message-Id: <20220201203707.389523858D35@sourceware.org> Date: Tue, 1 Feb 2022 20:37:07 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 20:37:07 -0000 https://gcc.gnu.org/g:447047a8f95c6bf4b1873f390c833e91aa8af18c commit r12-6977-g447047a8f95c6bf4b1873f390c833e91aa8af18c Author: Harald Anlauf Date: Tue Feb 1 21:36:42 2022 +0100 Fortran: error recovery when simplifying EOSHIFT gcc/fortran/ChangeLog: PR fortran/104331 * simplify.cc (gfc_simplify_eoshift): Avoid NULL pointer dereference when shape is not set. gcc/testsuite/ChangeLog: PR fortran/104331 * gfortran.dg/eoshift_9.f90: New test. Diff: --- gcc/fortran/simplify.cc | 3 +++ gcc/testsuite/gfortran.dg/eoshift_9.f90 | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index 8604162cfd5..6483f9c31e7 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -2572,6 +2572,9 @@ gfc_simplify_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary, if (arraysize == 0) goto final; + if (array->shape == NULL) + goto final; + arrayvec = XCNEWVEC (gfc_expr *, arraysize); array_ctor = gfc_constructor_first (array->value.constructor); for (i = 0; i < arraysize; i++) diff --git a/gcc/testsuite/gfortran.dg/eoshift_9.f90 b/gcc/testsuite/gfortran.dg/eoshift_9.f90 new file mode 100644 index 00000000000..f711b04a7da --- /dev/null +++ b/gcc/testsuite/gfortran.dg/eoshift_9.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! PR fortran/104331 - ICE in gfc_simplify_eoshift +! Contributed by G.Steinmetz + +program p + character(3), parameter :: a(:) = ['123'] ! { dg-error "deferred shape" } + character(3), parameter :: b(*) = eoshift(a, 1) +end