From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117929 invoked by alias); 19 Sep 2018 16:24:28 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 116949 invoked by uid 89); 19 Sep 2018 16:24:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=kwok, Kwok, fold_convert, sk:gfc_arr X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Sep 2018 16:24:03 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1g2fGh-0001OJ-OY from Andrew_Stubbs@mentor.com ; Wed, 19 Sep 2018 09:23:59 -0700 Received: from [172.30.90.223] (137.202.0.90) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 19 Sep 2018 17:23:54 +0100 Subject: Re: [PATCH 08/25] Fix co-array allocation To: Janne Blomqvist , Toon Moene , GCC Patches , Fortran List References: <024e798b9539b765a1259cfc9cb2f1dc480b24ca.1536144068.git.ams@codesourcery.com> <7f5064c3-afc6-b7b5-cade-f03af5b86331@moene.org> From: Andrew Stubbs Message-ID: <9290b55e-b12a-838a-5943-0c72d040dc3f@codesourcery.com> Date: Wed, 19 Sep 2018 16:24:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------CB6BC589001EFCB12A56C730" X-SW-Source: 2018-09/txt/msg00132.txt.bz2 --------------CB6BC589001EFCB12A56C730 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 789 On 05/09/18 19:07, Janne Blomqvist wrote: > The argument must be of type size_type_node, not sizetype. Please instead > use > > size = build_zero_cst (size_type_node); > > >> * trans-intrinsic.c (conv_intrinsic_event_query): Convert computed >> index to a size_t type. >> > > Using integer_type_node is wrong, but the correct type for calculating > array indices (lbound, ubound, etc.) is not size_type_node but rather > gfc_array_index_type (which in practice maps to ptrdiff_t). So please use > that, and then fold_convert index to size_type_node just before generating > the call to event_query. > > >> * trans-stmt.c (gfc_trans_event_post_wait): Likewise. >> > > Same here as above. How is the attached? I retested and found no regressions. Andrew --------------CB6BC589001EFCB12A56C730 Content-Type: text/x-patch; name="180919-fix-co-array-allocation.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="180919-fix-co-array-allocation.patch" Content-length: 3341 Fix co-array allocation The Fortran front-end has a bug in which it uses "int" values for "size_t" parameters. I don't know why this isn't problem for all 64-bit architectures, but GCN ends up with the data in the wrong argument register and/or stack slot, and bad things happen. This patch corrects the issue by setting the correct type. 2018-09-19 Andrew Stubbs Kwok Cheung Yeung gcc/fortran/ * trans-expr.c (gfc_trans_structure_assign): Ensure that the first argument of a call to _gfortran_caf_register is of size_type_node. * trans-intrinsic.c (conv_intrinsic_event_query): Convert computed index to a size_type_node type. * trans-stmt.c (gfc_trans_event_post_wait): Likewise. diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 56ce98c..28079ac 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -7729,7 +7729,7 @@ gfc_trans_structure_assign (tree dest, gfc_expr * expr, bool init, bool coarray) suffices to recognize the data as array. */ if (rank < 0) rank = 1; - size = integer_zero_node; + size = build_zero_cst (size_type_node); desc = field; gfc_add_modify (&block, gfc_conv_descriptor_rank (desc), build_int_cst (signed_char_type_node, rank)); diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index b2cea93..569435d 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -10732,7 +10732,9 @@ conv_intrinsic_event_query (gfc_code *code) tmp = fold_build2_loc (input_location, MULT_EXPR, integer_type_node, extent, tmp); index = fold_build2_loc (input_location, PLUS_EXPR, - integer_type_node, index, tmp); + gfc_array_index_type, index, + fold_convert (gfc_array_index_type, + tmp)); if (i < ar->dimen - 1) { ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]); @@ -10756,6 +10758,7 @@ conv_intrinsic_event_query (gfc_code *code) stat = gfc_create_var (integer_type_node, "stat"); } + index = fold_convert (size_type_node, index); tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_event_query, 5, token, index, image_index, count ? gfc_build_addr_expr (NULL, count) : count, diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 795d3cc..92d9c37 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -1096,7 +1096,8 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op) tmp = fold_build2_loc (input_location, MULT_EXPR, integer_type_node, extent, tmp); index = fold_build2_loc (input_location, PLUS_EXPR, - integer_type_node, index, tmp); + gfc_array_index_type, index, + fold_convert (gfc_array_index_type, tmp)); if (i < ar->dimen - 1) { ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]); @@ -1130,6 +1131,7 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op) stat = gfc_create_var (integer_type_node, "stat"); } + index = fold_convert (size_type_node, index); if (op == EXEC_EVENT_POST) tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_event_post, 6, token, index, image_index, --------------CB6BC589001EFCB12A56C730--