Fortran: error recovery for invalid types in array constructors [PR107000]

Message ID d67bf978-369e-6eb1-6dc3-dfc01827f725@orange.fr
State New
Headers
Series Fortran: error recovery for invalid types in array constructors [PR107000] |

Commit Message

Mikael Morin Oct. 5, 2022, 9:23 a.m. UTC
  Le 05/10/2022 ? 10:51, Mikael Morin a ?crit?:
> 
> Unfortunately, it doesn't fix the bogus incommensurate arrays errors.
> 

The following does.


    if (rc != ARITH_OK)


There is one last thing that I'm dissatisfied with.
The handling of unknown types should be moved to reduce_binary, because 
the dispatching in reduce_binary doesn't handle EXPR_OP, so even if 
either or both operands are scalar, they are handled by the (array vs 
array) reduce_binary_aa function.  That's confusing.
  

Comments

Harald Anlauf Oct. 5, 2022, 9:40 p.m. UTC | #1
Hi Mikael,

> Gesendet: Mittwoch, 05. Oktober 2022 um 11:23 Uhr
> Von: "Mikael Morin" <morin-mikael@orange.fr>
> An: "Harald Anlauf" <anlauf@gmx.de>, "fortran" <fortran@gcc.gnu.org>, "gcc-patches" <gcc-patches@gcc.gnu.org>
> Betreff: Re: [PATCH] Fortran: error recovery for invalid types in array constructors [PR107000]

> The following does.
>
>
> diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
> index e6e35ef3c42..2c57c796270 100644
> --- a/gcc/fortran/arith.cc
> +++ b/gcc/fortran/arith.cc
> @@ -1443,7 +1443,7 @@ reduce_binary_aa (arith (*eval) (gfc_expr *,
> gfc_expr *, gfc_expr **),
>          gfc_replace_expr (c->expr, r);
>       }
>
> -  if (c || d)
> +  if (rc == ARITH_OK && (c || d))
>       rc = ARITH_INCOMMENSURATE;
>
>     if (rc != ARITH_OK)

that's great!  It fixes several rather weird cases.  (There is at least
another PR on the incommensurate arrays, but we should not attempt to
fix everything today.)

> There is one last thing that I'm dissatisfied with.
> The handling of unknown types should be moved to reduce_binary, because
> the dispatching in reduce_binary doesn't handle EXPR_OP, so even if
> either or both operands are scalar, they are handled by the (array vs
> array) reduce_binary_aa function.  That's confusing.

Do you have an example?

Anyway, please find attached an updated patch that incorporates your
two changes and regtests fine on x86_64-pc-linux-gnu.

Even if you disagree, I think this is really a significant step
forwards... (error-recovery wise).

OK for mainline?

Thanks,
Harald

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr107000-v2.diff
Type: text/x-patch
Size: 8192 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20221005/0262664b/attachment.bin>
  

Patch

diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
index e6e35ef3c42..2c57c796270 100644
--- a/gcc/fortran/arith.cc
+++ b/gcc/fortran/arith.cc
@@ -1443,7 +1443,7 @@  reduce_binary_aa (arith (*eval) (gfc_expr *, 
gfc_expr *, gfc_expr **),
         gfc_replace_expr (c->expr, r);
      }

-  if (c || d)
+  if (rc == ARITH_OK && (c || d))
      rc = ARITH_INCOMMENSURATE;