* [PATCH] PR fortran/102717 - ICE in gfc_simplify_reshape, at fortran/simplify.c:6843
@ 2021-10-13 19:23 Harald Anlauf
2021-10-14 5:59 ` Thomas Koenig
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-10-13 19:23 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 301 bytes --]
Dear Fortranners,
when simplifying RESHAPE we hit a gcc_assert for negative entries in the
SHAPE array. Obvious solution: replace gcc_assert by an error message.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
As this is a safe fix, I'd like to backport to suitable branches.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr102717.diff --]
[-- Type: text/x-patch, Size: 1408 bytes --]
Fortran: generate error message for negative elements in SHAPE array
gcc/fortran/ChangeLog:
PR fortran/102717
* simplify.c (gfc_simplify_reshape): Replace assert by error
message for negative elements in SHAPE array.
gcc/testsuite/ChangeLog:
PR fortran/102717
* gfortran.dg/reshape_shape_2.f90: New test.
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index f40e4930b58..d675f2c3aef 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6840,7 +6840,13 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
gfc_extract_int (e, &shape[rank]);
gcc_assert (rank >= 0 && rank < GFC_MAX_DIMENSIONS);
- gcc_assert (shape[rank] >= 0);
+ if (shape[rank] < 0)
+ {
+ gfc_error ("The SHAPE array for the RESHAPE intrinsic at %L has a "
+ "negative value %d for dimension %d",
+ &shape_exp->where, shape[rank], rank+1);
+ return &gfc_bad_expr;
+ }
rank++;
}
diff --git a/gcc/testsuite/gfortran.dg/reshape_shape_2.f90 b/gcc/testsuite/gfortran.dg/reshape_shape_2.f90
new file mode 100644
index 00000000000..8f1757687bc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/reshape_shape_2.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/102717
+
+program p
+ integer, parameter :: a(1) = 2
+ integer, parameter :: b(2) = reshape([3,4], -[a]) ! { dg-error "negative" }
+end
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PR fortran/102717 - ICE in gfc_simplify_reshape, at fortran/simplify.c:6843
2021-10-13 19:23 [PATCH] PR fortran/102717 - ICE in gfc_simplify_reshape, at fortran/simplify.c:6843 Harald Anlauf
@ 2021-10-14 5:59 ` Thomas Koenig
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2021-10-14 5:59 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
H Harald,
> when simplifying RESHAPE we hit a gcc_assert for negative entries in the
> SHAPE array. Obvious solution: replace gcc_assert by an error message.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
> As this is a safe fix, I'd like to backport to suitable branches.
OK for both.
Thanks for the patch!
Best regards
Thomas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-14 5:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 19:23 [PATCH] PR fortran/102717 - ICE in gfc_simplify_reshape, at fortran/simplify.c:6843 Harald Anlauf
2021-10-14 5:59 ` Thomas Koenig
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).