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 r12-5480] Fortran: do not attempt simplification of [LU]BOUND for pointer/allocatable Date: Tue, 23 Nov 2021 21:02:51 +0000 (GMT) [thread overview] Message-ID: <20211123210251.9DB3D3858C2C@sourceware.org> (raw) https://gcc.gnu.org/g:16e95050f71e9fa408e9bd8ccd415b0e7adc66e5 commit r12-5480-g16e95050f71e9fa408e9bd8ccd415b0e7adc66e5 Author: Harald Anlauf <anlauf@gmx.de> Date: Tue Nov 23 21:39:36 2021 +0100 Fortran: do not attempt simplification of [LU]BOUND for pointer/allocatable gcc/fortran/ChangeLog: PR fortran/103392 * simplify.c (simplify_bound): Do not try to simplify LBOUND/UBOUND for arrays with POINTER or ALLOCATABLE attribute. gcc/testsuite/ChangeLog: PR fortran/103392 * gfortran.dg/bound_simplification_7.f90: New test. Diff: --- gcc/fortran/simplify.c | 6 ++++++ gcc/testsuite/gfortran.dg/bound_simplification_7.f90 | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 6a6b3fbd037..c9e13b59da9 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4266,6 +4266,12 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) || (as->type == AS_ASSUMED_SHAPE && upper))) return NULL; + /* 'array' shall not be an unallocated allocatable variable or a pointer that + is not associated. */ + if (array->expr_type == EXPR_VARIABLE + && (gfc_expr_attr (array).allocatable || gfc_expr_attr (array).pointer)) + return NULL; + gcc_assert (!as || (as->type != AS_DEFERRED && array->expr_type == EXPR_VARIABLE diff --git a/gcc/testsuite/gfortran.dg/bound_simplification_7.f90 b/gcc/testsuite/gfortran.dg/bound_simplification_7.f90 new file mode 100644 index 00000000000..3efecdff769 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bound_simplification_7.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! PR fortran/103392 - ICE in simplify_bound + +program p + integer, allocatable :: a(1:1) ! { dg-error "deferred shape or assumed rank" } + integer :: b(1) = lbound(a) ! { dg-error "does not reduce" } + integer :: c(1) = ubound(a) ! { dg-error "does not reduce" } +end + +subroutine s(x, y) + type t + integer :: i(3) + end type t + type(t), pointer :: x(:) + type(t), allocatable :: y(:) + integer, parameter :: m(1) = ubound (x(1)% i) + integer :: n(1) = ubound (y(1)% i) +end subroutine s
reply other threads:[~2021-11-23 21:02 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=20211123210251.9DB3D3858C2C@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).