public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/102043] [9/10/11/12 Regression] Wrong array types used for negative stride accesses, gfortran.dg/vector_subscript_1.f90  FAILs
Date: Fri, 22 Apr 2022 20:53:41 +0000	[thread overview]
Message-ID: <bug-102043-4-fyRRnEBbUr@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102043-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102043

--- Comment #47 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

https://gcc.gnu.org/g:7964ab6c364c410c34efe7ca2eba797d36525349

commit r12-8230-g7964ab6c364c410c34efe7ca2eba797d36525349
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Fri Apr 22 22:52:50 2022 +0200

    fortran: Use pointer arithmetic to index arrays [PR102043]

    The code generated for array references used to be ARRAY_REF trees as
    could be expected.  However, the middle-end may conclude from those
    trees that the indexes used are non-negative (more precisely not below
    the lower bound), which is a wrong assumption in the case of "reversed-
    order" arrays.

    The problematic arrays are those with a descriptor and having a negative
    stride for at least one dimension.  The descriptor data points to the
    first element in array order (which is not the first in memory order in
    that case), and the negative stride(s) makes walking the array backwards
    (towards lower memory addresses), and we can access elements with
    negative index wrt data pointer.

    With this change, pointer arithmetic is generated by default for array
    references, unless we are in a case where negative indexes canât happen
    (array descriptorâs dim element, substrings, explicit shape,
    allocatable, or assumed shape contiguous).  A new flag is added to
    choose between array indexing and pointer arithmetic, and itâs set
    if the context can tell array indexing is safe (descriptor dim
    element, substring, temporary array), or a new method is called
    to decide on whether the flag should be set for one given array
    expression.

            PR fortran/102043

    gcc/fortran/ChangeLog:

            * trans.h (gfc_build_array_ref): Add non_negative_offset
            argument.
            * trans.cc (gfc_build_array_ref): Ditto. Use pointer arithmetic
            if non_negative_offset is false.
            * trans-expr.cc (gfc_conv_substring): Set flag in the call to
            gfc_build_array_ref.
            * trans-array.cc (gfc_get_cfi_dim_item,
            gfc_conv_descriptor_dimension): Same.
            (build_array_ref): Decide on whether to set the flag and update
            the call.
            (gfc_conv_scalarized_array_ref): Same.  New argument tmp_array.
            (gfc_conv_tmp_array_ref): Update call to
            gfc_conv_scalarized_ref.
            (non_negative_strides_array_p): New function.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/array_reference_3.f90: New.
            * gfortran.dg/negative_stride_1.f90: New.
            * gfortran.dg/vector_subscript_8.f90: New.
            * gfortran.dg/vector_subscript_9.f90: New.
            * gfortran.dg/c_loc_test_22.f90: Update dump patterns.
            * gfortran.dg/finalize_10.f90: Same.

    Co-Authored-By: Richard Biener <rguenther@suse.de>

  parent reply	other threads:[~2022-04-22 20:53 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 14:18 [Bug fortran/102043] New: Wrong array types used for negative stride accesses rguenth at gcc dot gnu.org
2021-08-25  8:42 ` [Bug fortran/102043] " rguenth at gcc dot gnu.org
2021-08-25  9:16 ` rguenth at gcc dot gnu.org
2021-08-25 10:05 ` ebotcazou at gcc dot gnu.org
2021-08-25 10:07 ` rguenth at gcc dot gnu.org
2021-08-25 10:20 ` rguenth at gcc dot gnu.org
2021-09-30 19:56 ` anlauf at gcc dot gnu.org
2021-11-08 21:23 ` hubicka at gcc dot gnu.org
2021-11-10 16:31 ` mikael at gcc dot gnu.org
2021-11-10 17:12 ` aldot at gcc dot gnu.org
2021-11-11  8:00 ` rguenth at gcc dot gnu.org
2021-11-12 18:14 ` tkoenig at gcc dot gnu.org
2021-11-12 19:30 ` mikael at gcc dot gnu.org
2021-11-14  7:57 ` tkoenig at gcc dot gnu.org
2021-11-14  9:33 ` mikael at gcc dot gnu.org
2021-11-14  9:38 ` tkoenig at gcc dot gnu.org
2021-11-14 16:07 ` aldot at gcc dot gnu.org
2021-11-14 16:18 ` aldot at gcc dot gnu.org
2021-11-14 17:00 ` mikael at gcc dot gnu.org
2021-11-14 17:13 ` mikael at gcc dot gnu.org
2021-11-14 19:42 ` tkoenig at gcc dot gnu.org
2021-11-15 10:47 ` rguenth at gcc dot gnu.org
2021-11-19 18:21 ` mikael at gcc dot gnu.org
2021-11-19 18:31 ` mikael at gcc dot gnu.org
2021-11-22  7:46 ` rguenther at suse dot de
2021-11-22 22:33 ` hubicka at gcc dot gnu.org
2021-11-27 21:43 ` mikael at gcc dot gnu.org
2021-12-11 17:47 ` mikael at gcc dot gnu.org
2021-12-11 17:53 ` mikael at gcc dot gnu.org
2021-12-12 17:04 ` mikael at gcc dot gnu.org
2021-12-12 21:26 ` mikael at gcc dot gnu.org
2022-01-03  9:09 ` rguenth at gcc dot gnu.org
2022-01-03  9:12 ` rguenth at gcc dot gnu.org
2022-03-24  9:39 ` [Bug fortran/102043] [9/10/11/12 Regression] Wrong array types used for negative stride accesses, gfortran.dg/vector_subscript_1.f90 FAILs rguenth at gcc dot gnu.org
2022-03-24 16:40 ` tschwinge at gcc dot gnu.org
2022-03-27 19:36 ` mikael at gcc dot gnu.org
2022-03-28  6:36 ` rguenther at suse dot de
2022-03-28 12:16 ` rguenth at gcc dot gnu.org
2022-03-28 12:24 ` burnus at gcc dot gnu.org
2022-03-30  6:45 ` tkoenig at gcc dot gnu.org
2022-03-30  6:48 ` rguenther at suse dot de
2022-03-30  9:07 ` rguenth at gcc dot gnu.org
2022-03-30 11:22 ` rguenth at gcc dot gnu.org
2022-04-05 10:21 ` mikael at gcc dot gnu.org
2022-04-22 20:53 ` cvs-commit at gcc dot gnu.org
2022-04-22 20:53 ` cvs-commit at gcc dot gnu.org
2022-04-22 20:53 ` cvs-commit at gcc dot gnu.org
2022-04-22 20:53 ` cvs-commit at gcc dot gnu.org [this message]
2022-04-25  6:07 ` [Bug fortran/102043] [9/10/11 " rguenth at gcc dot gnu.org
2022-04-27  9:36 ` cvs-commit at gcc dot gnu.org
2022-05-27  9:46 ` [Bug fortran/102043] [10/11 " rguenth at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2022-08-28 10:36 ` mikael at gcc dot gnu.org
2022-08-28 10:37 ` mikael at gcc dot gnu.org
2023-07-07 10:40 ` [Bug fortran/102043] [11 " rguenth at gcc dot gnu.org

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=bug-102043-4-fyRRnEBbUr@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: link
Be 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).