From patchwork Sun May 13 13:08:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Richard Thomas X-Patchwork-Id: 912525 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-477611-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="pPnSVqIx"; 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 40kPKD4Rh4z9s2R for ; Sun, 13 May 2018 23:08:29 +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 :mime-version:from:date:message-id:subject:to:cc:content-type; q=dns; s=default; b=KEim0iqtXlG4VYhTmXQthDEC4UNjy8ZmMTW+MIPnO5v +DQTi1ZHyMU8Esko9a+dxmtRpssvlWMuVhVbHNdM/Vca60muUGZfnmYS2u7cUtmQ tYfqYJh8OOViZpsM2LEVseqv5CyfkAZHTRxBh2spvxCKfZrTuSoNVLs0PN2A8kds = 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 :mime-version:from:date:message-id:subject:to:cc:content-type; s=default; bh=Q0AQGN2IMV3rt8AGJHsw4wS/Fak=; b=pPnSVqIxOFt5pUENi bS0L89P4EUx05u79xyH9NF4xYxiEXvIjQtImtpyEkIMcjEfC68lcB73qi8EtulTd DuFzeLWBQmMm+S+z7BJUFjTW4AgDG+lOk3vpVvsxNrNYKDAZ2WUu2vkTfkk2X3XI /pY+oElE7teuGKfpeF0gMHd+7A= Received: (qmail 108009 invoked by alias); 13 May 2018 13:08:19 -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 107985 invoked by uid 89); 13 May 2018 13:08:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=rank, contributed, build_int_cst, contiguous X-Spam-User: qpsmtpd, 3 recipients X-HELO: mail-yw0-f169.google.com Received: from mail-yw0-f169.google.com (HELO mail-yw0-f169.google.com) (209.85.161.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 13 May 2018 13:08:16 +0000 Received: by mail-yw0-f169.google.com with SMTP id q7-v6so2859437ywd.9; Sun, 13 May 2018 06:08:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=Z2uBQUT0FlWWXD0x24jO7cSDBdIR0rDfmco9MoSZ1t0=; b=YehQQnMakqUn/vKXExjvowUA9TUfrMhGhNn9FzraunE5isN8ZnWB1rqXGR4m5CsfIH icIZe/qSmyuzLPK7eNC4BMbhFh3j/Bwinf5AxpanoUHgFkSiQ1l1W9r2UedOwLMJSr4I VDlZsS9g2T2/uti50tEYnHMh2yvLHh6xH2JnATLRPBrQf2Wwp6qnhlwKB8fyMUe1h5KQ ASDgWwpayJEjUBqbbYZFbQq9MhE0+0SbYbC0dE7FfEe76tnkl3FePO7uOYkdNqqBeMAA QVY1SJAjbBtbJQ7aYisRGQwamn83yTUtw8oWXmU9kT05bbNqnp5wM3+i4ZwV/75cEYwg UmyQ== X-Gm-Message-State: ALKqPwfwMqwUpDxg9B5krlSQ5viB4kcvXpjptmO3nBSQTMpm1X1lLk0e gGw7EJnC/wgSKKOGdkTmxfglNCOVUGGoq/g7kbM3+A== X-Google-Smtp-Source: AB8JxZqA2geko6caF43vXwTje3wIgniqbHs6vC3708oAXXU6ZoGXhyzZoLOy3pQ9kFVHUmuUjqLlBEUjVJTMEcy88qg= X-Received: by 2002:a81:5791:: with SMTP id l139-v6mr2894187ywb.114.1526216894810; Sun, 13 May 2018 06:08:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.13.215.196 with HTTP; Sun, 13 May 2018 06:08:14 -0700 (PDT) From: Paul Richard Thomas Date: Sun, 13 May 2018 14:08:14 +0100 Message-ID: Subject: [Patch, fortran] PR85742 sizeof allocatable arrays returning wrong value To: "fortran@gcc.gnu.org" , gcc-patches Cc: cesar@gcc.gnu.org I intend to apply this 'obvious' patch to trunk and 8-branch tonight, unless there are any objections. Bootstrapped and regetested on FC27/x86_64. Paul 2018-05-13 Paul Thomas PR fortran/85742 * trans-types.c (gfc_get_dtype_rank_type): Reorder evaluation of 'size'. If the element type is a pointer use the size of the TREE_TYPE of the type, unless it is VOID_TYPE. In this latter case, set the size to zero. 2018-05-13 Paul Thomas PR fortran/85742 * gfortran.dg/assumed_type_9.f90 : New test. Index: gcc/fortran/trans-types.c =================================================================== *** gcc/fortran/trans-types.c (revision 260208) --- gcc/fortran/trans-types.c (working copy) *************** gfc_get_dtype_rank_type (int rank, tree *** 1518,1523 **** --- 1518,1525 ---- tree field; vec *v = NULL; + size = TYPE_SIZE_UNIT (etype); + switch (TREE_CODE (etype)) { case INTEGER_TYPE: *************** gfc_get_dtype_rank_type (int rank, tree *** 1546,1567 **** /* We will never have arrays of arrays. */ case ARRAY_TYPE: n = BT_CHARACTER; break; case POINTER_TYPE: n = BT_ASSUMED; break; default: /* TODO: Don't do dtype for temporary descriptorless arrays. */ ! /* We can strange array types for temporary arrays. */ return gfc_index_zero_node; } - size = TYPE_SIZE_UNIT (etype); - if (n == BT_CHARACTER && size == NULL_TREE) - size = TYPE_SIZE_UNIT (TREE_TYPE (etype)); - tmp = get_dtype_type_node (); field = gfc_advance_chain (TYPE_FIELDS (tmp), GFC_DTYPE_ELEM_LEN); --- 1548,1571 ---- /* We will never have arrays of arrays. */ case ARRAY_TYPE: n = BT_CHARACTER; + if (size == NULL_TREE) + size = TYPE_SIZE_UNIT (TREE_TYPE (etype)); break; case POINTER_TYPE: n = BT_ASSUMED; + if (TREE_CODE (TREE_TYPE (etype)) != VOID_TYPE) + size = TYPE_SIZE_UNIT (TREE_TYPE (etype)); + else + size = build_int_cst (size_type_node, 0); break; default: /* TODO: Don't do dtype for temporary descriptorless arrays. */ ! /* We can encounter strange array types for temporary arrays. */ return gfc_index_zero_node; } tmp = get_dtype_type_node (); field = gfc_advance_chain (TYPE_FIELDS (tmp), GFC_DTYPE_ELEM_LEN); Index: gcc/testsuite/gfortran.dg/assumed_type_9.f90 =================================================================== *** gcc/testsuite/gfortran.dg/assumed_type_9.f90 (nonexistent) --- gcc/testsuite/gfortran.dg/assumed_type_9.f90 (working copy) *************** *** 0 **** --- 1,34 ---- + ! { dg-do run } + ! + ! Test the fix for PR85742 in which the descriptors, passed to alsize, + ! for 'a' and 'b' had the wrong element length. + ! + ! Contributed by Cesar Philippidis + ! + program main + implicit none + integer, allocatable :: a + real, pointer :: b + integer, allocatable :: am(:,:) + real, pointer :: bm(:,:) + + allocate (a) + allocate (b) + allocate (am(3,3)) + allocate (bm(4,4)) + + if (sizeof (a) /= alsize (a)) stop 1 + if (sizeof (b) /= alsize (b)) stop 2 + if (sizeof (am) /= alsize (am)) stop 3 + if (sizeof (bm) /= alsize (bm)) stop 4 + + deallocate (b) + deallocate (bm) + contains + function alsize (a) + integer alsize + type (*), dimension (..), contiguous :: a + alsize = sizeof(a) + end function + end program main +