From patchwork Sun Mar 9 16:25:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 328365 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 A65752C00AB for ; Mon, 10 Mar 2014 03:25:58 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=qGAB2L4EHPzNDiSNGlVYIHQb3vqIk1axCWpBMBdqd5Fu0D wY+58fivotX+GBmZcC0b5Fg6vLCLQQGBzEhAwzdF5X+y0HKq6WIdKNljkQ9TFNt5 XCssa2z7+QdlA+IYCXcX/zLazfhDJqKX7XY7H1MkiaLVpnal7R1Nf1PsSQP4g= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=obn3yzc2iZIRjAuTu55V8cRqkAE=; b=aOq4LejJvridgamg+mRe Ia5819F6bc8/qeliwhYAa8Vj6wON6nY7XO7r4b/7IKYe3SOrVSJKhcrW0LOHwkX5 n/F5S40REVkAWLgQ6qw02Vr74iJF+h77X4uapQYbDXrJvJMlYbSwAx7sjqxE5JXc fvmQPI1B3l0rFUrDPDLXfsk= Received: (qmail 11567 invoked by alias); 9 Mar 2014 16:25:51 -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 11545 invoked by uid 89); 9 Mar 2014 16:25:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: smtp21.services.sfr.fr Received: from smtp21.services.sfr.fr (HELO smtp21.services.sfr.fr) (93.17.128.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Mar 2014 16:25:49 +0000 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2103.sfr.fr (SMTP Server) with ESMTP id 21C147000063; Sun, 9 Mar 2014 17:25:47 +0100 (CET) Received: from [192.168.0.16] (did75-4-82-66-46-21.fbx.proxad.net [82.66.46.21]) by msfrf2103.sfr.fr (SMTP Server) with ESMTP id EC9A870000AD; Sun, 9 Mar 2014 17:25:46 +0100 (CET) X-SFR-UUID: 20140309162546969.EC9A870000AD@msfrf2103.sfr.fr Message-ID: <531C95FB.2020003@sfr.fr> Date: Sun, 09 Mar 2014 17:25:31 +0100 From: Mikael Morin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: gcc-patches , gfortran Subject: [Patch, fortran] PR 60392 wrong descriptor when passing a transposed array to a contiguous assumed shape dummy. X-IsSubscribed: yes Hello, here is a fix for a wrong code issue, where we pass a descriptor with broken bounds when the actual argument is a transposed array and the dummy an assumed shape dummy. The bug comes from the interaction of the transpose optimization, which creates a descriptor with transposed bounds without copying the data, and the contiguous optimization, which reuses the descriptor for passing as argument after the call to internal_pack. The attached patch makes a copy of the descriptor with the correct bounds when a transposed scalarization is detected. Regression-tested on x86_64-unknown-linux-gnu. This is not a regression as far as I know, but quite a severe wrong-code, albeit limited to the corner case of transpose and assumed shape and contiguous. OK for trunk/4.8/4.7 anyway ? Mikael PS: To not reproduce the same mistake as in the PR regarding the memory representation of matrices, I have filled the matrices one element at a time in the testcase. 2014-03-09 Mikael Morin PR fortran/60392 * trans-array.c (gfc_conv_array_parameter): Don't reuse the descriptor if it has transposed dimensions. 2014-03-09 Mikael Morin PR fortran/60392 * gfortran.dg/transpose_4.f90: New test. Index: trans-array.c =================================================================== --- trans-array.c (révision 208442) +++ trans-array.c (copie de travail) @@ -7227,7 +7227,50 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * else { tmp = build_fold_indirect_ref_loc (input_location, desc); - gfc_conv_descriptor_data_set (&se->pre, tmp, ptr); + + gfc_ss * ss = gfc_walk_expr (expr); + if (!transposed_dims (ss)) + gfc_conv_descriptor_data_set (&se->pre, tmp, ptr); + else + { + tree old_field, new_field; + + /* The original descriptor has transposed dims so we can't reuse + it directly; we have to create a new one. */ + tree old_desc = tmp; + tree new_desc = gfc_create_var (TREE_TYPE (old_desc), "arg_desc"); + + old_field = gfc_conv_descriptor_dtype (old_desc); + new_field = gfc_conv_descriptor_dtype (new_desc); + gfc_add_modify (&se->pre, new_field, old_field); + + old_field = gfc_conv_descriptor_offset (old_desc); + new_field = gfc_conv_descriptor_offset (new_desc); + gfc_add_modify (&se->pre, new_field, old_field); + + for (int i = 0; i < expr->rank; i++) + { + old_field = gfc_conv_descriptor_dimension (old_desc, + gfc_rank_cst[get_array_ref_dim_for_loop_dim (ss, i)]); + new_field = gfc_conv_descriptor_dimension (new_desc, + gfc_rank_cst[i]); + gfc_add_modify (&se->pre, new_field, old_field); + } + + if (gfc_option.coarray == GFC_FCOARRAY_LIB + && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (old_desc)) + && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (old_desc)) + == GFC_ARRAY_ALLOCATABLE) + { + old_field = gfc_conv_descriptor_token (old_desc); + new_field = gfc_conv_descriptor_token (new_desc); + gfc_add_modify (&se->pre, new_field, old_field); + } + + gfc_conv_descriptor_data_set (&se->pre, new_desc, ptr); + se->expr = gfc_build_addr_expr (NULL_TREE, new_desc); + } + gfc_free_ss (ss); } if (gfc_option.rtcheck & GFC_RTCHECK_ARRAY_TEMPS)