* [Patch, fortran] PR103716 - [10/11/12/13/14 Regression] ICE in gimplify_expr, at gimplify.c:15964
@ 2023-05-09 16:00 Paul Richard Thomas
2023-05-09 18:29 ` Harald Anlauf
0 siblings, 1 reply; 3+ messages in thread
From: Paul Richard Thomas @ 2023-05-09 16:00 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1.1: Type: text/plain, Size: 1086 bytes --]
Hi All,
This problem caused the gimplifier failure because the reference chain
ending in an inquiry_len still retained a full array reference. This had
already been corrected for deferred character lengths but the fix extends
this to all characters without a length expression and integer expressions,
which is the correct type of course, that retain a full array_spec. The
nullification of the se->string length in conv_inquiry is a
belts-and-braces measure to stop it from winding up as a hidden argument in
procedure calls.
OK for trunk and, after a decent delay, backporting?
Cheers
Paul
Fortran: Fix assumed length chars and len inquiry [PR103716]
2023-05-09 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/103716
* resolve.cc (gfc_resolve_ref): Conversion of array_ref into an
element should be done for all characters without a len expr,
not just deferred lens, and for integer expressions.
* trans-expr.cc (conv_inquiry): For len and kind inquiry refs,
set the se string_length to NULL_TREE.
gcc/testsuite/
PR fortran/103716
* gfortran.dg/pr103716 : New test.
[-- Attachment #2: pr103716.diff --]
[-- Type: text/x-patch, Size: 1243 bytes --]
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 55d8e326a87..8f0dd8b6dee 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -5504,7 +5504,9 @@ gfc_resolve_ref (gfc_expr *expr)
case REF_INQUIRY:
/* Implement requirement in note 9.7 of F2018 that the result of the
LEN inquiry be a scalar. */
- if (ref->u.i == INQUIRY_LEN && array_ref && expr->ts.deferred)
+ if (ref->u.i == INQUIRY_LEN && array_ref
+ && ((expr->ts.type == BT_CHARACTER && !expr->ts.u.cl->length)
+ || expr->ts.type == BT_INTEGER))
{
array_ref->u.ar.type = AR_ELEMENT;
expr->rank = 0;
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 09cdd9263c4..3225b419989 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -2861,11 +2861,13 @@ conv_inquiry (gfc_se * se, gfc_ref * ref, gfc_expr *expr, gfc_typespec *ts)
case INQUIRY_KIND:
res = build_int_cst (gfc_typenode_for_spec (&expr->ts),
ts->kind);
+ se->string_length = NULL_TREE;
break;
case INQUIRY_LEN:
res = fold_convert (gfc_typenode_for_spec (&expr->ts),
se->string_length);
+ se->string_length = NULL_TREE;
break;
default:
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch, fortran] PR103716 - [10/11/12/13/14 Regression] ICE in gimplify_expr, at gimplify.c:15964
2023-05-09 16:00 [Patch, fortran] PR103716 - [10/11/12/13/14 Regression] ICE in gimplify_expr, at gimplify.c:15964 Paul Richard Thomas
@ 2023-05-09 18:29 ` Harald Anlauf
2023-05-09 20:25 ` Paul Richard Thomas
0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2023-05-09 18:29 UTC (permalink / raw)
To: Paul Richard Thomas, fortran, gcc-patches
Hi Paul,
On 5/9/23 18:00, Paul Richard Thomas via Gcc-patches wrote:
> Hi All,
>
> This problem caused the gimplifier failure because the reference chain
> ending in an inquiry_len still retained a full array reference. This had
> already been corrected for deferred character lengths but the fix extends
> this to all characters without a length expression and integer expressions,
> which is the correct type of course, that retain a full array_spec. The
> nullification of the se->string length in conv_inquiry is a
> belts-and-braces measure to stop it from winding up as a hidden argument in
> procedure calls.
>
> OK for trunk and, after a decent delay, backporting?
ENOTESTCASE.
Nevertheless the patch LGTM and is also OK for backporting.
Thanks for fixing this!
Harald
> Cheers
>
> Paul
>
> Fortran: Fix assumed length chars and len inquiry [PR103716]
>
> 2023-05-09 Paul Thomas <pault@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/103716
> * resolve.cc (gfc_resolve_ref): Conversion of array_ref into an
> element should be done for all characters without a len expr,
> not just deferred lens, and for integer expressions.
> * trans-expr.cc (conv_inquiry): For len and kind inquiry refs,
> set the se string_length to NULL_TREE.
>
> gcc/testsuite/
> PR fortran/103716
> * gfortran.dg/pr103716 : New test.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch, fortran] PR103716 - [10/11/12/13/14 Regression] ICE in gimplify_expr, at gimplify.c:15964
2023-05-09 18:29 ` Harald Anlauf
@ 2023-05-09 20:25 ` Paul Richard Thomas
0 siblings, 0 replies; 3+ messages in thread
From: Paul Richard Thomas @ 2023-05-09 20:25 UTC (permalink / raw)
To: Harald Anlauf; +Cc: fortran, gcc-patches
[-- Attachment #1.1: Type: text/plain, Size: 1609 bytes --]
Duuh! There's even a choice :-)
Paul
On Tue, 9 May 2023 at 19:29, Harald Anlauf <anlauf@gmx.de> wrote:
> Hi Paul,
>
> On 5/9/23 18:00, Paul Richard Thomas via Gcc-patches wrote:
> > Hi All,
> >
> > This problem caused the gimplifier failure because the reference chain
> > ending in an inquiry_len still retained a full array reference. This had
> > already been corrected for deferred character lengths but the fix extends
> > this to all characters without a length expression and integer
> expressions,
> > which is the correct type of course, that retain a full array_spec. The
> > nullification of the se->string length in conv_inquiry is a
> > belts-and-braces measure to stop it from winding up as a hidden argument
> in
> > procedure calls.
> >
> > OK for trunk and, after a decent delay, backporting?
>
> ENOTESTCASE.
>
> Nevertheless the patch LGTM and is also OK for backporting.
>
> Thanks for fixing this!
>
> Harald
>
>
> > Cheers
> >
> > Paul
> >
> > Fortran: Fix assumed length chars and len inquiry [PR103716]
> >
> > 2023-05-09 Paul Thomas <pault@gcc.gnu.org>
> >
> > gcc/fortran
> > PR fortran/103716
> > * resolve.cc (gfc_resolve_ref): Conversion of array_ref into an
> > element should be done for all characters without a len expr,
> > not just deferred lens, and for integer expressions.
> > * trans-expr.cc (conv_inquiry): For len and kind inquiry refs,
> > set the se string_length to NULL_TREE.
> >
> > gcc/testsuite/
> > PR fortran/103716
> > * gfortran.dg/pr103716 : New test.
>
>
--
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein
[-- Attachment #2: pr103716b.f90 --]
[-- Type: text/x-fortran, Size: 649 bytes --]
! { dg-do run }
!
! The gimplifier used to throw a fit on the write statements in f1 and f2.
!
! Contributed by Gerhard Steinmetz <gscfq@t-online.de>
!
module m
character(6) :: buffer
contains
integer function g(x)
integer :: x
g = x
end
integer function f1(x)
character(*) :: x(*)
write (buffer(1:3),'(i2)') g(x%len)
end
integer function f2(x)
character(*) :: x(3)
write (buffer(4:6),'(i2)') g(x%len)
end
end module m
use m
integer :: i(2), j
character(2), dimension(3) :: chr = ['ab','cd','ef']
i(1) = f1(chr)
i(2) = f2(chr)
if (any (i .eq.2)) stop 1
if (trim(buffer) .ne. ' 2 2') stop 2
end
[-- Attachment #3: pr103716.f90 --]
[-- Type: text/x-fortran, Size: 270 bytes --]
! { dg-do compile }
!
! The gimplifier used to throw a fit on thes two functions.
!
! Contributed by Gerhard Steinmetz <gscfq@t-online.de>
!
function f1(x)
character(*) :: x(*)
print *, g(x%len)
end
function f2(x)
character(*) :: x(3)
print *, g(x%len)
end
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-09 20:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-09 16:00 [Patch, fortran] PR103716 - [10/11/12/13/14 Regression] ICE in gimplify_expr, at gimplify.c:15964 Paul Richard Thomas
2023-05-09 18:29 ` Harald Anlauf
2023-05-09 20:25 ` 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).