From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 99F9A3851AB4; Mon, 5 Sep 2022 19:25:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99F9A3851AB4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662405957; bh=ZeYVQGtonsTxEDibWBiP79Q6G2hRJaZUoZSJaMGEQcQ=; h=From:To:Subject:Date:From; b=I4FM29nS1ixE8f+NL4SlNUClyZh/NgnNVGWY3obe07n1mRGLRu2byBheCNAgVtUF4 I2nHg6PEs+k9M0CR91k6k1W5He15B0eIzEMsvPLGz5JM31XjjsrwqvZGyWaE/XHV3O HXfpDlpQT42+9KRsp6PnwhL4FB/Wgjh8oNmMGWes= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8743] Fortran: Fix ICE with -fcheck=pointer [PR100136] X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa?= X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: f4f72a25a9dfb5afbff8853bd51c1a891139dfd0 X-Git-Newrev: c1ba36ec779cccf6b54883d676d083df627f6d64 Message-Id: <20220905192557.99F9A3851AB4@sourceware.org> Date: Mon, 5 Sep 2022 19:25:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c1ba36ec779cccf6b54883d676d083df627f6d64 commit r12-8743-gc1ba36ec779cccf6b54883d676d083df627f6d64 Author: José Rui Faustino de Sousa Date: Sun Sep 4 21:53:09 2022 +0200 Fortran: Fix ICE with -fcheck=pointer [PR100136] gcc/fortran/ChangeLog: PR fortran/100136 * trans-expr.cc (gfc_conv_procedure_call): Add handling of pointer expressions. gcc/testsuite/ChangeLog: PR fortran/100136 * gfortran.dg/PR100136.f90: New test. (cherry picked from commit 20d30e737ad79dc36817e59f1676aa8bc0c6b325) Diff: --- gcc/fortran/trans-expr.cc | 7 +++--- gcc/testsuite/gfortran.dg/PR100136.f90 | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 850007fd2e1..e35ea2fc790 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -7220,16 +7220,15 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, else goto end_pointer_check; + tmp = parmse.expr; if (fsym && fsym->ts.type == BT_CLASS) { - tmp = build_fold_indirect_ref_loc (input_location, - parmse.expr); + if (POINTER_TYPE_P (TREE_TYPE (tmp))) + tmp = build_fold_indirect_ref_loc (input_location, tmp); tmp = gfc_class_data_get (tmp); if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp))) tmp = gfc_conv_descriptor_data_get (tmp); } - else - tmp = parmse.expr; /* If the argument is passed by value, we need to strip the INDIRECT_REF. */ diff --git a/gcc/testsuite/gfortran.dg/PR100136.f90 b/gcc/testsuite/gfortran.dg/PR100136.f90 new file mode 100644 index 00000000000..922af4aecc3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR100136.f90 @@ -0,0 +1,39 @@ +! { dg-do run } +! { dg-options "-fcheck=pointer" } +! { dg-shouldfail "Argument not allocated" } +! { dg-output "Fortran runtime error: Allocatable actual argument 'c_init2' is not allocated" } +! +! Tests fix for PR100136 +! +! Test cut down from PR58586 +! + +module test_pr58586_mod + implicit none + + type :: a + end type + + type :: c + type(a), allocatable :: a + end type + +contains + + subroutine add_class_c (d) + class(c), value :: d + end subroutine + + class(c) function c_init2() + allocatable :: c_init2 + end function + +end module test_pr58586_mod + +program test_pr58586 + use test_pr58586_mod + + ! This needs to execute, to see whether the segfault at runtime is resolved + call add_class_c(c_init2()) + +end program