From patchwork Sun Sep 15 13:55:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1162472 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-509014-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="sb/TKp/h"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="KeNlLrls"; 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 46WWB83wr6z9sPD for ; Sun, 15 Sep 2019 23:56:14 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=XIHN+1PSNsL9N5SMUXNFaicypmo2hZGQLMOfAt/uU01HW+XkS3 H/F+5LVcr6fR9qnMOnD5Xgx6VQfE3xhd37C2D9Wji5J9XknXfjmjMTrRi+HTKZBX yK9h8JkX+itP/VlHF4HDzNGXoiUeCHXL4iCZq5MFv/pJnEPmMesUstLo0= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=bGSnNmciZGMr34V35SEfj6x0rsQ=; b=sb/TKp/hjlmdKkhk28JX m9GPbiX720G0LAROO6fSjHlqrTPnL0VgDFs8R0y2At/xwwUqQzDWh3MmHymy7r3H tn0B7/0t+OVO2vjoOI9FqdXqqaZnLzZzepScjOg4BHg0PhZ2+tqB66lpavgSPZvj pNF4uWoFAINlD3R6Efqc4yk= Received: (qmail 125824 invoked by alias); 15 Sep 2019 13:56:02 -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 125807 invoked by uid 89); 15 Sep 2019 13:56:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=rea, H*r:IPv6 X-HELO: cc-smtpout2.netcologne.de Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 15 Sep 2019 13:56:00 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 4B7C712724; Sun, 15 Sep 2019 15:55:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1568555757; bh=6i08z9euqQE0HiNaaQVRIoxQ2qAkU5nivC5JM9ab8aw=; h=To:From:Subject:Message-ID:Date:From; b=KeNlLrlsGxTTX1HSQ4QgGcF3n2s8YEJCY1aEJDHqjLx9gCZqFjHsHOBcfCHv+6QU9 wfgmMjaWCQioAUWCnVuXVfn17pL6MDVYi3+lSHP795VDAYgrDD7OZl20M610pqMpRn 5jdxK4Xj6dyhgD/fvfmB6U4qBVwdjQNnnTNpe/Mr/NZ9XT6POId+Cq9oLCpiOTf8GO AUgwAfGCek0snIzj+ceh5AFfpfFRE+3r3Y1jDZw6alWzlpywdKC+QY/1KW1fa/S1/P ha0wQvp+JWufUg3amKchjkB7wyf74CpBpnZuNjRQDp+FgrkTPODMPdcF2AM0KP7k6/ 6sijB5dv83iYw== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id 3D52C11EEC; Sun, 15 Sep 2019 15:55:57 +0200 (CEST) Received: from [2001:4dd7:f354:0:7285:c2ff:fe6c:992d] (helo=cc-smtpin1.netcologne.de) by localhost with ESMTP (eXpurgate 4.6.0) (envelope-from ) id 5d7e42ed-5e31-7f0000012729-7f000001a906-1 for ; Sun, 15 Sep 2019 15:55:57 +0200 Received: from [IPv6:2001:4dd7:f354:0:7285:c2ff:fe6c:992d] (2001-4dd7-f354-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd7:f354:0:7285:c2ff:fe6c:992d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA; Sun, 15 Sep 2019 15:55:55 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Fix ICE on invalid with DO steps Message-ID: <67bcc60c-bf7c-2255-593a-395f8548aa3e@netcologne.de> Date: Sun, 15 Sep 2019 15:55:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 Hello world, the attached patch fixes an ICE on invalid, where the fact that the step in do i = 1, 3, .1 is actually zero slipped through. Regression-tested. OK for all affected branches (trunk, 9 and 8)? Regards Thomas 2019-09-15 Thomas Koenig PR fortran/91550 * frontend-passes.c (do_subscript): If step equals zero, a previuos error has been reported; do nothing in this case. * resolve.c (gfc_resolve_iterator): Move error checking after type conversion. 2019-09-15 Thomas Koenig PR fortran/91550 * gfortran.dg/do_subscript_6.f90: New test. Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 275719) +++ frontend-passes.c (Arbeitskopie) @@ -2578,6 +2578,7 @@ do_subscript (gfc_expr **e) bool have_do_start, have_do_end; bool error_not_proven; int warn; + int sgn; dl = lp->c; if (dl == NULL) @@ -2606,7 +2607,16 @@ do_subscript (gfc_expr **e) Do not warn in this case. */ if (dl->ext.iterator->step->expr_type == EXPR_CONSTANT) - mpz_init_set (do_step, dl->ext.iterator->step->value.integer); + { + sgn = mpz_cmp_ui (dl->ext.iterator->step->value.integer, 0); + /* This can happen, but then the error has been + reported previusly. */ + if (sgn == 0) + continue; + + mpz_init_set (do_step, dl->ext.iterator->step->value.integer); + } + else continue; @@ -2632,9 +2642,8 @@ do_subscript (gfc_expr **e) /* No warning inside a zero-trip loop. */ if (have_do_start && have_do_end) { - int sgn, cmp; + int cmp; - sgn = mpz_cmp_ui (do_step, 0); cmp = mpz_cmp (do_end, do_start); if ((sgn > 0 && cmp < 0) || (sgn < 0 && cmp > 0)) break; Index: resolve.c =================================================================== --- resolve.c (Revision 275719) +++ resolve.c (Arbeitskopie) @@ -7105,6 +7105,19 @@ gfc_resolve_iterator (gfc_iterator *iter, bool rea "Step expression in DO loop")) return false; + /* Convert start, end, and step to the same type as var. */ + if (iter->start->ts.kind != iter->var->ts.kind + || iter->start->ts.type != iter->var->ts.type) + gfc_convert_type (iter->start, &iter->var->ts, 1); + + if (iter->end->ts.kind != iter->var->ts.kind + || iter->end->ts.type != iter->var->ts.type) + gfc_convert_type (iter->end, &iter->var->ts, 1); + + if (iter->step->ts.kind != iter->var->ts.kind + || iter->step->ts.type != iter->var->ts.type) + gfc_convert_type (iter->step, &iter->var->ts, 1); + if (iter->step->expr_type == EXPR_CONSTANT) { if ((iter->step->ts.type == BT_INTEGER @@ -7118,19 +7131,6 @@ gfc_resolve_iterator (gfc_iterator *iter, bool rea } } - /* Convert start, end, and step to the same type as var. */ - if (iter->start->ts.kind != iter->var->ts.kind - || iter->start->ts.type != iter->var->ts.type) - gfc_convert_type (iter->start, &iter->var->ts, 1); - - if (iter->end->ts.kind != iter->var->ts.kind - || iter->end->ts.type != iter->var->ts.type) - gfc_convert_type (iter->end, &iter->var->ts, 1); - - if (iter->step->ts.kind != iter->var->ts.kind - || iter->step->ts.type != iter->var->ts.type) - gfc_convert_type (iter->step, &iter->var->ts, 1); - if (iter->start->expr_type == EXPR_CONSTANT && iter->end->expr_type == EXPR_CONSTANT && iter->step->expr_type == EXPR_CONSTANT)