public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] PR98472 - internal compiler error: in gfc_conv_expr_descriptor, at fortran/trans-array.c:7352
@ 2021-01-25 15:25 Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2021-01-25 15:25 UTC (permalink / raw)
  To: fortran

Before I do any more, I would like to ask which version of the fix for this
PR is preferred.

This is an additive patch:

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 4bd4db877bd..78db9421385 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7477,7 +7482,9 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
  && expr->value.function.esym->attr.elemental)
  || (expr->value.function.isym != NULL
     && expr->value.function.isym->elemental)
- || gfc_inline_intrinsic_function_p (expr));
+ || gfc_inline_intrinsic_function_p (expr)
+ || (gfc_expr_attr (expr).proc_pointer
+    && gfc_expr_attr (expr).elemental));
   else
     gcc_assert (ss_type == GFC_SS_INTRINSIC);

The above chunk is preceeded by:
      if (ss_expr != expr || ss_type != GFC_SS_FUNCTION)
         {
             if (ss_expr != expr)

so it can be seen that the second gcc_assert is redundant. The alternative
patch is simply to remove both gcc_asserts. Both versions fix the problem
and regtest OK.

My preference is to remove both gcc_asserts.

Paul

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

* [Patch, fortran] PR98472 - internal compiler error: in gfc_conv_expr_descriptor, at fortran/trans-array.c:7352
@ 2021-01-27  9:20 Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2021-01-27  9:20 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 711 bytes --]

I have applied another obvious patch to fix this PR. It was tempting to
remove both gcc-asserts but I have erred on the side of caution this time.

Commit r11-6924-g003f0414291d595d2126e6d2e24b281f38f3448f

Again, it is sufficiently safe and obvious that I am tempted to put it on
my list of backports.

Paul

Fortran: Fix ICE due to elemental procedure pointers [PR98472].

2021-01-27  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/98472
* trans-array.c (gfc_conv_expr_descriptor): Include elemental
procedure pointers in the assert under the comment 'elemental
function' and eliminate the second, spurious assert.

gcc/testsuite/
PR fortran/98472
* gfortran.dg/elemental_function_5.f90 : New test.

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 635 bytes --]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 4bd4db877bd..c346183e129 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7477,9 +7477,9 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
 			 && expr->value.function.esym->attr.elemental)
 			|| (expr->value.function.isym != NULL
 			    && expr->value.function.isym->elemental)
+			|| (gfc_expr_attr (expr).proc_pointer
+			    && gfc_expr_attr (expr).elemental)
 			|| gfc_inline_intrinsic_function_p (expr));
-	  else
-	    gcc_assert (ss_type == GFC_SS_INTRINSIC);
 
 	  need_tmp = 1;
 	  if (expr->ts.type == BT_CHARACTER

[-- Attachment #3: elemental_function_5.f90 --]
[-- Type: text/x-fortran, Size: 1238 bytes --]

! { dg-do compile }
!
! Test the fix for PR98472.
!
! Contributed by Rui Coelho  <ruicoelhopedro@hotmail.com>
!
module a
        type, abstract :: base
        contains
                procedure(elem_func), deferred, nopass :: add
        end type base

        type, extends(base) :: derived
        contains
                procedure, nopass :: add => add_derived
        end type derived

        abstract interface
                elemental function elem_func(x, y) result(out)
                        integer, intent(in) :: x, y
                        integer :: out
                end function elem_func
        end interface

contains
        elemental function add_derived(x, y) result(out)
                integer, intent(in) :: x, y
                integer :: out
                out = x + y
        end function add_derived
end module a

program main
        use a
        call foo
contains
        subroutine foo
               integer, dimension(:), allocatable :: vec
               class(base), allocatable :: instance
               allocate(derived :: instance)
               allocate(vec, source=instance%add([1, 2], [1, 2])) ! ICE here
               if (any (vec .ne. [2, 4])) stop 1
        end
end program main



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

end of thread, other threads:[~2021-01-27  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 15:25 [Patch, fortran] PR98472 - internal compiler error: in gfc_conv_expr_descriptor, at fortran/trans-array.c:7352 Paul Richard Thomas
2021-01-27  9:20 Paul Richard Thomas

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).