From patchwork Thu Apr 16 11:53:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1271667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=RGaVv3lU; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 492yKx5CGqz9sP7 for ; Thu, 16 Apr 2020 21:53:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82875385DC32; Thu, 16 Apr 2020 11:53:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82875385DC32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587038014; bh=Mn72XIYp2IlU+10MlQdhXMA02HHKmDP3Ca12iRROAZo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RGaVv3lU0qyaPeuhbNiM0iA9e+XJzfjYE49HfYrPz2YBZw5jUw8Z1Ku8E6lnf5V4j G2mdhruVPw/UXa2hrQuzBjsfBQJ3R3WTIGiUog7alqxfaJ8q7zjb6oZ/OABvqE+bAl bm3muA39zI6X85xUBtYTloIV3rqCDaAv4K1VoMV0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout1.netcologne.de (cc-smtpout1.netcologne.de [89.1.8.211]) by sourceware.org (Postfix) with ESMTPS id 3C811385B835; Thu, 16 Apr 2020 11:53:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3C811385B835 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id E8A1413350; Thu, 16 Apr 2020 13:53:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id DB05011EF0; Thu, 16 Apr 2020 13:53:28 +0200 (CEST) Received: from [2001:4dd7:4da9:0:8f7e:7854:b0d:2bec] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.11.6) (envelope-from ) id 5e984738-3658-7f0000012729-7f0000019a64-1 for ; Thu, 16 Apr 2020 13:53:28 +0200 Received: from linux-p51k.fritz.box (2001-4dd7-4da9-0-8f7e-7854-b0d-2bec.ipv6dyn.netcologne.de [IPv6:2001:4dd7:4da9:0:8f7e:7854:b0d:2bec]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Thu, 16 Apr 2020 13:53:27 +0200 (CEST) To: gcc-patches , "fortran@gcc.gnu.org" Subject: [patch, fortran] Fix PR PR93500 Message-ID: <98db0650-04a5-e398-d6bd-60d3e78bce2e@netcologne.de> Date: Thu, 16 Apr 2020 13:53:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Language: de-DE X-Spam-Status: No, score=-19.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thomas Koenig via Gcc-patches From: Thomas Koenig Reply-To: Thomas Koenig Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello world, this patch fixes PR PR93500. One part of it is due to what Steve wrote in the patch (returning from resolutions when both operands are NULL), but that still left a nonsensical error. Returning &gfc_bad_expr when simplifying bounds resulted in the division by zero error actually reaching the user. As to why there is an extra error when this is done in the main program, as compared to a subroutine, I don't know, but I do not particularly care. What is important is that the first error message is clear and reaches the user. Regression-tested. OK for trunk? Regards Thomas 2020-04-16 Thomas Koenig PR fortran/93500 * resolve.c (resolve_operator): If both operands are NULL, return false. * simplify.c (simplify_bound): If a division by zero was seen during bound simplification, free the corresponcing expression and return &gfc_bad_expr. 2020-04-16 Thomas Koenig PR fortran/93500 * arith_divide_3.f90: New test. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 9b95200c241..650837e18c3 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -3986,6 +3986,9 @@ resolve_operator (gfc_expr *e) op1 = e->value.op.op1; op2 = e->value.op.op2; + if (op1 == NULL && op2 == NULL) + return false; + dual_locus_error = false; /* op1 and op2 cannot both be BOZ. */ diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 807565b4e80..fba7f7020be 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4251,7 +4251,13 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) for (j = 0; j < d; j++) gfc_free_expr (bounds[j]); - return bounds[d]; + if (gfc_seen_div0) + { + gfc_free_expr (bounds[d]); + return &gfc_bad_expr; + } + else + return bounds[d]; } } diff --git a/gcc/testsuite/gfortran.dg/arith_divide_3.f90 b/gcc/testsuite/gfortran.dg/arith_divide_3.f90 new file mode 100644 index 00000000000..d9eb4a0d590 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/arith_divide_3.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! PR 93500 - this used to cause an ICE + +program p + integer :: a(min(2,0)/0) ! { dg-error "Division by zero" } + integer :: b = lbound(a) ! { dg-error "must be an array" } +end + +subroutine s + integer :: a(min(2,0)/0) ! { dg-error "Division by zero" } + integer :: b = lbound(a) +end +