From 126036359a27ee32a433d0404d88557bb0d15687 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 16 Dec 2019 22:24:15 +0000 Subject: [PATCH] PR middle-end/92952 - gfortran.dg/lto/pr87689 FAILs at -O2 gcc/ChangeLog: * builtins.c (compute_objsize): Adjust offset by the array low bound. From-SVN: r279445 --- gcc/ChangeLog | 5 +++++ gcc/builtins.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d25666380cd..26dd71177e7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-12-16 Martin Sebor + + PR middle-end/92952 + * builtins.c (compute_objsize): Adjust offset by the array low bound. + 2019-12-16 David Malcolm * pretty-print.c (pp_write_text_as_html_like_dot_to_stream): New diff --git a/gcc/builtins.c b/gcc/builtins.c index 3e89f2a7f26..1297494ba0c 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3999,6 +3999,16 @@ compute_objsize (tree dest, int ostype, tree *pdecl /* = NULL */, above. */ if (TREE_CODE (dest) == ARRAY_REF) { + tree lowbnd = array_ref_low_bound (dest); + if (!integer_zerop (lowbnd) && tree_fits_uhwi_p (lowbnd)) + { + /* Adjust the offset by the low bound of the array + domain (normally zero but 1 in Fortran). */ + unsigned HOST_WIDE_INT lb = tree_to_uhwi (lowbnd); + offrng[0] -= lb; + offrng[1] -= lb; + } + /* Convert the array index into a byte offset. */ tree eltype = TREE_TYPE (dest); tree tpsize = TYPE_SIZE_UNIT (eltype); -- 2.30.2