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-10878] Fortran: handle explicit-shape specs with constant bounds [PR105954] Date: Fri, 1 Jul 2022 18:14:35 +0000 (GMT) [thread overview] Message-ID: <20220701181435.290CA385782C@sourceware.org> (raw) https://gcc.gnu.org/g:bac42273343bb9a198704900e2118ed4e84cb23a commit r10-10878-gbac42273343bb9a198704900e2118ed4e84cb23a Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Jun 20 20:59:55 2022 +0200 Fortran: handle explicit-shape specs with constant bounds [PR105954] gcc/fortran/ChangeLog: PR fortran/105954 * decl.c (variable_decl): Adjust upper bounds for explicit-shape specs with constant bound expressions to ensure non-negative extents. gcc/testsuite/ChangeLog: PR fortran/105954 * gfortran.dg/pr105954.f90: New test. (cherry picked from commit a312407bd715647f7c11b67e0a52effc94d0f15d) Diff: --- gcc/fortran/decl.c | 12 ++++++++++++ gcc/testsuite/gfortran.dg/pr105954.f90 | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 2ad9fb63399..a007bb15333 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2685,6 +2685,18 @@ variable_decl (int elem) else gfc_free_expr (n); } + /* For an explicit-shape spec with constant bounds, ensure + that the effective upper bound is not lower than the + respective lower bound minus one. Otherwise adjust it so + that the extent is trivially derived to be zero. */ + if (as->lower[i]->expr_type == EXPR_CONSTANT + && as->upper[i]->expr_type == EXPR_CONSTANT + && as->lower[i]->ts.type == BT_INTEGER + && as->upper[i]->ts.type == BT_INTEGER + && mpz_cmp (as->upper[i]->value.integer, + as->lower[i]->value.integer) < 0) + mpz_sub_ui (as->upper[i]->value.integer, + as->lower[i]->value.integer, 1); } } } diff --git a/gcc/testsuite/gfortran.dg/pr105954.f90 b/gcc/testsuite/gfortran.dg/pr105954.f90 new file mode 100644 index 00000000000..89004bf9aa7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr105954.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! PR fortran/105954 - ICE in gfc_element_size, at fortran/target-memory.cc:132 +! Contributed by G.Steinmetz + +program p + use iso_c_binding, only: c_float, c_sizeof + implicit none + integer, parameter :: n = -99 + type t + real :: b(3,7:n) + end type + type, bind(c) :: u + real(c_float) :: b(3,7:n) + end type + type(t) :: d + type(u) :: e + integer, parameter :: k = storage_size(d) + integer, parameter :: m = sizeof(d) + integer, parameter :: l = c_sizeof(e) + if (k /= 0) stop 1 + if (m /= 0) stop 2 + if (l /= 0) stop 3 +end + +! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } }
reply other threads:[~2022-07-01 18:14 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=20220701181435.290CA385782C@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).