From patchwork Tue Jan 3 05:29:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 710377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3tt2cD6SdVz9svs for ; Tue, 3 Jan 2017 16:31:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="q9PLtGmu"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=omN2auEXZsZI/9olpnMAQG/GLmRbRSPQD021xDhSilfOikQaszJlc lqkWBHTgEouRTlREaY+Xcgu72SSQ8InQDFHLVSyXSWDeGrLMO97x3bFoXYLvZ9Rp T85+KkAVHHku9T3B6MvXgvHFARpkwl6QKltT5/evIS8qQOKggFnnn4= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=tUaeAdC6HXMivd+kAYX96bIZ1bs=; b=q9PLtGmuv8FswEf1guth LcvOblsMHT8j387WDK/+egiAi8ArF2xzES/G0uwRl7VlbuQjVJsaa6c7TCuDRXUG zeZf5Ps26Ap5Yyc2cLAp5ZWyrj7VN7BgrcBVp33QQ8LVz9ORsgx4TmQcmu3G6HhP 4mhLbiKbnV18mY2baxABNko= Received: (qmail 16612 invoked by alias); 3 Jan 2017 05:29:35 -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 16531 invoked by uid 89); 3 Jan 2017 05:29:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=simplify.c, UD:simplify.c, simplifyc, gfc_expr X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jan 2017 05:29:24 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E0AB4E4C4 for ; Tue, 3 Jan 2017 05:29:24 +0000 (UTC) Received: from freie.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v035TMOa008096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 3 Jan 2017 00:29:23 -0500 Received: from livre (livre.home [172.31.160.2]) by freie.home (8.15.2/8.15.2) with ESMTP id v035T5Yd011533; Tue, 3 Jan 2017 03:29:05 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [bootstrap-O3, fortran] silence warning in simplify_transformation_to_array Date: Tue, 03 Jan 2017 03:29:05 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 simplify_transformation_to_array had the nested loop unrolled 7 times, which is reasonable given that it iterates over arrays of size GFC_MAX_DIMENSIONS == 7. The problem is that the last iteration increments the index, tests that it's less than result->rank, and then accesses the arrays with the incremented index. We did not optimize out that part in the 7th iteration, so VRP flagged the unreachable code as accessing arrays past the end. It couldn't possibly know that we'd never reach that part, since the test was on result->rank, and it's not obvious (for the compiler) that result->rank <= GFC_MAX_DIMENSIONS. Even an assert to that effect before the enclosing loop didn't avoid the warning turned to error, though; I suppose there might be some aliasing at play, because moving the assert into the loop does, but then, it's not as efficient as testing the index itself against the limit. Regstrapped on x86_64-linux-gnu and i686-linux-gnu. OK to install? for gcc/fortran/ChangeLog * simplify.c (simplify_transformation_to_array): Assert the array access is in range. Fix whitespace. --- gcc/fortran/simplify.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index a46fbc5..1036681 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -610,7 +610,8 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d n++; if (n < result->rank) { - count [n]++; + gcc_checking_assert (n < GFC_MAX_DIMENSIONS); + count[n]++; base += sstride[n]; dest += dstride[n]; }