public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/102456] New: ICE in gfc_check_rank, at fortran/check.c:4594
@ 2021-09-22 17:38 gscfq@t-online.de
  2021-09-22 19:43 ` [Bug fortran/102456] " kargl at gcc dot gnu.org
  2021-09-29 18:52 ` gscfq@t-online.de
  0 siblings, 2 replies; 3+ messages in thread
From: gscfq@t-online.de @ 2021-09-22 17:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102456

            Bug ID: 102456
           Summary: ICE in gfc_check_rank, at fortran/check.c:4594
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gscfq@t-online.de
  Target Milestone: ---

Affects versions down to at least r5 :


$ cat z1.f90
program p
   type t
      integer :: a
   end type
   type(t) :: x[*]
   print *, rank(x[1])
end


$ gfortran-12-20210919 -c z1.f90 -fcoarray=single
$
$ gfortran-12-20210919 -c z1.f90 -fcoarray=lib
f951: internal compiler error: Segmentation fault
0xc8446f crash_signal
        ../../gcc/toplev.c:328
0x6afceb gfc_check_rank(gfc_expr*)
        ../../gcc/fortran/check.c:4594
0x6eddf9 do_check
        ../../gcc/fortran/intrinsic.c:4786
0x6eddf9 check_specific
        ../../gcc/fortran/intrinsic.c:4799
0x6f81b4 gfc_intrinsic_func_interface(gfc_expr*, int)
        ../../gcc/fortran/intrinsic.c:5036
0x74a859 resolve_unknown_f
        ../../gcc/fortran/resolve.c:2937
0x74a859 resolve_function
        ../../gcc/fortran/resolve.c:3281
0x74a859 gfc_resolve_expr(gfc_expr*)
        ../../gcc/fortran/resolve.c:7115
0x750d44 gfc_resolve_expr(gfc_expr*)
        ../../gcc/fortran/resolve.c:7082
0x750d44 gfc_resolve_code(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.c:11876
0x74f68f gfc_resolve_blocks(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.c:10892
0x74fa58 gfc_resolve_code(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.c:11866
0x752397 resolve_codes
        ../../gcc/fortran/resolve.c:17479
0x75245e gfc_resolve(gfc_namespace*)
        ../../gcc/fortran/resolve.c:17514
0x73a874 resolve_all_program_units
        ../../gcc/fortran/parse.c:6511
0x73a874 gfc_parse_file()
        ../../gcc/fortran/parse.c:6763
0x78761f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:216

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/102456] ICE in gfc_check_rank, at fortran/check.c:4594
  2021-09-22 17:38 [Bug fortran/102456] New: ICE in gfc_check_rank, at fortran/check.c:4594 gscfq@t-online.de
@ 2021-09-22 19:43 ` kargl at gcc dot gnu.org
  2021-09-29 18:52 ` gscfq@t-online.de
  1 sibling, 0 replies; 3+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-09-22 19:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102456

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Priority|P3                          |P4
   Last reconfirmed|                            |2021-09-22

--- Comment #1 from kargl at gcc dot gnu.org ---
The following diff stops the ICE, which is a null pointer dereference.

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 851af1b30dc..2a250d73a28 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -4589,9 +4589,14 @@ gfc_check_rank (gfc_expr *a)

   /* Functions returning pointers are regarded as variable, cf. F2008, R602. 
*/
   if (a->expr_type == EXPR_FUNCTION)
-    is_variable = a->value.function.esym
-                 ? a->value.function.esym->result->attr.pointer
-                 : a->symtree->n.sym->result->attr.pointer;
+    {
+      if (a->value.function.esym && a->value.function.esym->result)
+       is_variable = a->value.function.esym->result->attr.pointer;
+      else if (a->symtree->n.sym->result)
+       is_variable = a->symtree->n.sym->result->attr.pointer;
+      else
+       is_variable = false;
+    }

   if (a->expr_type == EXPR_OP
       || a->expr_type == EXPR_NULL

But, the patch yields

% gfcx -c -fcoarray=lib a.f90
a.f90:6:17:

    6 |    print *, rank(x[1])
      |                 1
Error: The argument of the RANK intrinsic at (1) must be a data object

and Gerhard indicates the code is legal.  I don't use coarrays say cannot
confirm or deny this assertion.  I do note that if one pokes around in
gdb that one finds

(gdb) p *a->value.function.actual->expr->symtree->n.sym->as 
$11 = {rank = 0, corank = 1, type = AS_EXPLICIT, cotype = AS_EXPLICIT, 
  lower = {0x203627620, 0x0 <repeats 14 times>}, upper = {
    0x0 <repeats 15 times>}, cray_pointee = false, cp_was_assumed = false, 
  resolved = true}

which is the only place I can locate rank and corank info.  I'll also
note that we do have

(gdb) p a->rank
$13 = 0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/102456] ICE in gfc_check_rank, at fortran/check.c:4594
  2021-09-22 17:38 [Bug fortran/102456] New: ICE in gfc_check_rank, at fortran/check.c:4594 gscfq@t-online.de
  2021-09-22 19:43 ` [Bug fortran/102456] " kargl at gcc dot gnu.org
@ 2021-09-29 18:52 ` gscfq@t-online.de
  1 sibling, 0 replies; 3+ messages in thread
From: gscfq@t-online.de @ 2021-09-29 18:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102456

--- Comment #2 from G. Steinmetz <gscfq@t-online.de> ---

It compiles when using "size(shape(x))" as a synonym for "rank(x)".
And indeed, that scalar x (from image 1) has rank 0.

$ cat z2.f90
program p
   type t
      integer :: a
   end type
   type(t) :: x[*]
   print *, size(shape(x[1]))
end

$ gfortran-12 -c z2.f90 -fcoarray=lib
$

---

Simplified a bit with "integer" instead of "type(t)".
All of the following variants work i.e. with -fcoarray=single :


$ cat z4.f90
program p
   integer :: a
   integer :: b(2)
   integer :: c(2,3)
   integer :: d(2,3,5)
   print *, rank(a), size(shape(a))
   print *, rank(b), size(shape(b))
   print *, rank(c), size(shape(c))
   print *, rank(d), size(shape(d))
end


$ cat z5.f90
program p
   integer :: a[*]
   integer :: b(2)[*]
   integer :: c(2,3)[*]
   integer :: d(2,3,5)[*]
   print *, rank(a), size(shape(a))
   print *, rank(b), size(shape(b))
   print *, rank(c), size(shape(c))
   print *, rank(d), size(shape(d))
end


$ cat z6.f90
program p
   integer :: a[*]
   integer :: b(2)[*]
   integer :: c(2,3)[*]
   integer :: d(2,3,5)[*]
   print *, rank(a[1]), size(shape(a[1]))
   print *, rank(b(:)[1]), size(shape(b(:)[1]))
   print *, rank(c(:,:)[1]), size(shape(c(:,:)[1]))
   print *, rank(d(:,:,:)[1]), size(shape(d(:,:,:)[1]))
end


$ gfortran-12 z4.f90 && ./a.out
           0           0
           1           1
           2           2
           3           3

$ gfortran-12 z5.f90 -fcoarray=single && ./a.out
           0           0
           1           1
           2           2
           3           3

$ gfortran-12 z6.f90 -fcoarray=single && ./a.out
           0           0
           1           1
           2           2
           3           3

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-29 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 17:38 [Bug fortran/102456] New: ICE in gfc_check_rank, at fortran/check.c:4594 gscfq@t-online.de
2021-09-22 19:43 ` [Bug fortran/102456] " kargl at gcc dot gnu.org
2021-09-29 18:52 ` gscfq@t-online.de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).