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-9213] Fortran: handle initialization of derived type parameter arrays from scalar Date: Sun, 7 Nov 2021 20:54:37 +0000 (GMT) [thread overview] Message-ID: <20211107205437.209A63858403@sourceware.org> (raw) https://gcc.gnu.org/g:1b740d8000cac8048c728fb0bd75c71464eeee29 commit r11-9213-g1b740d8000cac8048c728fb0bd75c71464eeee29 Author: Harald Anlauf <anlauf@gmx.de> Date: Sun Oct 10 20:11:43 2021 +0200 Fortran: handle initialization of derived type parameter arrays from scalar gcc/fortran/ChangeLog: PR fortran/99348 PR fortran/102521 * decl.c (add_init_expr_to_sym): Extend initialization of parameter arrays from scalars to handle derived types. gcc/testsuite/ChangeLog: PR fortran/99348 PR fortran/102521 * gfortran.dg/parameter_array_init_8.f90: New test. (cherry picked from commit 74ccca380cde5e79e082d39214b306a90ded0344) Diff: --- gcc/fortran/decl.c | 10 ++++++--- .../gfortran.dg/parameter_array_init_8.f90 | 25 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 4606155f699..982e3e9d9ac 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2126,12 +2126,16 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) gfc_expr *array; int n; if (sym->attr.flavor == FL_PARAMETER - && init->expr_type == EXPR_CONSTANT - && spec_size (sym->as, &size) - && mpz_cmp_si (size, 0) > 0) + && gfc_is_constant_expr (init) + && (init->expr_type == EXPR_CONSTANT + || init->expr_type == EXPR_STRUCTURE) + && spec_size (sym->as, &size) + && mpz_cmp_si (size, 0) > 0) { array = gfc_get_array_expr (init->ts.type, init->ts.kind, &init->where); + if (init->ts.type == BT_DERIVED) + array->ts.u.derived = init->ts.u.derived; for (n = 0; n < (int)mpz_get_si (size); n++) gfc_constructor_append_expr (&array->value.constructor, n == 0 diff --git a/gcc/testsuite/gfortran.dg/parameter_array_init_8.f90 b/gcc/testsuite/gfortran.dg/parameter_array_init_8.f90 new file mode 100644 index 00000000000..2e5f7694d3a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/parameter_array_init_8.f90 @@ -0,0 +1,25 @@ +! { dg-do run } +! PR fortran/99348 +! PR fortran/102521 +! Check simplifications for initialization of DT parameter arrays + +program p + type t + integer :: n + end type + type(t), parameter :: a(4) = t(1) + type(t), parameter :: d(*) = a + type(t), parameter :: b(2,2) = reshape(d, [2,2]) + integer, parameter :: nn = b(2,2)% n + type u + character(3) :: c + end type + type(u), parameter :: x(2,3) = u('ab') + type(u), parameter :: y(*,*) = transpose (x) + character(*), parameter :: c = y(3,2)% c + integer, parameter :: lc = c% len + integer, parameter :: lyc = len (y(3,2)% c) +! integer, parameter :: lxc = x(1,1)% c% len ! fails (pr101735?) + if (nn /= 1) stop 1 + if (lc /= 3 .or. lyc /= 3 .or. c /= "ab ") stop 2 +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=20211107205437.209A63858403@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).