From patchwork Tue Mar 5 20:48:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1051992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-497398-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="lPfb0tya"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44DTX50mvJz9s4Y for ; Wed, 6 Mar 2019 07:49:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=tjbRq+c4MLWT744tNrTAD3jE9jCOM6J5ZlOB3/YfAQyHag Jh9g3JMgEKJitBtjug037GpRZ+JNreCn7g1tlJHquAvO0jeqLreQam4mP5iJSuGw Q3gzHgoAD9IbIy80TaKF3GJ1ZUmmPoQKfF9OhVQh8hML4ccejLAn1grWTbhJE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=ApQDu/6G1m08vZiIigK5YfLOcEk=; b=lPfb0tyaSl4XxymnTXjb f3H+i/rLeXRrDnv9Y1UWOKt9lE8pC8bgm8cDKI0I94Uue8Q6i1UzPcsFFDEKfCeH wuISus2kapIU5jFf7kTG4QBq8+6jwVSHk76v3hnR97QyAgMZxVMvPIs/OI2uvb17 ozrWjyeGVEh4LY1qDy9fttI= Received: (qmail 11071 invoked by alias); 5 Mar 2019 20:48:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 10898 invoked by uid 89); 5 Mar 2019 20:48:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=unavailable version=3.3.2 spammy=investigation, anlauf@gmx.de, U*anlauf, Anlauf X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.15.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Mar 2019 20:48:21 +0000 Received: from proton.at.home ([93.207.86.78]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0M0gcI-1hEpYT12ic-00uswA; Tue, 05 Mar 2019 21:48:11 +0100 Message-ID: <5C7EE085.7020502@gmx.de> Date: Tue, 05 Mar 2019 21:48:05 +0100 From: Harald Anlauf User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: gfortran , gcc-patches Subject: [PR fortran/71203, patch] - ICE on zero-length arrays or substrings The attached patch addresses ICEs on several situations with zero-length arrays of strings or zero-length substrings, which were caused by a NULL pointer dereference in those particular situations. To the reviewer: I am not 100% sure that my solution is correct, but it solves the issues reported and regtests cleanly on x86_64-pc-linux-gnu. OK for trunk? Backports? Thanks, Harald P.S.: the PR has another ICE with integer array constructors which is unrelated and under investigation. 2019-03-05 Harald Anlauf PR fortran/71203 * expr.c (simplify_const_ref): Avoid null pointer dereference. 2019-03-05 Harald Anlauf PR fortran/71203 * gfortran.dg/substr_8.f90: New test. Index: gcc/testsuite/gfortran.dg/substr_8.f90 =================================================================== --- gcc/testsuite/gfortran.dg/substr_8.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/substr_8.f90 (working copy) @@ -0,0 +1,15 @@ +! { dg-do run } +! PR fortran/71203 - used to ICE on zero-length arrays or substrings +! Derived from original test cases by Gerhard Steinmetz + +program p + implicit none + character(3), parameter :: a(4) = ' ' + character(*), parameter :: b(4) = 'abc' + character(*), parameter :: x(*) = a(2:2)(3:1) + character(*), parameter :: y(*) = a(2:1)(3:1) + character(*), parameter :: z(*) = b(2:1)(2:3) + if (size (x) /= 1 .or. len(x) /= 0) stop 1 + if (size (y) /= 0 .or. len(y) /= 0) stop 2 + if (size (z) /= 0 .or. len(z) /= 2) stop 3 +end Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (revision 269400) +++ gcc/fortran/expr.c (working copy) @@ -1897,8 +1897,14 @@ string_len = 0; if (!p->ts.u.cl) - p->ts.u.cl = gfc_new_charlen (p->symtree->n.sym->ns, - NULL); + { + if (p->symtree) + p->ts.u.cl = gfc_new_charlen (p->symtree->n.sym->ns, + NULL); + else + p->ts.u.cl = gfc_new_charlen (gfc_current_ns, + NULL); + } else gfc_free_expr (p->ts.u.cl->length);