public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg
@ 2020-10-02 14:03 longb at cray dot com
2020-10-02 19:44 ` [Bug fortran/97272] " anlauf at gcc dot gnu.org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: longb at cray dot com @ 2020-10-02 14:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
Bug ID: 97272
Summary: Wrong answer from MAXLOC with character arg
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: longb at cray dot com
Target Milestone: ---
Test case:
> cat test.f90
program test
character, allocatable :: a(:)
integer(8) l, i
l = 2000000_8
allocate (a(l))
do i = 1, l
a(i) = 'a'
end do
l = l - 1
a(l) = 'b'
i = maxloc (a, dim=1, kind=8)
print *, 'i = ', i, 'a(i) = ', a(i)
end
Expected behavior (Cray):
> ftn test.f90
> ./a.out
i = 1999999 a(i) = b
Incorrect result (gfortran):
> module swap PrgEnv-cray PrgEnv-gnu
> gfortran test.f90
> ./a.out
i = 2000000 a(i) = a
> gfortran --version
GNU Fortran (GCC) 10.1.0 20200507 (Cray Inc.)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
@ 2020-10-02 19:44 ` anlauf at gcc dot gnu.org
2020-10-02 20:02 ` anlauf at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-02 19:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-10-02
Keywords| |wrong-code
CC| |anlauf at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed for the case where the kind argument is present:
i = maxloc (a, dim=1, kind=8)
or
i = maxloc (a, dim=1, kind=4)
The issue does not occur when the kind argument is not present:
i = maxloc (a, dim=1)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
2020-10-02 19:44 ` [Bug fortran/97272] " anlauf at gcc dot gnu.org
@ 2020-10-02 20:02 ` anlauf at gcc dot gnu.org
2020-10-02 20:32 ` anlauf at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-02 20:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #2 from anlauf at gcc dot gnu.org ---
Untested fix:
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 3b3bd8629cd..9e9898c2bbf 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -5211,7 +5211,9 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr *
expr, enum tree_code op)
while (a->next)
{
b = a->next;
- if (b->expr == NULL || strcmp (b->name, "dim") == 0)
+ if (b->expr == NULL
+ || strcmp (b->name, "dim") == 0
+ || strcmp (b->name, "kind") == 0)
{
a->next = b->next;
b->next = NULL;
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
2020-10-02 19:44 ` [Bug fortran/97272] " anlauf at gcc dot gnu.org
2020-10-02 20:02 ` anlauf at gcc dot gnu.org
@ 2020-10-02 20:32 ` anlauf at gcc dot gnu.org
2020-10-04 18:24 ` cvs-commit at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-02 20:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #3 from anlauf at gcc dot gnu.org ---
Patch: https://gcc.gnu.org/pipermail/fortran/2020-October/055143.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (2 preceding siblings ...)
2020-10-02 20:32 ` anlauf at gcc dot gnu.org
@ 2020-10-04 18:24 ` cvs-commit at gcc dot gnu.org
2020-10-04 21:53 ` longb at cray dot com
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-04 18:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:35d2c6b6e8a7448a84abbf967feeb78a29117014
commit r11-3646-g35d2c6b6e8a7448a84abbf967feeb78a29117014
Author: Harald Anlauf <anlauf@gmx.de>
Date: Sun Oct 4 20:24:29 2020 +0200
PR fortran/97272 - Wrong answer from MAXLOC with character arg
The optional KIND argument to the MINLOC/MAXLOC intrinsic must not be
passed to the library function, as the kind conversion of the result
is treated explicitly elsewhere.
gcc/fortran/ChangeLog:
PR fortran/97272
* trans-intrinsic.c (strip_kind_from_actual): Helper function for
removal of KIND argument.
(gfc_conv_intrinsic_minmaxloc): Ignore KIND argument here, as it
is treated elsewhere.
gcc/testsuite/ChangeLog:
PR fortran/97272
* gfortran.dg/pr97272.f90: New test.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (3 preceding siblings ...)
2020-10-04 18:24 ` cvs-commit at gcc dot gnu.org
@ 2020-10-04 21:53 ` longb at cray dot com
2020-10-05 7:16 ` anlauf at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: longb at cray dot com @ 2020-10-04 21:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #5 from Bill Long <longb at cray dot com> ---
The original intent of adding the KIND argument was because some
implementations used a 32-bit integer for the result, and it is possible for
the answer to be larger than 2**31-1. Just checking to be sure that the
underlying library code returns a 64-bit integer that can later be converted
based on the KIND value.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (4 preceding siblings ...)
2020-10-04 21:53 ` longb at cray dot com
@ 2020-10-05 7:16 ` anlauf at gcc dot gnu.org
2020-10-08 16:55 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-05 7:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #6 from anlauf at gcc dot gnu.org ---
(In reply to Bill Long from comment #5)
> The original intent of adding the KIND argument was because some
> implementations used a 32-bit integer for the result, and it is possible for
> the answer to be larger than 2**31-1. Just checking to be sure that the
> underlying library code returns a 64-bit integer that can later be converted
> based on the KIND value.
Did you try? It's not exactly fast, but
program test
implicit none
integer(8) :: k, l = 10 + 2_8**32
character, allocatable :: a(:)
allocate (a(l))
print *, l
a(:) = 'a'
l = l - 1
a(l) = 'b'
print *, l
print *, size (a, kind=8)
k = maxloc (a, dim=1, kind=8, back=.true.)
print *, 'k = ', k, 'a(k) = ', a(k)
end
works for me on master now on a 64-bit platform:
4294967306
4294967305
4294967306
k = 4294967305 a(k) = b
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (5 preceding siblings ...)
2020-10-05 7:16 ` anlauf at gcc dot gnu.org
@ 2020-10-08 16:55 ` cvs-commit at gcc dot gnu.org
2020-10-08 20:29 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-08 16:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:d4ec0a15afb7538247206aa9936071544fd860f8
commit r10-8870-gd4ec0a15afb7538247206aa9936071544fd860f8
Author: Harald Anlauf <anlauf@gmx.de>
Date: Sun Oct 4 20:24:29 2020 +0200
PR fortran/97272 - Wrong answer from MAXLOC with character arg
The optional KIND argument to the MINLOC/MAXLOC intrinsic must not be
passed to the library function, as the kind conversion of the result
is treated explicitly elsewhere.
gcc/fortran/ChangeLog:
PR fortran/97272
* trans-intrinsic.c (strip_kind_from_actual): Helper function for
removal of KIND argument.
(gfc_conv_intrinsic_minmaxloc): Ignore KIND argument here, as it
is treated elsewhere.
gcc/testsuite/ChangeLog:
PR fortran/97272
* gfortran.dg/pr97272.f90: New test.
(cherry picked from commit 35d2c6b6e8a7448a84abbf967feeb78a29117014)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (6 preceding siblings ...)
2020-10-08 16:55 ` cvs-commit at gcc dot gnu.org
@ 2020-10-08 20:29 ` cvs-commit at gcc dot gnu.org
2020-10-08 21:00 ` anlauf at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-08 20:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:83967508034454425dfce7fe0ea33a153c34e7cb
commit r9-8985-g83967508034454425dfce7fe0ea33a153c34e7cb
Author: Harald Anlauf <anlauf@gmx.de>
Date: Sun Oct 4 20:24:29 2020 +0200
PR fortran/97272 - Wrong answer from MAXLOC with character arg
The optional KIND argument to the MINLOC/MAXLOC intrinsic must not be
passed to the library function, as the kind conversion of the result
is treated explicitly elsewhere.
gcc/fortran/ChangeLog:
PR fortran/97272
* trans-intrinsic.c (strip_kind_from_actual): Helper function for
removal of KIND argument.
(gfc_conv_intrinsic_minmaxloc): Ignore KIND argument here, as it
is treated elsewhere.
gcc/testsuite/ChangeLog:
PR fortran/97272
* gfortran.dg/pr97272.f90: New test.
(cherry picked from commit 35d2c6b6e8a7448a84abbf967feeb78a29117014)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (7 preceding siblings ...)
2020-10-08 20:29 ` cvs-commit at gcc dot gnu.org
@ 2020-10-08 21:00 ` anlauf at gcc dot gnu.org
2021-01-22 21:08 ` longb at cray dot com
2021-01-22 21:24 ` anlauf at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-08 21:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #9 from anlauf at gcc dot gnu.org ---
Fixed on master for gcc-11, and on 10- and 9-branch.
Not applied to 8-branch, which did not support the back argument,
so not considered worth it.
Thanks for the report!
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (8 preceding siblings ...)
2020-10-08 21:00 ` anlauf at gcc dot gnu.org
@ 2021-01-22 21:08 ` longb at cray dot com
2021-01-22 21:24 ` anlauf at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: longb at cray dot com @ 2021-01-22 21:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #10 from Bill Long <longb at cray dot com> ---
Still fails with 10.2.0. Can you say which release version will include the
fix?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/97272] Wrong answer from MAXLOC with character arg
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
` (9 preceding siblings ...)
2021-01-22 21:08 ` longb at cray dot com
@ 2021-01-22 21:24 ` anlauf at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-01-22 21:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97272
--- Comment #11 from anlauf at gcc dot gnu.org ---
(In reply to Bill Long from comment #10)
> Still fails with 10.2.0. Can you say which release version will include the
> fix?
According to https://gcc.gnu.org/, gcc 10.2 was released in July 2020.
Extrapolating previous schedules, I'd expect 10.3 one year after 9.3,
which was released in March 2020.
You could check the 10-branch that the fix works for you.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-01-22 21:24 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 14:03 [Bug fortran/97272] New: Wrong answer from MAXLOC with character arg longb at cray dot com
2020-10-02 19:44 ` [Bug fortran/97272] " anlauf at gcc dot gnu.org
2020-10-02 20:02 ` anlauf at gcc dot gnu.org
2020-10-02 20:32 ` anlauf at gcc dot gnu.org
2020-10-04 18:24 ` cvs-commit at gcc dot gnu.org
2020-10-04 21:53 ` longb at cray dot com
2020-10-05 7:16 ` anlauf at gcc dot gnu.org
2020-10-08 16:55 ` cvs-commit at gcc dot gnu.org
2020-10-08 20:29 ` cvs-commit at gcc dot gnu.org
2020-10-08 21:00 ` anlauf at gcc dot gnu.org
2021-01-22 21:08 ` longb at cray dot com
2021-01-22 21:24 ` anlauf 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).