[gcc(refs/users/mikael/heads/pr126892_v01)] fortran: Dereference descriptor pointer in IS_CONTIGUOUS code [PR126892]

Mikael Morin via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:91ad569a83b84816a6c8fd67e4dade0205fa3d50

commit 91ad569a83b84816a6c8fd67e4dade0205fa3d50
Author: Mikael Morin <[email protected]>
Date:   Sat Aug 15 17:23:27 2026 +0200

    fortran: Dereference descriptor pointer in IS_CONTIGUOUS code [PR126892]
    
    In the implementation of IS_CONTIGUOUS, the pointer resulting from the
    evaluation of the argument was stabilized to a variable and then used to
    access the descriptor fields.  This was causing an internal compiler error
    because the descriptor accessors aren't prepared to receive a pointer.
    Add the missing dereference to really get a descriptor-typed expression.
    
            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.

Diff:
---
 gcc/fortran/trans-intrinsic.cc                |  5 +++--
 gcc/testsuite/gfortran.dg/is_contiguous_6.f90 | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 5e3681da4675..69a6034b3d38 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 000000000000..28d118235670
--- /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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.