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-9217] Fortran: error recovery on initializing invalid derived type array component Date: Sun, 7 Nov 2021 20:54:58 +0000 (GMT) [thread overview] Message-ID: <20211107205458.0EE8E385843D@sourceware.org> (raw) https://gcc.gnu.org/g:3371e7f18df52867b0b88966bd98d3f1eff6f815 commit r11-9217-g3371e7f18df52867b0b88966bd98d3f1eff6f815 Author: Harald Anlauf <anlauf@gmx.de> Date: Tue Oct 26 20:51:46 2021 +0200 Fortran: error recovery on initializing invalid derived type array component gcc/fortran/ChangeLog: PR fortran/102816 * resolve.c (resolve_structure_cons): Reject invalid array spec of a DT component referenced in a structure constructor. gcc/testsuite/ChangeLog: PR fortran/102816 * gfortran.dg/pr102816.f90: New test. (cherry picked from commit 99af0b2f0fe1c0dc8c6d558157e700326d52816a) Diff: --- gcc/fortran/resolve.c | 11 +++++++++-- gcc/testsuite/gfortran.dg/pr102816.f90 | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 277af0e61b0..bf7902742e2 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -1463,8 +1463,15 @@ resolve_structure_cons (gfc_expr *expr, int init) mpz_init (len); for (int n = 0; n < rank; n++) { - gcc_assert (comp->as->upper[n]->expr_type == EXPR_CONSTANT - && comp->as->lower[n]->expr_type == EXPR_CONSTANT); + if (comp->as->upper[n]->expr_type != EXPR_CONSTANT + || comp->as->lower[n]->expr_type != EXPR_CONSTANT) + { + gfc_error ("Bad array spec of component %qs referenced in " + "structure constructor at %L", + comp->name, &cons->expr->where); + t = false; + break; + }; mpz_set_ui (len, 1); mpz_add (len, len, comp->as->upper[n]->value.integer); mpz_sub (len, len, comp->as->lower[n]->value.integer); diff --git a/gcc/testsuite/gfortran.dg/pr102816.f90 b/gcc/testsuite/gfortran.dg/pr102816.f90 new file mode 100644 index 00000000000..46831743b2b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102816.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/102816 + +program p + type t + integer :: a([2]) ! { dg-error "must be scalar" } + end type + type(t) :: x = t([3, 4]) ! { dg-error "Bad array spec of component" } +end
reply other threads:[~2021-11-07 20:54 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=20211107205458.0EE8E385843D@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).