From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 4FC223858D20; Tue, 8 Mar 2022 23:28:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FC223858D20 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7551] Fortran: Fix gfc_conv_gfc_desc_to_cfi_desc with NULL [PR104126] X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/master X-Git-Oldrev: 3093f8a18e7a9c5a9bba976d58a2f91033e7f35a X-Git-Newrev: 48777d982add74cef14ec6704a622fce4d4a2609 Message-Id: <20220308232808.4FC223858D20@sourceware.org> Date: Tue, 8 Mar 2022 23:28:08 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Mar 2022 23:28:08 -0000 https://gcc.gnu.org/g:48777d982add74cef14ec6704a622fce4d4a2609 commit r12-7551-g48777d982add74cef14ec6704a622fce4d4a2609 Author: Tobias Burnus Date: Wed Mar 9 00:26:14 2022 +0100 Fortran: Fix gfc_conv_gfc_desc_to_cfi_desc with NULL [PR104126] PR fortran/104126 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_gfc_desc_to_cfi_desc): Handle NULL without MOLD. gcc/testsuite/ChangeLog: * gfortran.dg/null_actual_2.f90: New test. Diff: --- gcc/fortran/trans-expr.cc | 13 +++++++++---- gcc/testsuite/gfortran.dg/null_actual_2.f90 | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 71d037101d4..06713f24f95 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -5610,8 +5610,11 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym) itype = (e->ts.u.derived->intmod_sym_id == ISOCBINDING_FUNPTR ? CFI_type_cfunptr : CFI_type_cptr); else - switch (e->ts.type) - { + { + if (e->expr_type == EXPR_NULL && e->ts.type == BT_UNKNOWN) + e->ts = fsym->ts; + switch (e->ts.type) + { case BT_INTEGER: case BT_LOGICAL: case BT_REAL: @@ -5649,7 +5652,8 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym) case BT_UNKNOWN: // FIXME: Really unreachable? Or reachable for type(*) ? If so, CFI_type_other? gcc_unreachable (); - } + } + } tmp = gfc_get_cfi_desc_type (cfi); gfc_add_modify (&block, tmp, @@ -5702,7 +5706,8 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym) gfc_init_block (&block2); /* Set elem_len, which may be only known at run time. */ - if (e->ts.type == BT_CHARACTER) + if (e->ts.type == BT_CHARACTER + && (e->expr_type != EXPR_NULL || gfc_strlen != NULL_TREE)) { gcc_assert (gfc_strlen); tmp = gfc_strlen; diff --git a/gcc/testsuite/gfortran.dg/null_actual_2.f90 b/gcc/testsuite/gfortran.dg/null_actual_2.f90 new file mode 100644 index 00000000000..de481f01295 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/null_actual_2.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! +! PR fortran/104126 +! +! Contributed by G. Steinmetz +! +program p + use iso_c_binding, only: c_char + character(len=:,kind=c_char), pointer :: d + call s(null(d)) + call s(null()) +contains + subroutine s(x) bind(c) + character(len=:, kind=c_char), pointer, intent(in) :: x + end +end