From patchwork Tue Dec 14 09:50:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 75480 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]) by ozlabs.org (Postfix) with SMTP id 9C6DBB6EE9 for ; Tue, 14 Dec 2010 20:50:31 +1100 (EST) Received: (qmail 14696 invoked by alias); 14 Dec 2010 09:50:29 -0000 Received: (qmail 14687 invoked by uid 22791); 14 Dec 2010 09:50:27 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Dec 2010 09:50:23 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBE9oLn8005838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 14 Dec 2010 04:50:21 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBE9oKfX032479 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 14 Dec 2010 04:50:21 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oBE9oKpE017664 for ; Tue, 14 Dec 2010 10:50:20 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oBE9oKxK017663 for gcc-patches@gcc.gnu.org; Tue, 14 Dec 2010 10:50:20 +0100 Date: Tue, 14 Dec 2010 10:50:20 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix handling of allocatable dummy vars in reduction (PR fortran/46874) Message-ID: <20101214095020.GG27214@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! gfc_trans_omp_array_reduction wasn't expecting that allocatable dummy vars are REFERENCEs to the actual desriptor. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, will commit soon. 2010-12-14 Jakub Jelinek PR fortran/46874 * trans-openmp.c (gfc_trans_omp_array_reduction): Handle allocatable dummy variables. * libgomp.fortran/allocatable6.f90: New test. Jakub --- gcc/fortran/trans-openmp.c.jj 2010-12-06 08:08:48.000000000 +0100 +++ gcc/fortran/trans-openmp.c 2010-12-13 22:18:37.000000000 +0100 @@ -482,13 +482,23 @@ gfc_trans_omp_array_reduction (tree c, g gfc_symbol init_val_sym, outer_sym, intrinsic_sym; gfc_expr *e1, *e2, *e3, *e4; gfc_ref *ref; - tree decl, backend_decl, stmt; + tree decl, backend_decl, stmt, type, outer_decl; locus old_loc = gfc_current_locus; const char *iname; gfc_try t; decl = OMP_CLAUSE_DECL (c); gfc_current_locus = where; + type = TREE_TYPE (decl); + outer_decl = create_tmp_var_raw (type, NULL); + if (TREE_CODE (decl) == PARM_DECL + && TREE_CODE (type) == REFERENCE_TYPE + && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type)) + && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (type)) == GFC_ARRAY_ALLOCATABLE) + { + decl = build_fold_indirect_ref (decl); + type = TREE_TYPE (type); + } /* Create a fake symbol for init value. */ memset (&init_val_sym, 0, sizeof (init_val_sym)); @@ -507,7 +517,9 @@ gfc_trans_omp_array_reduction (tree c, g outer_sym.attr.dummy = 0; outer_sym.attr.result = 0; outer_sym.attr.flavor = FL_VARIABLE; - outer_sym.backend_decl = create_tmp_var_raw (TREE_TYPE (decl), NULL); + outer_sym.backend_decl = outer_decl; + if (decl != OMP_CLAUSE_DECL (c)) + outer_sym.backend_decl = build_fold_indirect_ref (outer_decl); /* Create fake symtrees for it. */ symtree1 = gfc_new_symtree (&root1, sym->name); @@ -624,12 +636,12 @@ gfc_trans_omp_array_reduction (tree c, g /* Create the init statement list. */ pushlevel (0); - if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)) - && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_ALLOCATABLE) + if (GFC_DESCRIPTOR_TYPE_P (type) + && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE) { /* If decl is an allocatable array, it needs to be allocated with the same bounds as the outer var. */ - tree type = TREE_TYPE (decl), rank, size, esize, ptr; + tree rank, size, esize, ptr; stmtblock_t block; gfc_start_block (&block); @@ -669,8 +681,8 @@ gfc_trans_omp_array_reduction (tree c, g /* Create the merge statement list. */ pushlevel (0); - if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)) - && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_ALLOCATABLE) + if (GFC_DESCRIPTOR_TYPE_P (type) + && GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE) { /* If decl is an allocatable array, it needs to be deallocated afterwards. */ @@ -691,7 +703,7 @@ gfc_trans_omp_array_reduction (tree c, g OMP_CLAUSE_REDUCTION_MERGE (c) = stmt; /* And stick the placeholder VAR_DECL into the clause as well. */ - OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = outer_sym.backend_decl; + OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = outer_decl; gfc_current_locus = old_loc; --- libgomp/testsuite/libgomp.fortran/allocatable6.f90.jj 2010-12-13 22:40:27.000000000 +0100 +++ libgomp/testsuite/libgomp.fortran/allocatable6.f90 2010-12-13 22:38:56.000000000 +0100 @@ -0,0 +1,45 @@ +! PR fortran/46874 +! { dg-do run } + + interface + subroutine sub (a, b, c, d, n) + integer :: n + integer, allocatable :: a(:), b(:), c(:), d(:) + end subroutine + end interface + + integer, allocatable :: a(:), b(:), c(:), d(:) + integer :: i, j + allocate (a(50), b(50), c(50), d(50)) + do i = 1, 50 + a(i) = 2 + modulo (i, 7) + b(i) = 179 - modulo (i, 11) + end do + c = 0 + d = 2147483647 + call sub (a, b, c, d, 50) + do i = 1, 50 + j = 0 + if (i .eq. 3) then + j = 8 + else if (i .gt. 1 .and. i .lt. 9) then + j = 7 + end if + if (c(i) .ne. j) call abort + j = 179 - modulo (i, 11) + if (i .gt. 1 .and. i .lt. 9) j = i + if (d(i) .ne. j) call abort + end do + deallocate (a, b, c, d) +end + +subroutine sub (a, b, c, d, n) + integer :: n + integer, allocatable :: a(:), b(:), c(:), d(:) +!$omp parallel do shared(a, b) reduction(+:c) reduction(min:d) + do i = 1, n + c(a(i)) = c(a(i)) + 1 + d(i) = min(d(i), b(i)) + d(a(i)) = min(d(a(i)), a(i)) + end do +end