public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] PR99125 - [9/10/11 Regression] ICE: gimplification failed (gimplify.c:15068)
@ 2021-02-24 14:05 Paul Richard Thomas
  2021-02-24 16:28 ` Tobias Burnus
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Richard Thomas @ 2021-02-24 14:05 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: gerhard.steinmetz.fortran

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

This problem was caused by the compiler attempting to use 0 as an lvalue
and to assign 0 to it. Understandably, this upset the gimplifer quite a bit
:-) The fix is to use the ss_info string length for deferred length
character components, where the hidden string length component has been
used. The use of a constant as an lvalue is prevented by checking that the
expression string length is a variable.

Regtests on FC33/x86_64 - OK for all three branches?

Paul

Fortran: Fix for class defined operators [PR99125].

2021-02-23  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/99125
* trans-array.c (gfc_conv_expr_descriptor): For deferred length
length components use the ss_info string length instead of
gfc_get_expr_charlen. Make sure that the deferred string length
is a variable before assigning to it. Otherwise use the expr.
* trans-expr.c (gfc_conv_string_length): Make sure that the
deferred string length is a variable before assigning to it.

gcc/testsuite/
PR fortran/99125
* gfortran.dg/alloc_deferred_comp_1.f90: New test.

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

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index c6725659093..e85d63c3539 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7670,15 +7670,21 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
       /* Set the string_length for a character array.  */
       if (expr->ts.type == BT_CHARACTER)
 	{
-	  se->string_length =  gfc_get_expr_charlen (expr);
+	  if (deferred_array_component)
+	    se->string_length = ss_info->string_length;
+	  else
+	    se->string_length =  gfc_get_expr_charlen (expr);
+
 	  if (VAR_P (se->string_length)
 	      && expr->ts.u.cl->backend_decl == se->string_length)
 	    tmp = ss_info->string_length;
 	  else
 	    tmp = se->string_length;
 
-	  if (expr->ts.deferred)
+	  if (expr->ts.deferred && VAR_P (expr->ts.u.cl->backend_decl))
 	    gfc_add_modify (&se->pre, expr->ts.u.cl->backend_decl, tmp);
+	  else
+	    expr->ts.u.cl->backend_decl = tmp;
 	}
 
       /* If we have an array section, are assigning  or passing an array
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index e61492485b8..9d178360fc3 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2471,7 +2471,7 @@ gfc_conv_string_length (gfc_charlen * cl, gfc_expr * expr, stmtblock_t * pblock)
 			     se.expr, build_zero_cst (TREE_TYPE (se.expr)));
   gfc_add_block_to_block (pblock, &se.pre);
 
-  if (cl->backend_decl)
+  if (cl->backend_decl && VAR_P (cl->backend_decl))
     gfc_add_modify (pblock, cl->backend_decl, se.expr);
   else
     cl->backend_decl = gfc_evaluate_now (se.expr, pblock);

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

! { dg-do run }
!
! Test the fix for PR99125, where the array reference in the print
! statement caused an ICE because the gimplifier complained about '0'
! being used as an lvalue.
!
! Contributed by Gerhard Steinmetz  <gscfq@t-online.de>
!
program p
   type t
      character(:), allocatable :: a(:)
   end type
   type(t) :: x
   character(8) :: c(3) = ['12 45 78','23 56 89','34 67 90']
   x%a = c
   if (any (x%a(2:3) .ne. ['23 56 89','34 67 90'])) stop 1
   if (any (x%a(2:3)(4:5) .ne. ['56','67'])) stop 2 ! Bizarrely this worked.
end

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

* Re: [Patch, fortran] PR99125 - [9/10/11 Regression] ICE: gimplification failed (gimplify.c:15068)
  2021-02-24 14:05 [Patch, fortran] PR99125 - [9/10/11 Regression] ICE: gimplification failed (gimplify.c:15068) Paul Richard Thomas
@ 2021-02-24 16:28 ` Tobias Burnus
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2021-02-24 16:28 UTC (permalink / raw)
  To: Paul Richard Thomas, fortran, gcc-patches; +Cc: gerhard.steinmetz.fortran

Hi Paul,

On 24.02.21 15:05, Paul Richard Thomas via Fortran wrote:
> This problem was caused by the compiler attempting to use 0 as an lvalue
> and to assign 0 to it.

I did recall the problem – and indeed: PR95868.

The trans-array.c patch does effectively the same as mine there, some
other use of 'tmp' but otherwise ...

The trans-expr patch, I didn't have; unfortunately, it does not solve
the other issues of my PR, either. (Thus, if you are interested in
continuing the len=: work ...)

[Once that PR is fixed, trans-openmp.c has to updated for it as well.]

> Understandably, this upset the gimplifer quite a bit
> :-) The fix is to use the ss_info string length for deferred length
> character components, where the hidden string length component has been
> used. The use of a constant as an lvalue is prevented by checking that the
> expression string length is a variable.
>
> Regtests on FC33/x86_64 - OK for all three branches?

LGTM.

Thanks for the patch!

Tobias

> Fortran: Fix for class defined operators [PR99125].
>
> 2021-02-23  Paul Thomas  <pault@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/99125
> * trans-array.c (gfc_conv_expr_descriptor): For deferred length
> length components use the ss_info string length instead of
> gfc_get_expr_charlen. Make sure that the deferred string length
> is a variable before assigning to it. Otherwise use the expr.
> * trans-expr.c (gfc_conv_string_length): Make sure that the
> deferred string length is a variable before assigning to it.
>
> gcc/testsuite/
> PR fortran/99125
> * gfortran.dg/alloc_deferred_comp_1.f90: New test.
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

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

end of thread, other threads:[~2021-02-24 16:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 14:05 [Patch, fortran] PR99125 - [9/10/11 Regression] ICE: gimplification failed (gimplify.c:15068) Paul Richard Thomas
2021-02-24 16:28 ` Tobias Burnus

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