From patchwork Fri Jun 8 19:06:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 926987 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-479372-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none 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="JghKYrzo"; 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 412X356ZsYz9rxs for ; Sat, 9 Jun 2018 05:07:12 +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=fzxhsGDVkf6wJpG3yY0IdrEJp90dvRYTBhyUvQo0Y4y4nSnt7v 1xnmH1TQmrBQn8oJrBh84bzV9eXD27J5AHooZvWfN5ox/WednK2D8sIoL5+uxNC8 6y8nsYV2Lu34F6dARtb7gtlpP59dIB2DE2p0cgYzb0ToyEZDXI+79LtNo= 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=6PqsXVv4ulCBa0eK3Qob9Z4RGUQ=; b=JghKYrzolyYhon0OiYd5 ihFPlvW+TvCaJmBHHvxn4sEw9V0HRrZTonUl5Z1aPkAEALsjzYd91YoWfi/cx3NA OyjiKG3s5FVl3WfiEzQS3mBRoic+BfU8vyi9grw2OSQFmyd5NACEuwfB7JMrNrEB yHDZaSe7LDR13ABX2FN2OHs= Received: (qmail 36594 invoked by alias); 8 Jun 2018 19:07:04 -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 36202 invoked by uid 89); 8 Jun 2018 19:07:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=U*tkoenig, tkoenig@gcc.gnu.org, tkoeniggccgnuorg, sk:tkoenig X-Spam-User: qpsmtpd, 2 recipients 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; Fri, 08 Jun 2018 19:06:59 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id A34A912D2E; Fri, 8 Jun 2018 21:06:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 95EE211DDD; Fri, 8 Jun 2018 21:06:56 +0200 (CEST) Received: from [78.35.152.204] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 5b1ad3d0-02b8-7f0000012729-7f0000018ad2-1 for ; Fri, 08 Jun 2018 21:06:56 +0200 Received: from [192.168.178.68] (xdsl-78-35-152-204.netcologne.de [78.35.152.204]) (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; Fri, 8 Jun 2018 21:06:55 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Fix PR 85631, wrong size checking with allocatable arrays Message-ID: <7a7a342c-c824-0acc-0966-63a82ec9de8a@netcologne.de> Date: Fri, 8 Jun 2018 21:06:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 Hello world, the attached patch fixes a bug which was uncovered by the PR in a matmul regression. The problem is that bounds checking on the LHS with reallocation on assignment makes no sense, and the original flag was not set for the case in question. I added both the original test and the reduced test to the single test case. OK for trunk? Regards Thomas 2018-06-08 Thomas Koenig PR fortran/85631 * trans.h (gfc_ss): Add field no_bounds_check. * trans-array.c (gfc_conv_ss_startstride): If flag_realloc_lhs and ss->no_bounds_check is set, do not use runtime checks. * trans-expr.c (gfc_trans_assignment_1): Set lss->no_bounds_check for reallocatable lhs. 2018-06-08 Thomas Koenig PR fortran/85631 * gfortran.dg/bounds_check_20.f90: New test. Index: trans-array.c =================================================================== --- trans-array.c (Revision 261245) +++ trans-array.c (Arbeitskopie) @@ -4304,7 +4304,7 @@ done: } } - /* The rest is just runtime bound checking. */ + /* The rest is just runtime bounds checking. */ if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS) { stmtblock_t block; @@ -4334,7 +4334,7 @@ done: continue; /* Catch allocatable lhs in f2003. */ - if (flag_realloc_lhs && ss->is_alloc_lhs) + if (flag_realloc_lhs && ss->no_bounds_check) continue; expr = ss_info->expr; Index: trans-expr.c =================================================================== --- trans-expr.c (Revision 261245) +++ trans-expr.c (Arbeitskopie) @@ -9982,12 +9982,15 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr /* Walk the lhs. */ lss = gfc_walk_expr (expr1); - if (gfc_is_reallocatable_lhs (expr1) - && !(expr2->expr_type == EXPR_FUNCTION - && expr2->value.function.isym != NULL - && !(expr2->value.function.isym->elemental - || expr2->value.function.isym->conversion))) - lss->is_alloc_lhs = 1; + if (gfc_is_reallocatable_lhs (expr1)) + { + lss->no_bounds_check = 1; + if (!(expr2->expr_type == EXPR_FUNCTION + && expr2->value.function.isym != NULL + && !(expr2->value.function.isym->elemental + || expr2->value.function.isym->conversion))) + lss->is_alloc_lhs = 1; + } rss = NULL; Index: trans.h =================================================================== --- trans.h (Revision 261245) +++ trans.h (Arbeitskopie) @@ -330,6 +330,7 @@ typedef struct gfc_ss struct gfc_loopinfo *loop; unsigned is_alloc_lhs:1; + unsigned no_bounds_check:1; } gfc_ss; #define gfc_get_ss() XCNEW (gfc_ss)