public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9358] Fortran: generate error message for negative elements in SHAPE array Date: Sat, 4 Dec 2021 22:06:49 +0000 (GMT) [thread overview] Message-ID: <20211204220649.6665C3858D39@sourceware.org> (raw) https://gcc.gnu.org/g:6fa3c73e88ccbb6fffb4169bcab830fc3f4f3c9a commit r11-9358-g6fa3c73e88ccbb6fffb4169bcab830fc3f4f3c9a Author: Harald Anlauf <anlauf@gmx.de> Date: Thu Oct 14 20:19:50 2021 +0200 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. (cherry picked from commit b47490c572c5938f887b54240af6096a7c90f640) Diff: --- gcc/fortran/simplify.c | 8 +++++++- gcc/testsuite/gfortran.dg/reshape_shape_2.f90 | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 77b982005fc..fb7b7814603 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -6852,7 +6852,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
reply other threads:[~2021-12-04 22:06 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20211204220649.6665C3858D39@sourceware.org \ --to=anlauf@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).