From patchwork Mon Sep 20 04:02:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 45169 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C593385803D for ; Mon, 20 Sep 2021 04:02:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id B1C2C3858427; Mon, 20 Sep 2021 04:02:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B1C2C3858427 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: XIdyL9fI/dDKHfIGOfp8/e5cWcmx4S0PxXu4FwCgMjKSp5iPa7EnRXFkbCxWooNVeZl/DN8UMd A1VG26OgyCGfYLzffGXMVv6C5lXrEe1o4VkkuveNLXHD3wCNora/XbwhE/irLQ75cW69juJaP/ q349t02+HDarMVOqI1RhdQUWlcBF0QtGDr6dZwx3OU6N5vEw/rz9UAoxia4wrvFCBL7Rwcu4BR g9hCx/HpbPEFu9CgCQtI9ycxKSa1yk9qqWtIi7HXYPyhZQKnW8seDEH7Fq8vuodopvQ73e5aIF ppA= X-IronPort-AV: E=Sophos;i="5.85,307,1624348800"; d="scan'208";a="66042131" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Sep 2021 20:02:22 -0800 IronPort-SDR: SuCCPBzFsiiom2JTW5T0FwKcqDpaWC4muL5slBf7X6QaLJX4NNB1uspYoLZOWmq8/VV2DtiiiN jJDMDRCYlOpUX+44dDU0iACAAZITxxyOuBsnuOwIVwbjBS1axrr3lLmAl2eCldUKEK5/MTMVi9 6FfGVhCzbKQ+u0A/H0o+gfIdc1FbXaCPYej9IQxfP3JjItlvpr3gqacnG+/drEoTf4Au/+psbX sclHxB0fMCnU4fZwoVUoJXCjGpoVQZp6cQjdRNCqXnTeljSEmvDIiWt5pM8ZJ9p3/slxBS82bC bVI= To: "gcc-patches@gcc.gnu.org" , "fortran@gcc.gnu.org" From: Sandra Loosemore Subject: [PATCH, Fortran] Fix testcases that violate C838, + revealed ICE Message-ID: <1fabbb25-f811-8a27-d082-a4f820304ba9@codesourcery.com> Date: Sun, 19 Sep 2021 22:02:18 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Language: en-US X-ClientProxiedBy: SVR-ORW-MBX-05.mgc.mentorg.com (147.34.90.205) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch fixes 3 testcases that violate F2018 C838 by passing an assumed-rank argument to a procedure via an assumed-sized dummy, by wrapping the call in a SELECT RANK construct. But wait, there's more! This triggered an ICE due to a null pointer dereference in the code that handles the associated variable in the SELECT RANK. I fixed that by copying the idiom used in other places for GFC_DECL_SAVED_DESCRIPTOR, so now all the tests pass again. Is this OK to commit? I confess I'm not certain whether adding the SELECT RANK causes the testcases now to do something different from what they were originally trying to test, but they never should have worked as originally written anyway. We were just not previously diagnosing the C838 violations without the other patch I just posted to do that. -Sandra commit dd48922d40542eb1b9d17a78fcb3a7cfb857d555 Author: Sandra Loosemore Date: Sun Sep 19 17:23:58 2021 -0700 Fortran: Fix testcases that violate C838, + revealed ICE The three test cases fixed in this patch violated F2018 C838, which only allows passing an assumed-rank argument to an assumed-rank dummy. Wrapping the call in "select rank" revealed a null pointer dereference which is fixed by guarding the use of the result of GFC_DECL_SAVED_DESCRIPTOR similar to what is already done elsewhere. 2021-09-19 Sandra Loosemore gcc/fortran/ * trans-stmt.c (trans_associate_var): Check that result of GFC_DECL_SAVED_DESCRIPTOR is not null before using it. gcc/testsuite/ * gfortran.dg/assumed_rank_18.f90 (g): Wrap call to h in select rank. * gfortran.dg/assumed_type_10.f90 (test_array): Likewise for call to test_lib. * gfortran.dg/assumed_type_11.f90 (test_array): Likewise. diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 11df186..a8ff473 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -1788,9 +1788,10 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block) /* Go straight to the class data. */ if (sym2->attr.dummy && !sym2->attr.optional) { - class_decl = DECL_LANG_SPECIFIC (sym2->backend_decl) ? - GFC_DECL_SAVED_DESCRIPTOR (sym2->backend_decl) : - sym2->backend_decl; + class_decl = sym2->backend_decl; + if (DECL_LANG_SPECIFIC (class_decl) + && GFC_DECL_SAVED_DESCRIPTOR (class_decl)) + class_decl = GFC_DECL_SAVED_DESCRIPTOR (class_decl); if (POINTER_TYPE_P (TREE_TYPE (class_decl))) class_decl = build_fold_indirect_ref_loc (input_location, class_decl); diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_18.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_18.f90 index a8fa3ff..0bc419a 100644 --- a/gcc/testsuite/gfortran.dg/assumed_rank_18.f90 +++ b/gcc/testsuite/gfortran.dg/assumed_rank_18.f90 @@ -7,7 +7,10 @@ program p contains subroutine g(x) real :: x(..) - call h(x) + select rank (x) + rank (1) + call h(x) + end select end subroutine h(x) real :: x(*) diff --git a/gcc/testsuite/gfortran.dg/assumed_type_10.f90 b/gcc/testsuite/gfortran.dg/assumed_type_10.f90 index bf0c873..a8bbf2d 100644 --- a/gcc/testsuite/gfortran.dg/assumed_type_10.f90 +++ b/gcc/testsuite/gfortran.dg/assumed_type_10.f90 @@ -31,7 +31,10 @@ contains subroutine test_array (a) use iso_c_binding, only: c_size_t class(*), dimension(..), target :: a - call test_lib (a, int (sizeof (a), kind=c_size_t)) + select rank (a) + rank (1) + call test_lib (a, int (sizeof (a), kind=c_size_t)) + end select end subroutine end module diff --git a/gcc/testsuite/gfortran.dg/assumed_type_11.f90 b/gcc/testsuite/gfortran.dg/assumed_type_11.f90 index df6572d..391fa0d 100644 --- a/gcc/testsuite/gfortran.dg/assumed_type_11.f90 +++ b/gcc/testsuite/gfortran.dg/assumed_type_11.f90 @@ -31,7 +31,10 @@ contains subroutine test_array (a) use iso_c_binding, only: c_size_t class(*), dimension(..), target :: a - call test_lib (a, int (sizeof (a), kind=c_size_t)) + select rank (a) + rank (1) + call test_lib (a, int (sizeof (a), kind=c_size_t)) + end select end subroutine end module