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 r10-10269] Fortran: error recovery on rank mismatch of array and its initializer Date: Sat, 13 Nov 2021 20:15:10 +0000 (GMT) [thread overview] Message-ID: <20211113201510.CCD38385780A@sourceware.org> (raw) https://gcc.gnu.org/g:5625599e6f23622447418e6cbfcc080ecd0f2c28 commit r10-10269-g5625599e6f23622447418e6cbfcc080ecd0f2c28 Author: Harald Anlauf <anlauf@gmx.de> Date: Sat Nov 6 19:42:01 2021 +0100 Fortran: error recovery on rank mismatch of array and its initializer gcc/fortran/ChangeLog: PR fortran/102715 * decl.c (add_init_expr_to_sym): Reject rank mismatch between array and its initializer. gcc/testsuite/ChangeLog: PR fortran/102715 * gfortran.dg/pr68019.f90: Adjust error message. * gfortran.dg/pr102715.f90: New test. (cherry picked from commit df2135e88a8f78c853b35246ad426b01b6d08378) Diff: --- gcc/fortran/decl.c | 8 ++++++++ gcc/testsuite/gfortran.dg/pr102715.f90 | 13 +++++++++++++ gcc/testsuite/gfortran.dg/pr68019.f90 | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 1556fde7143..63fdba4fbfe 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2020,6 +2020,14 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) } } + if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension && sym->as + && sym->as->rank && init->rank && init->rank != sym->as->rank) + { + gfc_error ("Rank mismatch of array at %L and its initializer " + "(%d/%d)", &sym->declared_at, sym->as->rank, init->rank); + return false; + } + /* If sym is implied-shape, set its upper bounds from init. */ if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension && sym->as->type == AS_IMPLIED_SHAPE) diff --git a/gcc/testsuite/gfortran.dg/pr102715.f90 b/gcc/testsuite/gfortran.dg/pr102715.f90 new file mode 100644 index 00000000000..7b29a1c05a6 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102715.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! PR fortran/102715 - ICE in gfc_simplify_transpose + +program p + type t + end type + type(t), parameter :: a(4) = t() + type(t), parameter :: b(2,2) = reshape(a, [2]) ! { dg-error "Rank mismatch" } + type(t), parameter :: c(2,2) = transpose(b) ! { dg-error "must be of rank 2" } + type(t), parameter :: s2(*) = b(2,:) ! { dg-error "Syntax error" } + type(t), parameter :: x(*,*) = reshape(a, [2]) ! { dg-error "Rank mismatch" } + type(t), parameter :: s3(*) = x(2,:) ! { dg-error "Syntax error" } +end diff --git a/gcc/testsuite/gfortran.dg/pr68019.f90 b/gcc/testsuite/gfortran.dg/pr68019.f90 index 2e304c3a260..77fd55bd331 100644 --- a/gcc/testsuite/gfortran.dg/pr68019.f90 +++ b/gcc/testsuite/gfortran.dg/pr68019.f90 @@ -9,5 +9,5 @@ program p integer :: n end type type(t), parameter :: vec(*) = [(t(i), i = 1, 4)] - type(t), parameter :: arr(*) = reshape(vec, [2, 2]) ! { dg-error "ranks 1 and 2 in assignment" } + type(t), parameter :: arr(*) = reshape(vec, [2, 2]) ! { dg-error "Rank mismatch" } end
reply other threads:[~2021-11-13 20:15 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=20211113201510.CCD38385780A@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).