public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99027] New: Incorrect ubound result
@ 2021-02-09 15:30 andrew.burgess at embecosm dot com
  2021-02-13 11:59 ` [Bug fortran/99027] " dominiq at lps dot ens.fr
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: andrew.burgess at embecosm dot com @ 2021-02-09 15:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99027
           Summary: Incorrect ubound result
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrew.burgess at embecosm dot com
  Target Milestone: ---

I believe I have run into a case where ubound is giving the wrong result.

Given:

  program test
    integer, dimension (1:3,1:6) :: array
    print *, "ubound = ", ubound (array (1, 1:4))
  end program test

I see the output:

  ubound =            1

When I would have expected:

  ubound =            4

Due to array (1, 1:4) being a 4 element 1-dimensional array.

I am seeing this behaviour in my default Fedora compiler:

  GNU Fortran (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)

But I also build current HEAD from git (26a3f288f18) and am still seeing this
issue:

  GNU Fortran (GCC) 11.0.0 20210209 (experimental)

Interestingly, if I change the test program to:

  program test
    integer, dimension (1:3,1:6) :: array
    print *, "ubound = ", ubound (array (1:2, 1:4))
  end program test

Then I do now see what I would expect for this case:

  ubound =            2           4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/99027] Incorrect ubound result
  2021-02-09 15:30 [Bug fortran/99027] New: Incorrect ubound result andrew.burgess at embecosm dot com
@ 2021-02-13 11:59 ` dominiq at lps dot ens.fr
  2021-02-13 19:42 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-02-13 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-02-13
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed since at least GCC7.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/99027] Incorrect ubound result
  2021-02-09 15:30 [Bug fortran/99027] New: Incorrect ubound result andrew.burgess at embecosm dot com
  2021-02-13 11:59 ` [Bug fortran/99027] " dominiq at lps dot ens.fr
@ 2021-02-13 19:42 ` burnus at gcc dot gnu.org
  2021-02-19  9:42 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-02-13 19:42 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Untested patch:

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 23317a2e2d9..6a180ff40f2 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -4170,3 +4170,13 @@ simplify_bound_dim (gfc_expr *array, gfc_expr *kind, int
d, int upper,
        {
-         if (!gfc_ref_dimen_size (&ref->u.ar, d - 1, &result->value.integer,
NULL))
+         int d2 = 0, cnt = 0;
+         for (int idx = 0; idx < ref->u.ar.dimen; ++idx)
+           {
+             if (ref->u.ar.dimen_type == DIMEN_ELEMENT)
+               d2++;
+             else if (cnt < d - 1)
+               cnt++;
+             else
+               break;
+           }
+         if (!gfc_ref_dimen_size (&ref->u.ar, d2 + d - 1,
&result->value.integer, NULL))
            goto returnNull;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/99027] Incorrect ubound result
  2021-02-09 15:30 [Bug fortran/99027] New: Incorrect ubound result andrew.burgess at embecosm dot com
  2021-02-13 11:59 ` [Bug fortran/99027] " dominiq at lps dot ens.fr
  2021-02-13 19:42 ` burnus at gcc dot gnu.org
@ 2021-02-19  9:42 ` cvs-commit at gcc dot gnu.org
  2021-02-20 20:04 ` andrew.burgess at embecosm dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-19  9:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:f600f271b10d0214b111f2aa52a3d5740477e139

commit r11-7292-gf600f271b10d0214b111f2aa52a3d5740477e139
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Fri Feb 19 10:42:15 2021 +0100

    Fortran: Fix ubound simplifcation [PR99027]

    gcc/fortran/ChangeLog:

            PR fortran/99027
            * simplify.c (simplify_bound_dim): Honor DIMEN_ELEMENT
            when using dim=.

    gcc/testsuite/ChangeLog:

            PR fortran/99027
            * gfortran.dg/ubound_1.f90: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/99027] Incorrect ubound result
  2021-02-09 15:30 [Bug fortran/99027] New: Incorrect ubound result andrew.burgess at embecosm dot com
                   ` (2 preceding siblings ...)
  2021-02-19  9:42 ` cvs-commit at gcc dot gnu.org
@ 2021-02-20 20:04 ` andrew.burgess at embecosm dot com
  2021-02-22 10:31 ` cvs-commit at gcc dot gnu.org
  2021-02-22 10:48 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: andrew.burgess at embecosm dot com @ 2021-02-20 20:04 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Burgess <andrew.burgess at embecosm dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from Andrew Burgess <andrew.burgess at embecosm dot com> ---
Can confirm that with latest GCC HEAD I am now seeing the results that I
expect.  Thanks for the quick fix.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/99027] Incorrect ubound result
  2021-02-09 15:30 [Bug fortran/99027] New: Incorrect ubound result andrew.burgess at embecosm dot com
                   ` (3 preceding siblings ...)
  2021-02-20 20:04 ` andrew.burgess at embecosm dot com
@ 2021-02-22 10:31 ` cvs-commit at gcc dot gnu.org
  2021-02-22 10:48 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-22 10:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Tobias Burnus
<burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:700dcc60b5646cc64ae3ba72a79a7542b4902b50

commit r10-9380-g700dcc60b5646cc64ae3ba72a79a7542b4902b50
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Fri Feb 19 10:42:15 2021 +0100

    Fortran: Fix ubound simplifcation [PR99027]

    gcc/fortran/ChangeLog:

            PR fortran/99027
            * simplify.c (simplify_bound_dim): Honor DIMEN_ELEMENT
            when using dim=.

    gcc/testsuite/ChangeLog:

            PR fortran/99027
            * gfortran.dg/ubound_1.f90: New test.

    (cherry picked from commit f600f271b10d0214b111f2aa52a3d5740477e139)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/99027] Incorrect ubound result
  2021-02-09 15:30 [Bug fortran/99027] New: Incorrect ubound result andrew.burgess at embecosm dot com
                   ` (4 preceding siblings ...)
  2021-02-22 10:31 ` cvs-commit at gcc dot gnu.org
@ 2021-02-22 10:48 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-02-22 10:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Now also FIXED for the GCC 10 branch.

(In reply to Andrew Burgess from comment #4)
> Can confirm that with latest GCC HEAD I am now seeing the results that I
> expect.  Thanks for the quick fix.

:-) You are welcome. Thanks for the report!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-22 10:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 15:30 [Bug fortran/99027] New: Incorrect ubound result andrew.burgess at embecosm dot com
2021-02-13 11:59 ` [Bug fortran/99027] " dominiq at lps dot ens.fr
2021-02-13 19:42 ` burnus at gcc dot gnu.org
2021-02-19  9:42 ` cvs-commit at gcc dot gnu.org
2021-02-20 20:04 ` andrew.burgess at embecosm dot com
2021-02-22 10:31 ` cvs-commit at gcc dot gnu.org
2021-02-22 10:48 ` burnus at gcc dot gnu.org

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).