From patchwork Wed Mar 25 13:35:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 454396 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 344791400B7 for ; Thu, 26 Mar 2015 00:36:10 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=TEsP9Coh; dkim-adsp=none (unprotected policy); 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:date :from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=RSP3as/1nIHIG+MZ T6J/uiHCZphOO9VCg1+lMWDAmgTBgHgXqJqYziY9ALiguhcEHXjng+GoM5kSA9tz IM9tWTixsb0YBDnxlq6Zxmmje4kF7TFYcmZ/IMmF+8ppEIP0s2DyqGVIOJFmLdsr jwD+kgQOkyKkGGG1W9D+a9U6TQg= 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:date :from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type; s=default; bh=73/iPXZk8kmD3mORIpZLpX JFtpQ=; b=TEsP9CohMpE0cVWG95eVLy5GunlTzf5iIEKKMzyZRmF+5NRprLPAdv qSqdYFslFUYRcLunMvzchSrEKyKg7W4Xr84LgqQ9ak8wDO56ByY2wUMIiMIqz8Gr SVqXmYgXwECNtjemhIWWgaeLpOsJXbIhyeRHcQ1k0nGgaaz/qmVTM= Received: (qmail 36439 invoked by alias); 25 Mar 2015 13:36:02 -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 36414 invoked by uid 89); 25 Mar 2015 13:36:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 3 recipients X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 25 Mar 2015 13:36:00 +0000 Received: from vepi2 ([88.75.104.20]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0Mh6lB-1YoI0r30cr-00MNcV; Wed, 25 Mar 2015 14:35:56 +0100 Date: Wed, 25 Mar 2015 14:35:54 +0100 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML Cc: "dominiq at lps dot ens.fr" Subject: [Patch, fortran, pr65548, v1] [5 Regression] gfc_conv_procedure_call Message-ID: <20150325143554.0343a7a7@vepi2> In-Reply-To: References: MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; Hi all, please find attached a fix for the recently introduced regression when allocating arrays with an intrinsic function for source=. The patch addresses this issue by using gfc_conv_expr_descriptor () for intrinsic functions. Bootstraps and regtests ok on x86_64-linux-gnu/F20. Ok for trunk? Regards, Andre diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 6ffae6e79e..68b343b 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5075,12 +5075,17 @@ gfc_trans_allocate (gfc_code * code) /* In all other cases evaluate the expr3 and create a temporary. */ gfc_init_se (&se, NULL); - gfc_conv_expr_reference (&se, code->expr3); + if (code->expr3->rank != 0 + && code->expr3->expr_type == EXPR_FUNCTION + && code->expr3->value.function.isym) + gfc_conv_expr_descriptor (&se, code->expr3); + else + gfc_conv_expr_reference (&se, code->expr3); if (code->expr3->ts.type == BT_CLASS) gfc_conv_class_to_class (&se, code->expr3, code->expr3->ts, false, true, - false,false); + false, false); gfc_add_block_to_block (&block, &se.pre); gfc_add_block_to_block (&post, &se.post); /* Prevent aliasing, i.e., se.expr may be already a diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_5.f90 b/gcc/testsuite/gfortran.dg/allocate_with_source_5.f90 new file mode 100644 index 0000000..e934e08 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_source_5.f90 @@ -0,0 +1,52 @@ +! { dg-do run } +! +! Check that pr65548 is fixed. +! Contributed by Juergen Reuter + +module allocate_with_source_5_module + + type :: selector_t + integer, dimension(:), allocatable :: map + real, dimension(:), allocatable :: weight + contains + procedure :: init => selector_init + end type selector_t + +contains + + subroutine selector_init (selector, weight) + class(selector_t), intent(out) :: selector + real, dimension(:), intent(in) :: weight + real :: s + integer :: n, i + logical, dimension(:), allocatable :: mask + s = sum (weight) + allocate (mask (size (weight)), source = weight /= 0) + n = count (mask) + if (n > 0) then + allocate (selector%map (n), & + source = pack ([(i, i = 1, size (weight))], mask)) + allocate (selector%weight (n), & + source = pack (weight / s, mask)) + else + allocate (selector%map (1), source = 1) + allocate (selector%weight (1), source = 0.) + end if + end subroutine selector_init + +end module allocate_with_source_5_module + +program allocate_with_source_5 + use allocate_with_source_5_module + + class(selector_t), allocatable :: sel; + real, dimension(5) :: w = [ 1, 0, 2, 0, 3]; + + allocate (sel) + call sel%init(w) + + if (any(sel%map /= [ 1, 3, 5])) call abort() + if (any(abs(sel%weight - [1, 2, 3] / 6) < 1E-6)) call abort() +end program allocate_with_source_5 +! { dg-final { cleanup-modules "allocate_with_source_5_module" } } +