* [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
@ 2021-12-20 22:05 Harald Anlauf
2021-12-21 12:38 ` Mikael Morin
0 siblings, 1 reply; 7+ messages in thread
From: Harald Anlauf @ 2021-12-20 22:05 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 416 bytes --]
Dear all,
we need to check the arguments of the elemental MASKL and MASKR
intrinsics also before simplifying.
Testcase by Gerhard. The fix is almost obvious, but I'm happy to
get feedback in case there is something I overlooked. (There is
already a check on scalar arguments to MASKL/MASKR, which however
misses the case of array arguments.)
Regtested on x86_64-pc-linux-gnu. OK for mainline?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-check-arguments-of-MASKL-MASKR-intrinsics-be.patch --]
[-- Type: text/x-patch, Size: 2398 bytes --]
From b58a44bc861ee3d1e67e3b7c949a301b6290c05c Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 20 Dec 2021 22:59:53 +0100
Subject: [PATCH] Fortran: check arguments of MASKL/MASKR intrinsics before
simplification
gcc/fortran/ChangeLog:
PR fortran/103777
* simplify.c (gfc_simplify_maskr): Check validity of argument 'I'
before simplifying.
(gfc_simplify_maskl): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/103777
* gfortran.dg/masklr_3.f90: New test.
---
gcc/fortran/simplify.c | 6 ++++++
gcc/testsuite/gfortran.dg/masklr_3.f90 | 14 ++++++++++++++
2 files changed, 20 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/masklr_3.f90
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 90067b6bbe6..b6f636d4ff1 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -4878,6 +4878,9 @@ gfc_simplify_maskr (gfc_expr *i, gfc_expr *kind_arg)
bool fail = gfc_extract_int (i, &arg);
gcc_assert (!fail);
+ if (!gfc_check_mask (i, kind_arg))
+ return &gfc_bad_expr;
+
result = gfc_get_constant_expr (BT_INTEGER, kind, &i->where);
/* MASKR(n) = 2^n - 1 */
@@ -4909,6 +4912,9 @@ gfc_simplify_maskl (gfc_expr *i, gfc_expr *kind_arg)
bool fail = gfc_extract_int (i, &arg);
gcc_assert (!fail);
+ if (!gfc_check_mask (i, kind_arg))
+ return &gfc_bad_expr;
+
result = gfc_get_constant_expr (BT_INTEGER, kind, &i->where);
/* MASKL(n) = 2^bit_size - 2^(bit_size - n) */
diff --git a/gcc/testsuite/gfortran.dg/masklr_3.f90 b/gcc/testsuite/gfortran.dg/masklr_3.f90
new file mode 100644
index 00000000000..eb689f0f408
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/masklr_3.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR fortran/103777 - ICE in gfc_simplify_maskl
+! Contributed by G.Steinmetz
+
+program p
+ print *, maskl([999]) ! { dg-error "must be less than or equal" }
+ print *, maskr([999]) ! { dg-error "must be less than or equal" }
+ print *, maskl([-999]) ! { dg-error "must be nonnegative" }
+ print *, maskr([-999]) ! { dg-error "must be nonnegative" }
+ print *, maskl([32],kind=4)
+ print *, maskl([33],kind=4) ! { dg-error "must be less than or equal" }
+ print *, maskl([64],kind=8)
+ print *, maskl([65],kind=8) ! { dg-error "must be less than or equal" }
+end
--
2.26.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
2021-12-20 22:05 [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918 Harald Anlauf
@ 2021-12-21 12:38 ` Mikael Morin
2022-01-06 19:50 ` Harald Anlauf
0 siblings, 1 reply; 7+ messages in thread
From: Mikael Morin @ 2021-12-21 12:38 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Le 20/12/2021 à 23:05, Harald Anlauf via Fortran a écrit :
> Dear all,
>
> we need to check the arguments of the elemental MASKL and MASKR
> intrinsics also before simplifying.
>
> Testcase by Gerhard. The fix is almost obvious, but I'm happy to
> get feedback in case there is something I overlooked. (There is
> already a check on scalar arguments to MASKL/MASKR, which however
> misses the case of array arguments.)
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
Your patch looks reasonable and safe.
However, I find it surprising that it’s actually needed, as gfc_check
mask is already the check function associated to maskl and maskr in the
definition of the symbols. The simplification function should be called
only when the associated check function has returned successfully, so it
shouldn’t be necessary to call it again at simplification time.
Looking at the backtrace, it is the do_simplify call at the beginning of
gfc_intrinsic_func_interface that seems dubious to me, as it comes
before all the check further down in the function and it looks redundant
with the other simplification code after the checks.
So I’m inclined to test whether by any chance removing that call works,
and if it doesn’t, let’s go with this patch.
Mikael
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
2021-12-21 12:38 ` Mikael Morin
@ 2022-01-06 19:50 ` Harald Anlauf
2022-01-06 19:50 ` Harald Anlauf
2022-01-06 21:44 ` Mikael Morin
0 siblings, 2 replies; 7+ messages in thread
From: Harald Anlauf @ 2022-01-06 19:50 UTC (permalink / raw)
To: Mikael Morin, fortran, gcc-patches
Hi Mikael,
Am 21.12.21 um 13:38 schrieb Mikael Morin:
> Le 20/12/2021 à 23:05, Harald Anlauf via Fortran a écrit :
>> Dear all,
>>
>> we need to check the arguments of the elemental MASKL and MASKR
>> intrinsics also before simplifying.
>>
>> Testcase by Gerhard. The fix is almost obvious, but I'm happy to
>> get feedback in case there is something I overlooked. (There is
>> already a check on scalar arguments to MASKL/MASKR, which however
>> misses the case of array arguments.)
>>
>> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>>
> Your patch looks reasonable and safe.
> However, I find it surprising that it’s actually needed, as gfc_check
> mask is already the check function associated to maskl and maskr in the
> definition of the symbols. The simplification function should be called
> only when the associated check function has returned successfully, so it
> shouldn’t be necessary to call it again at simplification time.
> Looking at the backtrace, it is the do_simplify call at the beginning of
> gfc_intrinsic_func_interface that seems dubious to me, as it comes
> before all the check further down in the function and it looks redundant
> with the other simplification code after the checks.
>
> So I’m inclined to test whether by any chance removing that call works,
> and if it doesn’t, let’s go with this patch.
Did you find the time to try your version?
> Mikael
>
Thanks,
Harald
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
2022-01-06 19:50 ` Harald Anlauf
@ 2022-01-06 19:50 ` Harald Anlauf
2022-01-06 21:44 ` Mikael Morin
1 sibling, 0 replies; 7+ messages in thread
From: Harald Anlauf @ 2022-01-06 19:50 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches
Hi Mikael,
Am 21.12.21 um 13:38 schrieb Mikael Morin:
> Le 20/12/2021 à 23:05, Harald Anlauf via Fortran a écrit :
>> Dear all,
>>
>> we need to check the arguments of the elemental MASKL and MASKR
>> intrinsics also before simplifying.
>>
>> Testcase by Gerhard. The fix is almost obvious, but I'm happy to
>> get feedback in case there is something I overlooked. (There is
>> already a check on scalar arguments to MASKL/MASKR, which however
>> misses the case of array arguments.)
>>
>> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>>
> Your patch looks reasonable and safe.
> However, I find it surprising that it’s actually needed, as gfc_check
> mask is already the check function associated to maskl and maskr in the
> definition of the symbols. The simplification function should be called
> only when the associated check function has returned successfully, so it
> shouldn’t be necessary to call it again at simplification time.
> Looking at the backtrace, it is the do_simplify call at the beginning of
> gfc_intrinsic_func_interface that seems dubious to me, as it comes
> before all the check further down in the function and it looks redundant
> with the other simplification code after the checks.
>
> So I’m inclined to test whether by any chance removing that call works,
> and if it doesn’t, let’s go with this patch.
Did you find the time to try your version?
> Mikael
>
Thanks,
Harald
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
2022-01-06 19:50 ` Harald Anlauf
2022-01-06 19:50 ` Harald Anlauf
@ 2022-01-06 21:44 ` Mikael Morin
2022-01-09 20:12 ` Mikael Morin
1 sibling, 1 reply; 7+ messages in thread
From: Mikael Morin @ 2022-01-06 21:44 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Le 06/01/2022 à 20:50, Harald Anlauf a écrit :
>
> Did you find the time to try your version?
>
Not yet. But I have not (yet) forgotten about this.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
2022-01-06 21:44 ` Mikael Morin
@ 2022-01-09 20:12 ` Mikael Morin
2022-01-09 21:25 ` Harald Anlauf
0 siblings, 1 reply; 7+ messages in thread
From: Mikael Morin @ 2022-01-09 20:12 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Le 06/01/2022 à 22:44, Mikael Morin a écrit :
> Le 06/01/2022 à 20:50, Harald Anlauf a écrit :
>>
>> Did you find the time to try your version?
>>
> Not yet. But I have not (yet) forgotten about this.
> I have looked at it, and it enables infinite mutual recursion between
gfc_intrinsic_func_interface and gfc_simplify_expr, so it breaks heavily.
I am still looking at it, but let’s proceed with your original patch for
now.
Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
2022-01-09 20:12 ` Mikael Morin
@ 2022-01-09 21:25 ` Harald Anlauf
0 siblings, 0 replies; 7+ messages in thread
From: Harald Anlauf @ 2022-01-09 21:25 UTC (permalink / raw)
To: Mikael Morin, fortran, gcc-patches
Am 09.01.22 um 21:12 schrieb Mikael Morin:
> Le 06/01/2022 à 22:44, Mikael Morin a écrit :
>> Le 06/01/2022 à 20:50, Harald Anlauf a écrit :
>>>
>>> Did you find the time to try your version?
>>>
>> Not yet. But I have not (yet) forgotten about this.
>> I have looked at it, and it enables infinite mutual recursion between
> gfc_intrinsic_func_interface and gfc_simplify_expr, so it breaks heavily.
> I am still looking at it, but let’s proceed with your original patch for
> now.
OK, done so. It should not prevent a better solution later...
> Thanks.
>
Thanks,
Harald
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-01-09 21:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 22:05 [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918 Harald Anlauf
2021-12-21 12:38 ` Mikael Morin
2022-01-06 19:50 ` Harald Anlauf
2022-01-06 19:50 ` Harald Anlauf
2022-01-06 21:44 ` Mikael Morin
2022-01-09 20:12 ` Mikael Morin
2022-01-09 21:25 ` Harald Anlauf
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).