public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikael Morin <morin-mikael@orange.fr>
To: Harald Anlauf <anlauf@gmx.de>, sgk@troutmask.apl.washington.edu
Cc: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fortran: use name of array component in runtime error message [PR30802]
Date: Tue, 30 Jan 2024 11:38:10 +0100	[thread overview]
Message-ID: <50f2a7c0-55af-4079-9f6f-41dc6497c234@orange.fr> (raw)
In-Reply-To: <bdec0f2f-2acb-43ee-ac69-66cdf9e50c61@gmx.de>

Le 29/01/2024 à 21:50, Harald Anlauf a écrit :
> Am 29.01.24 um 18:25 schrieb Harald Anlauf:
>> I was talking about the generated format strings of runtime error
>> messages.
>>
>> program p
>>    implicit none
>>    type t
>>       real :: zzz(10) = 42
>>    end type t
>>    class(t), allocatable :: xx(:)
>>    integer :: j
>>    j = 0
>>    allocate (t :: xx(1))
>>    print *, xx(1)% zzz(j)
>> end
>>
>> This is generating the following error at runtime since at least gcc-7:
>>
>> Fortran runtime error: Index '0' of dimension 1 of array 'xx%_data%zzz'
>> below lower bound of 1
> 
> Of course this is easily suppressed by:
> 
> diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
> index 1e0d698a949..fa0e00a28a6 100644
> --- a/gcc/fortran/trans-array.cc
> +++ b/gcc/fortran/trans-array.cc
> @@ -4054,7 +4054,8 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref *
> ar, gfc_expr *expr,
>       {
>         if (ref->type == REF_ARRAY && &ref->u.ar == ar)
>           break;
> -      if (ref->type == REF_COMPONENT)
> +      if (ref->type == REF_COMPONENT
> +          && strcmp (ref->u.c.component->name, "_data") != 0)
>           {
>             strcat (var_name, "%%");
>             strcat (var_name, ref->u.c.component->name);
> 
> 
> I have been contemplating the generation the full chain of references as
> suggested by Mikael and supported by NAG.


To be clear, my suggestion was to have the question marks (or dashes, 
dots, stars, whatever) literally in the array reference, without the 
actual values of the array indexes.

Another (easier) way to clarify the data reference would be rephrasing 
the message so that the array part is separate from the scalar part, 
like so (there are too many 'of', but I lack inspiration):
Index '0' of dimension 1 of component 'zz' of element from 'x1%vv'
below lower bound of 1


> The main issue is: how do I easily generate that call?

> gfc_trans_runtime_check is a vararg function, but what I would rather
> have is a function that takes either a (chained?) list of trees or
> an array of trees holding the (co-)indices of the reference.
> 
> Is there an example, or a recommendation which variant to prefer?
> 
None that I know.
For a scalarized expression, the values are present (among others) in 
the gfc_loopinfo::ss linked list, maybe just use that?
In any case, I agree it would be nice to have, but it would probably be 
a non-negligible amount of new error-prone code; I would rather not 
attempt this during the stage4 stabilization phase as we are currently.

  reply	other threads:[~2024-01-30 10:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 21:39 Harald Anlauf
2024-01-28 11:39 ` Mikael Morin
2024-01-28 19:56   ` Harald Anlauf
2024-01-28 21:43     ` Steve Kargl
2024-01-29  6:51       ` rep.dot.nop
2024-01-29 17:25       ` Harald Anlauf
2024-01-29 20:50         ` Harald Anlauf
2024-01-30 10:38           ` Mikael Morin [this message]
2024-01-30 10:46             ` Mikael Morin
2024-03-10 21:31               ` [PATCH, v2] " Harald Anlauf
2024-03-15 16:31                 ` Mikael Morin
2024-03-15 17:26                   ` Harald Anlauf
2024-03-15 19:29                     ` Mikael Morin
2024-03-20 20:24                       ` [PATCH, v3] Fortran: improve array component description " Harald Anlauf
2024-03-21 13:07                         ` Mikael Morin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50f2a7c0-55af-4079-9f6f-41dc6497c234@orange.fr \
    --to=morin-mikael@orange.fr \
    --cc=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=sgk@troutmask.apl.washington.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).