[patch, fortran] Fix PR PR93500

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch, fortran] Fix PR PR93500

gcc - fortran mailing list
Hello world,

this patch fixes PR PR93500.  One part of it is due to
what Steve wrote in the patch (returning from resolutions when both
operands are NULL), but that still left a nonsensical error.
Returning &gfc_bad_expr when simplifying bounds resulted in the
division by zero error actually reaching the user.

As to why there is an extra error when this is done in the main
program, as compared to a subroutine, I don't know, but I do not
particularly care. What is important is that the first error message
is clear and reaches the user.

Regression-tested. OK for trunk?

Regards

        Thomas

2020-04-16  Thomas Koenig  <[hidden email]>

        PR fortran/93500
        * resolve.c (resolve_operator): If both operands are
        NULL, return false.
        * simplify.c (simplify_bound): If a division by zero
        was seen during bound simplification, free the
        corresponcing expression and return &gfc_bad_expr.

2020-04-16  Thomas Koenig  <[hidden email]>

        PR fortran/93500
        * arith_divide_3.f90: New test.

p3.diff.txt (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [patch, fortran] Fix PR PR93500

gcc - fortran mailing list
Hi Fritz,

> First, it appears if simplify_bound_dim returns &gfc_bad_expr (and a
> div/0 occurs) then this code will free &gfc_bad_expr. I'm not sure
> whether or not that can actually occur, but it is certainly incorrect,
> since &gfc_bad_expr points to static storage. The only other possible
> case is bounds[d] == NULL, in which case the free is a no-op. I
> suggest removing the free call.

OK, removed.

> That being said, it looks like the same error condition can occur with
> the lcobound intrinsic.

I have adjusted the test case so it also checks for the coarray case;
this is handled correctly with a "Divion by zero" error without
changing the patch in that respect.

So, anything else?  If not, I will commit this within a few days.

Regards

        Thomas

p4.diff.txt (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [patch, fortran] Fix PR PR93500

gcc - fortran mailing list
On Fri, Apr 17, 2020 at 10:33 AM Thomas Koenig <[hidden email]> wrote:

>
> Hi Fritz,
>
> > First, it appears if simplify_bound_dim returns &gfc_bad_expr (and a
> > div/0 occurs) then this code will free &gfc_bad_expr. I'm not sure
> > whether or not that can actually occur, but it is certainly incorrect,
> > since &gfc_bad_expr points to static storage. The only other possible
> > case is bounds[d] == NULL, in which case the free is a no-op. I
> > suggest removing the free call.
>
> OK, removed.
>
> > That being said, it looks like the same error condition can occur with
> > the lcobound intrinsic.
>
> I have adjusted the test case so it also checks for the coarray case;
> this is handled correctly with a "Divion by zero" error without
> changing the patch in that respect.
>
> So, anything else?  If not, I will commit this within a few days.
>

Let the record show I am unsettled that the error path is different
between simplify_bound and simplify_cobound, and that different errors
occur for the program and subroutine case. There is probably a root
cause somewhere else that should be fixed one day. However! That is
not a problem for this PR, nor for stage 4, and is certainly no fault
of this patch. Therefore the patch looks OK to me for now. Thank you
for your work!

---
Fritz Reese