[PATCH] fortran: Dereference descriptor pointer in IS_CONTIGUOUS code [PR126892]
Mikael Morin <[email protected]>
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
Hello, I'm going to push shortly the attached patch. Fortran-tested on aarch64-unknown-linux-gnu. Mikael
pr126892_v01-02.patch
(text/x-patch, 2.5 KB)
From a9146d715eba94033eb7ff15f1ad720fa2a5a8d8 Mon Sep 17 00:00:00 2001 From: Mikael Morin <[email protected]> Date: Sat, 15 Aug 2026 17:23:27 +0200 Subject: [PATCH] fortran: Dereference descriptor pointer in IS_CONTIGUOUS code [PR126892] In the IS_CONTIGUOUS implementation, add the missing dereference to really have a descriptor-typed expression, usable with the descriptor accessors. Without this change, the pointer resulting from the evaluation of the IS_CONTIGUOUS argument was stabilized to a variable and then directly used to access the descriptor fields. This was causing an internal compiler error because the descriptor accessors aren't prepared to receive a pointer. PR fortran/126892 gcc/fortran/ChangeLog: * trans-intrinsic.cc (gfc_conv_is_contiguous_expr): Dereference the pointer variable before using it as descriptor. gcc/testsuite/ChangeLog: * gfortran.dg/is_contiguous_6.f90: New test. --- gcc/fortran/trans-intrinsic.cc | 5 +++-- gcc/testsuite/gfortran.dg/is_contiguous_6.f90 | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/is_contiguous_6.f90 diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index 5e3681da467..69a6034b3d3 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -2348,9 +2348,10 @@ gfc_conv_is_contiguous_expr (gfc_se *se, gfc_expr *arg) gfc_conv_expr_descriptor (&argse, arg); gfc_add_block_to_block (&se->pre, &argse.pre); gfc_add_block_to_block (&se->post, &argse.post); - desc = gfc_evaluate_now (argse.expr, &se->pre); + tree ptr = gfc_evaluate_now (argse.expr, &se->pre); fncall0 = build_call_expr_loc (input_location, - gfor_fndecl_is_contiguous0, 1, desc); + gfor_fndecl_is_contiguous0, 1, ptr); + desc = build_fold_indirect_ref_loc (input_location, ptr); se->expr = fncall0; se->expr = convert (boolean_type_node, se->expr); } diff --git a/gcc/testsuite/gfortran.dg/is_contiguous_6.f90 b/gcc/testsuite/gfortran.dg/is_contiguous_6.f90 new file mode 100644 index 00000000000..28d11823567 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/is_contiguous_6.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! +! PR fortran/126892 +! The translation of the IS_CONTIGUOUS call used to cause an internal error +! because the variable used as descriptor for A was one pointer dereference +! away from the real descriptor. + +subroutine s(a) + integer, pointer, intent(in) :: a(..) + print *, is_contiguous(a) +end subroutine -- 2.53.0