From patchwork Mon Aug 12 15:18:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1145789 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-506706-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="HhriZxw7"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="XHUBozh4"; 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 466fcn4W55z9s7T for ; Tue, 13 Aug 2019 01:18:33 +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=l+KcLUwJIjNZjJBYelduA2G7AqwkZq2PVlKx27gQ+4gOhnPNeo aDwQkFGZWL1X9Ani654kU87HfktsOKls5NiVNN1IRaohBSHVcDrYqP8JPfXYz5lR Bvrc+3mO+0btTX7k1eDxGuqocjOzmhEVjppV9Sol4CNmITPDhu5lZbH38= 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=RENvVVIGBDp+gyYEltC5jLFFkUY=; b=HhriZxw7sTbHW0RLbDn0 dDqQgrhx80cQPHJOz0iQq2S3PGE49w6OpL5dO0VrzofQfQTFQ50ightvL+yIEZJX WKcjQBuRX5lnDZ1JT/y+PPX9e6yGwuJ4iB4BKajbZHMOMCnvSMscQjWB9FpbYUKk FlSztEe0LG+hlzmMw39u6y8= Received: (qmail 54561 invoked by alias); 12 Aug 2019 15:18:26 -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 54546 invoked by uid 89); 12 Aug 2019 15:18:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.8 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=1j, H*Ad:U*tkoenig, gang, trip X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Aug 2019 15:18:23 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 09072133EC; Mon, 12 Aug 2019 17:18:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1565623101; bh=r59gguGJ4w+r8KkkiVrmqhaGF0NloU8Zd535Vrd9Puc=; h=To:From:Subject:Message-ID:Date:From; b=XHUBozh48k3wbJbtdbrdMEAlMG8WjjTND8Kb/s61KqZ/4ofH47DvWLWcKcaCCMpkn Q4GgNaVOCUCIvWq+fuAVGIFTPulxhlame5UTskP4FOF3YiWpj/xZGN2wQLUkZI9Mw9 IoLitIWZX9JIgXLcOJ5IZ7Uog256GAx+oBnM7CwSZ+llAjQ/gEwwozCyergbh+94Ed fH03Uow7P7jEtx/c3CKJmy+sqZUWyC3esNcMp4wskGb8llOfNhA21KWPyH7AE4LPPh WlJ/p2wTK2fumDkkCGlMB45jatcXU57YEwG81KPK9LAgRmFvQceWHqGDsIDIAEn+dV kSERqVdFxsO9Q== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id EE20311EF5; Mon, 12 Aug 2019 17:18:20 +0200 (CEST) Received: from [2001:4dd6:e4c:0:7285:c2ff:fe6c:992d] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.6.0) (envelope-from ) id 5d51833c-669a-7f0000012729-7f000001b206-1 for ; Mon, 12 Aug 2019 17:18:20 +0200 Received: from [IPv6:2001:4dd6:e4c:0:7285:c2ff:fe6c:992d] (2001-4dd6-e4c-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd6:e4c:0:7285:c2ff:fe6c:992d]) (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; Mon, 12 Aug 2019 17:18:19 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Some corrections for DO loop index warnings Message-ID: <93ba61ec-0db4-1888-9a3f-856a4c59d9ba@netcologne.de> Date: Mon, 12 Aug 2019 17:18:18 +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 three problems with DO loop index warnings: - DO loops in contained procedures were not checked - Zero-trip loops gave a false positive - DO loops in blocks gave the same warning twice plus it fixes the resulting fallout from the test suite. Regression-tested. OK for trunk? I also think that this is something that could be safely backported to gcc-9. 2019-08-12 Thomas Koenig PR fortran/91424 * frontend-passes.c (do_subscript): Do not warn for an expression a second time. Do not warn about a zero-trip loop. (doloop_warn): Also look at contained namespaces. 2019-08-12 Thomas Koenig PR fortran/91424 * gfortran.dg/do_subscript_3.f90: New test. * gfortran.dg/do_subscript_4.f90: New test. * gfortran.dg/pr70754.f90: Use indices that to not overflow. 2019-08-12 Thomas Koenig PR fortran/91422 * testsuite/libgomp.oacc-fortran/routine-7.f90: Correct array dimension. Index: gcc/fortran/frontend-passes.c =================================================================== --- gcc/fortran/frontend-passes.c (revision 273855) +++ gcc/fortran/frontend-passes.c (working copy) @@ -2556,6 +2556,12 @@ do_subscript (gfc_expr **e) if (in_assoc_list) return 0; + /* We already warned about this. */ + if (v->do_not_warn) + return 0; + + v->do_not_warn = 1; + for (ref = v->ref; ref; ref = ref->next) { if (ref->type == REF_ARRAY && ref->u.ar.type == AR_ELEMENT) @@ -2608,7 +2614,6 @@ do_subscript (gfc_expr **e) else have_do_start = false; - if (dl->ext.iterator->end->expr_type == EXPR_CONSTANT) { have_do_end = true; @@ -2620,6 +2625,17 @@ do_subscript (gfc_expr **e) if (!have_do_start && !have_do_end) return 0; + /* No warning inside a zero-trip loop. */ + if (have_do_start && have_do_end) + { + int sgn, 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; + } + /* May have to correct the end value if the step does not equal one. */ if (have_do_start && have_do_end && mpz_cmp_ui (do_step, 1) != 0) @@ -2761,6 +2777,12 @@ static void doloop_warn (gfc_namespace *ns) { gfc_code_walker (&ns->code, doloop_code, do_function, NULL); + + for (ns = ns->contained; ns; ns = ns->sibling) + { + if (ns->code == NULL || ns->code->op != EXEC_BLOCK) + doloop_warn (ns); + } } /* This selction deals with inlining calls to MATMUL. */ Index: gcc/testsuite/gfortran.dg/pr70754.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr70754.f90 (revision 273855) +++ gcc/testsuite/gfortran.dg/pr70754.f90 (working copy) @@ -18,12 +18,13 @@ contains integer (ii4), dimension(40,40) :: c integer i, j - do i=1,20 - b(i,j) = 123 * a(i,j) + 34 * a(i,j+1) & - + 34 * a(i,j-1) + a(i+1,j+1) & - + a(i+1,j-1) + a(i-1,j+1) & - + a(i-1,j-1) - c(i,j) = 123 + j = 10 + do i=11,30 + b(i,j) = 123 * a(i,j) + 34 * a(i,j+1) & + + 34 * a(i,j-1) + a(i+1,j+1) & + + a(i+1,j-1) + a(i-1,j+1) & + + a(i-1,j-1) + c(i,j) = 123 end do where ((xyz(:,:,2) /= 0) .and. (c /= 0)) Index: libgomp/testsuite/libgomp.oacc-fortran/routine-7.f90 =================================================================== --- libgomp/testsuite/libgomp.oacc-fortran/routine-7.f90 (revision 273855) +++ libgomp/testsuite/libgomp.oacc-fortran/routine-7.f90 (working copy) @@ -109,7 +109,7 @@ end subroutine gang subroutine seq (a) !$acc routine seq - integer, intent (inout) :: a(M) + integer, intent (inout) :: a(N) integer :: i do i = 1, N