public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran@gcc.gnu.org
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fortran: error recovery on invalid array reference of non-array [PR103590]
Date: Tue, 19 Jul 2022 21:09:28 +0200	[thread overview]
Message-ID: <26b7b8f2-fd97-058c-40e1-d16b4e26880e@gmx.de> (raw)
In-Reply-To: <0342ad62-3f9c-4fbb-bd00-f4d4a6b49fc7@orange.fr>

Hi Mikael,

Am 19.07.22 um 11:03 schrieb Mikael Morin:
> Hello,
> 
> the principle looks good, but...
> 
> Le 18/07/2022 à 22:43, Harald Anlauf via Fortran a écrit :
> 
>> diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
>> index 2ebf076f730..dacd33561d0 100644
>> --- a/gcc/fortran/resolve.cc
>> +++ b/gcc/fortran/resolve.cc
>> @@ -5004,7 +5004,11 @@ find_array_spec (gfc_expr *e)
>>        {
>>        case REF_ARRAY:
>>      if (as == NULL)
>> -      gfc_internal_error ("find_array_spec(): Missing spec");
>> +      {
>> +        gfc_error ("Symbol %qs at %L has not been declared as an array",
>> +               e->symtree->n.sym->name, &e->where);
> 
> ... the error here only makes sense if the array reference follows a 
> variable reference.  If it follows a derived type component reference, a 
> slightly different error message would be more appropriate.

how detailed or tailored should the error message be, or can
we just have a more generic message, like "Name at %L ...",
or "Invalid subscript reference at %L"?  We seem to not hit
that internal error very often...

I have played only little with invalid code in the present context,
but often hit another code path that shows up in associate_54.f90
and gives

Error: Associate-name 'state' at (1) is used as array

For the testcase in the PR, Intel says:

associate_59.f90(7): error #6410: This name has not been declared as an 
array or a function.   [A]
     print *, [character(a(1)) :: '1'] ! { dg-error "Scalar INTEGER 
expression" }
------------------------^

Crayftn 14.0 says:

   Improper ir tree in expr_semantics.

     print *, [character(a(1)) :: '1'] ! { dg-error "Scalar INTEGER 
expression" }
                          ^ 

ftn-873 crayftn: ERROR P, File = associate_59.f90, Line = 7, Column = 26
   Invalid subscripted reference of a scalar ASSOCIATE name.


gfortran's behavior during error handling is difficult to understand.
While the proposed new error message is emitted for associate_54.f90,
it never makes it far enough for the testcase of the present PR
(associate_59.f90).

Thanks,
Harald


WARNING: multiple messages have this Message-ID
From: Harald Anlauf <anlauf@gmx.de>
To: Mikael Morin <morin-mikael@orange.fr>,
	fortran <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fortran: error recovery on invalid array reference of non-array [PR103590]
Date: Tue, 19 Jul 2022 21:09:28 +0200	[thread overview]
Message-ID: <26b7b8f2-fd97-058c-40e1-d16b4e26880e@gmx.de> (raw)
Message-ID: <20220719190928.lG5O7Mn8X2V4wGyr4ck8UIE5Q1CAEqIK47gYwxxQom4@z> (raw)
In-Reply-To: <0342ad62-3f9c-4fbb-bd00-f4d4a6b49fc7@orange.fr>

Hi Mikael,

Am 19.07.22 um 11:03 schrieb Mikael Morin:
> Hello,
>
> the principle looks good, but...
>
> Le 18/07/2022 à 22:43, Harald Anlauf via Fortran a écrit :
>
>> diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
>> index 2ebf076f730..dacd33561d0 100644
>> --- a/gcc/fortran/resolve.cc
>> +++ b/gcc/fortran/resolve.cc
>> @@ -5004,7 +5004,11 @@ find_array_spec (gfc_expr *e)
>>        {
>>        case REF_ARRAY:
>>      if (as == NULL)
>> -      gfc_internal_error ("find_array_spec(): Missing spec");
>> +      {
>> +        gfc_error ("Symbol %qs at %L has not been declared as an array",
>> +               e->symtree->n.sym->name, &e->where);
>
> ... the error here only makes sense if the array reference follows a
> variable reference.  If it follows a derived type component reference, a
> slightly different error message would be more appropriate.

how detailed or tailored should the error message be, or can
we just have a more generic message, like "Name at %L ...",
or "Invalid subscript reference at %L"?  We seem to not hit
that internal error very often...

I have played only little with invalid code in the present context,
but often hit another code path that shows up in associate_54.f90
and gives

Error: Associate-name 'state' at (1) is used as array

For the testcase in the PR, Intel says:

associate_59.f90(7): error #6410: This name has not been declared as an
array or a function.   [A]
     print *, [character(a(1)) :: '1'] ! { dg-error "Scalar INTEGER
expression" }
------------------------^

Crayftn 14.0 says:

   Improper ir tree in expr_semantics.

     print *, [character(a(1)) :: '1'] ! { dg-error "Scalar INTEGER
expression" }
                          ^

ftn-873 crayftn: ERROR P, File = associate_59.f90, Line = 7, Column = 26
   Invalid subscripted reference of a scalar ASSOCIATE name.


gfortran's behavior during error handling is difficult to understand.
While the proposed new error message is emitted for associate_54.f90,
it never makes it far enough for the testcase of the present PR
(associate_59.f90).

Thanks,
Harald

  reply	other threads:[~2022-07-19 19:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 20:43 Harald Anlauf
2022-07-19  9:03 ` Mikael Morin
2022-07-19 19:09   ` Harald Anlauf [this message]
2022-07-19 19:09     ` Harald Anlauf
2022-07-19 20:53     ` Mikael Morin
2022-07-19 21:34       ` Harald Anlauf
2022-07-19 21:34         ` Harald Anlauf
2022-07-20  9:40         ` 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=26b7b8f2-fd97-058c-40e1-d16b4e26880e@gmx.de \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /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).