From patchwork Wed Oct 30 15:40:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1186831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512078-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TAuYlvII"; 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 473CN36KZkz9sP4 for ; Thu, 31 Oct 2019 02:40:49 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=MBcWbMHtX0g4bjZUi/OQR1y3jokX2Ve9olcBdUNqxSHC4IRbIR eiCJIp8NojsFUMWGfHLYgfqBpn7uHaoa4bJdnK/C3OJ6VMb5YCr65Ns8qS9UgxZT ESyG4VkDRYpnU3TtdvCsEyw0EdvoMQqznuvPuuatNj1Bp+xhJI/2mlD24= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=3auXDEICqAy0tuZLPHBw/9m5uPg=; b=TAuYlvIIKPNEyS31XTeF T7YCRenw5mpVTISIUnzzTQkVlu1I8B8Gr2yRSUaKYJIsN+MIaH7D4vCqDC7Ph0W7 sa7e/mo6/NB6WbF+oB+ur0lXIkCDY3OUtDlVo/vY/ghPfivyUN1kQNxukdPV27DQ p9MA5e4H2tdXNcmvZSa79Wo= Received: (qmail 110646 invoked by alias); 30 Oct 2019 15:40:42 -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 110630 invoked by uid 89); 30 Oct 2019 15:40:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=act X-HELO: esa1.mentor.iphmx.com Received: from esa1.mentor.iphmx.com (HELO esa1.mentor.iphmx.com) (68.232.129.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Oct 2019 15:40:40 +0000 IronPort-SDR: TaL79Ac7T29LI/iIU/EJkX3lei7AUZnwQlh2VppZhZU8m1vh1PJNcweYCqzh4mKr38X2vwWF69 iKrfL+FRiAm5JZcCT0rR9aUl+ImL+9WjjWCZT/sO44c+BMz1Sp5K2uY2qKUxDMv3rXmeYbDh8q 6YUH5W5GNE6Lp64AR4eXK9Z5AdVdSYRwfiZHHln/YSeUNdRAqd/6J46ukuFY1bgwgyZmXtVEzO 9fV+DFFOd8TylmaCPvaSYXnsPPJqGdJeNshQ8iX8Us2EzHQmPFlxviUriyyptsLpU6lL+6vo5b 4H4= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 30 Oct 2019 07:40:38 -0800 IronPort-SDR: WdP95MSn2z7db4ocjpkO4DPHi2moPgvV7f6KZoG3Y415hc8KkJ0eoK4y02yw/sYpt1PTxQlIgh gQD9SEsS4tD/Am5HAW/T6uZjul/DHa0E0DgXdB+vmUOyCp9e4ciT3QQ3pQgYOnHyQ3jCeBV/RC vIcmBp6in4gO77zsW0TrueA0X4Glxc5UYrzDgnB3Pe2CQCCOwkGpAwkXReYXASmMuiRs5PVtYb 4FdXR5F8IktgEyaaunKUBgxf9K8rUSGdv+wWlOdz40l59eymNORxOS9e54sx6cUPSSK66fKsyT Z9U= To: gcc-patches , fortran From: Tobias Burnus Subject: [Patch, Fortran] PR92277 - Fix assumed-rank array with bind(C) Message-ID: Date: Wed, 30 Oct 2019 16:40:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 X-IsSubscribed: yes The attached test case (w/o optional and with "this") gave an ICE as "*this" was passed to DECL_ARTIFICIAL and only "this" but not the INDIRECT_REF is a declaration. [I added optional as those often act slightly different, but it doesn't seem to make a difference here.] Solution: If it is an INDIRECT_REF, check the the arg0 of it. Note: The INDIRECT_REF not only comes about via the build_fold_indirect_ref_loc call in the line above "is_artificial" but can be produced earlier. An example is this test case. (This is GCC 10 regression, only.) OK for the trunk? Tobias PS: Review is also still pending for https://gcc.gnu.org/ml/fortran/2019-10/msg00237.html gcc/fortran/ * trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): Fix DECL_ARTIFICIAL checking. gcc/testsuite/ * fortran.dg/pr92277.f90: New. diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 7eba1bbd082..381e314a9b5 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -5239,6 +5239,9 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym) if (POINTER_TYPE_P (TREE_TYPE (parmse->expr))) parmse->expr = build_fold_indirect_ref_loc (input_location, parmse->expr); + bool is_artificial = (INDIRECT_REF_P (parmse->expr) + ? DECL_ARTIFICIAL (TREE_OPERAND (parmse->expr, 0)) + : DECL_ARTIFICIAL (parmse->expr)); /* Unallocated allocatable arrays and unassociated pointer arrays need their dtype setting if they are argument associated with @@ -5258,7 +5261,7 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym) type = e->ts.type != BT_ASSUMED ? gfc_typenode_for_spec (&e->ts) : NULL_TREE; - if (type && DECL_ARTIFICIAL (parmse->expr) + if (type && is_artificial && type != gfc_get_element_type (TREE_TYPE (parmse->expr))) { /* Obtain the offset to the data. */ @@ -5271,7 +5274,7 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym) gfc_get_dtype_rank_type (e->rank, type)); } else if (type == NULL_TREE - || (!is_subref_array (e) && !DECL_ARTIFICIAL (parmse->expr))) + || (!is_subref_array (e) && !is_artificial)) { /* Make sure that the span is set for expressions where it might not have been done already. */ diff --git a/gcc/testsuite/gfortran.dg/pr92277.f90 b/gcc/testsuite/gfortran.dg/pr92277.f90 new file mode 100644 index 00000000000..5121063f5f3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr92277.f90 @@ -0,0 +1,32 @@ +! { dg-do compile } +! +! PR fortran/92277 +! +! Contributed by José Rui Faustino de Sousa +! +module arr_m + implicit none +contains + subroutine arr_set(this, that) + integer, intent(out) :: this(..) + integer, optional, intent(out) :: that(..) + + interface + subroutine arr_set_c(this) bind(c) + use, intrinsic :: iso_c_binding, only: c_int + implicit none + integer(kind=c_int), intent(out) :: this(..) + end subroutine arr_set_c + subroutine arr_set_c_opt(this) bind(c) + use, intrinsic :: iso_c_binding, only: c_int + implicit none + integer(kind=c_int), optional, intent(out) :: this(..) + end subroutine arr_set_c_opt + end interface + + call arr_set_c(this) + call arr_set_c(that) + call arr_set_c_opt(this) + call arr_set_c_opt(that) + end subroutine arr_set +end module arr_m