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 r13-4486] Fortran: error recovery simplifying UNPACK for insufficient FIELD [PR107922] Date: Sun, 4 Dec 2022 20:00:26 +0000 (GMT) [thread overview] Message-ID: <20221204200026.3D59538432DE@sourceware.org> (raw) https://gcc.gnu.org/g:24b9337d1f1b5197b6498dceb9074319be003449 commit r13-4486-g24b9337d1f1b5197b6498dceb9074319be003449 Author: Harald Anlauf <anlauf@gmx.de> Date: Thu Dec 1 21:16:46 2022 +0100 Fortran: error recovery simplifying UNPACK for insufficient FIELD [PR107922] gcc/fortran/ChangeLog: PR fortran/107922 * simplify.cc (gfc_simplify_unpack): Terminate simplification when array-valued argument FIELD does not provide enough elements. gcc/testsuite/ChangeLog: PR fortran/107922 * gfortran.dg/unpack_field_1.f90: New test. Diff: --- gcc/fortran/simplify.cc | 11 ++++++++++- gcc/testsuite/gfortran.dg/unpack_field_1.f90 | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index b6184181f26..aff9a1b8ced 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -8485,7 +8485,16 @@ gfc_simplify_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field) } } else if (field->expr_type == EXPR_ARRAY) - e = gfc_copy_expr (field_ctor->expr); + { + if (field_ctor) + e = gfc_copy_expr (field_ctor->expr); + else + { + /* Not enough elements in array FIELD. */ + gfc_free_expr (result); + return &gfc_bad_expr; + } + } else e = gfc_copy_expr (field); diff --git a/gcc/testsuite/gfortran.dg/unpack_field_1.f90 b/gcc/testsuite/gfortran.dg/unpack_field_1.f90 new file mode 100644 index 00000000000..ca3cfbd2bd4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unpack_field_1.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! PR fortran/107922 - ICE in gfc_simplify_unpack +! Test error recovery when shapes of FIELD and MASK do not match +! Contributed by G.Steinmetz + +program p + integer, parameter :: a(2) = 1 + integer, parameter :: d(3) = 1 + logical, parameter :: mask(3) = [.false.,.true.,.false.] + integer, parameter :: b(2) = unpack(a,mask,a) ! { dg-error "must have identical shape" } + integer :: c(3) = unpack(a,[.false.,.true.,.false.],a) ! { dg-error "must have identical shape" } + print *, unpack(a,mask,a) ! { dg-error "must have identical shape" } + print *, unpack(a,mask,d) ! OK + print *, unpack(a,mask,3) ! OK +end
reply other threads:[~2022-12-04 20:00 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=20221204200026.3D59538432DE@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).