public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables
@ 2008-05-17 18:04 fxcoudert at gcc dot gnu dot org
2008-05-18 10:03 ` [Bug fortran/36257] " pault at gcc dot gnu dot org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-05-17 18:04 UTC (permalink / raw)
To: gcc-bugs
This one turned up during my testing of SPREAD on wide character strings, but
it turns out that it already happens on default character variables. It looks
like the front-end doesn't fill the return array descriptor well.
$ cat k2.f90
implicit none
character(len=5), dimension(3,3), parameter :: &
p = reshape(["", "", "", "", "", "", "", "", ""], [3,3])
character(len=5), dimension(3,3) :: m1
m1 = p
if (any (spread (p, 1, 2) /= spread (m1, 1, 2))) call abort
end
$ gfortran k2.f90 && ./a.out
Fortran runtime error: rank mismatch in spread()
The most amazing is that it's specific to character variables (ie it doesn't
happen with integer, for example).
--
Summary: SPREAD gives wrong results with CHARACTER variables
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fxcoudert at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36257
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/36257] SPREAD gives wrong results with CHARACTER variables
2008-05-17 18:04 [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables fxcoudert at gcc dot gnu dot org
@ 2008-05-18 10:03 ` pault at gcc dot gnu dot org
2008-05-18 10:43 ` [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters tkoenig at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-05-18 10:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pault at gcc dot gnu dot org 2008-05-18 10:03 -------
Confirmed.
This is quite revealing...
implicit none
character(len=5), dimension(3,3), parameter :: &
p = reshape(["a", "b", "c", "d", "e", "f", "g", "h", "i"], [3,3])
character(len=5), dimension(3,3) :: m1
m1 = p
print *, shape (spread (p, 1, 2))
print *, spread (p, 1, 2)
print *, spread (p, 1, 2)//"z"
! print *, spread (p, 1, 2) /= spread (m1, 1, 2)
! if (any (spread (p, 1, 2) /= spread (m1, 1, 2))) call abort
end
The first two prints are OK but the third is completely screwed up. The
front-end is not providing the right shape, to judge by the array descriptors
provided for the temporaries. BTW characters are treated separately in the
library - they all go to spread_internal.
Thanks for that one! Maybe Thomas can pinpoint the problem right away?
Cheers
Paul
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-05-18 10:03:00
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36257
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters
2008-05-17 18:04 [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables fxcoudert at gcc dot gnu dot org
2008-05-18 10:03 ` [Bug fortran/36257] " pault at gcc dot gnu dot org
@ 2008-05-18 10:43 ` tkoenig at gcc dot gnu dot org
2008-05-18 14:56 ` fxcoudert at gcc dot gnu dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-05-18 10:43 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2948 bytes --]
------- Comment #2 from tkoenig at gcc dot gnu dot org 2008-05-18 10:42 -------
The problem is with the array parameter.
$ cat spread.f90
implicit none
character(len=5), dimension(3,3), parameter :: &
p = reshape(["a", "b", "c", "d", "e", "f", "g", "h", "i"], [3,3])
character(len=5), dimension(3,3) :: m1
m1 = p
print '(18A)', spread (p, 1, 2)//"z"
print '(18A)', spread (m1, 1, 2)//"z"
end
$ gfortran -fdump-tree-original -g spread.f90
$ gdb ./a.out
Breakpoint 1 (_gfortran_spread_char) pending.
(gdb) r
Starting program: /tmp/a.out
Breakpoint 2 at 0xb7f69f13: file
../../../../gcc/trunk/libgfortran/intrinsics/spread_generic.c, line 421.
Pending breakpoint "_gfortran_spread_char" resolved
Breakpoint 2, *_gfortran_spread_char (ret=0xbfe7d7b8, ret_length=5,
source=0xbfe7d80c,
along=0x8048dd4, pncopies=0x8048dd0, source_length=5)
at ../../../../gcc/trunk/libgfortran/intrinsics/spread_generic.c:422
422 spread_internal (ret, source, along, pncopies, source_length);
(gdb) p *source
$1 = {data = 0xbfe7d827 "a b c ç¿\001", offset = 0, dtype = 369, dim =
{{
stride = 1, lbound = 0, ubound = 2}, {stride = 1627389952, lbound =
538976288,
ubound = 538976354}, {stride = 538993440, lbound = -1075372000, ubound =
1}, {
stride = 0, lbound = -1075324808, ubound = -1208419248}, {stride =
-1075324752,
lbound = -1209229152, ubound = -1075317768}, {stride = -1075324652,
lbound = -1075324808, ubound = 134515769}, {stride = 1, lbound =
-1075324652,
ubound = -1075324792}}}
This is seriously flawed. The data pointer is wrong, as is the dtype.
Using m1 is ok:
(gdb) c
Continuing.
a za zb zb zc zc z
Breakpoint 2, *_gfortran_spread_char (ret=0xbfe7d758, ret_length=5,
source=0xbfe7d7b8,
along=0x8048dd4, pncopies=0x8048dd0, source_length=5)
at ../../../../gcc/trunk/libgfortran/intrinsics/spread_generic.c:422
422 spread_internal (ret, source, along, pncopies, source_length);
(gdb) p *source
$2 = {data = 0xbfe7d78b "a b c d e f g h i
\213×ç¿üÿÿÿr\001",
offset = 4294967292, dtype = 370, dim = {{stride = 1, lbound = 1, ubound =
3}, {
stride = 3, lbound = 1, ubound = 3}, {stride = -1208504320, lbound =
543414304,
ubound = 2048925728}, {stride = -1075324928, lbound = 0, ubound = 0},
{stride = 1,
lbound = 0, ubound = 2}, {stride = 134516032, lbound = 134516037,
ubound = 134516042}, {stride = -1075324889, lbound = 0, ubound = 369}}}
--
tkoenig at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|SPREAD gives wrong results |SPREAD gives wrong results
|with CHARACTER variables |with array CHARACTER
| |parameters
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36257
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters
2008-05-17 18:04 [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables fxcoudert at gcc dot gnu dot org
2008-05-18 10:03 ` [Bug fortran/36257] " pault at gcc dot gnu dot org
2008-05-18 10:43 ` [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters tkoenig at gcc dot gnu dot org
@ 2008-05-18 14:56 ` fxcoudert at gcc dot gnu dot org
2008-05-20 13:34 ` fxcoudert at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-05-18 14:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from fxcoudert at gcc dot gnu dot org 2008-05-18 14:55 -------
I have some more information, but it still doesn't make sense. I'm comparing
the codepaths taken in the front-end by:
implicit none
character(len=5), dimension(3,3), parameter :: &
p = reshape(["a", "b", "c", "d", "e", "f", "g", "h", "i"], [3,3])
character(len=5), dimension(3,3) :: m1
m1 = p
print '(18A)', spread (m1, 1, 2)//"z"
end
and:
implicit none
character(len=5), dimension(3,3), parameter :: &
p = reshape(["a", "b", "c", "d", "e", "f", "g", "h", "i"], [3,3])
print '(18A)', spread (p, 1, 2)//"z"
end
In both cases, we end up twice in gfc_resolve_spread, but while for a
non-parameter array, we always give the return type its correct rank (f->rank =
3), for the paramater array, we give it a rank of 2 the second time. That's
because in check_charlen_present(), the source->rank gets modified from 2 to
1). I don't understand why we do this (someone assumed that we can only have
array parameters with rank 1?)
So, commenting that piece of code there:
Index: iresolve.c
===================================================================
--- iresolve.c (revision 135395)
+++ iresolve.c (working copy)
@@ -78,7 +78,7 @@ check_charlen_present (gfc_expr *source)
{
source->ts.cl->length =
gfc_int_expr (source->value.constructor->expr->value.character.length);
- source->rank = 1;
+ /*source->rank = 1;*/
}
}
make that testcase work, but I wonder what else it breaks :)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36257
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters
2008-05-17 18:04 [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables fxcoudert at gcc dot gnu dot org
` (2 preceding siblings ...)
2008-05-18 14:56 ` fxcoudert at gcc dot gnu dot org
@ 2008-05-20 13:34 ` fxcoudert at gcc dot gnu dot org
2008-05-21 16:03 ` fxcoudert at gcc dot gnu dot org
2008-05-21 16:13 ` fxcoudert at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-05-20 13:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from fxcoudert at gcc dot gnu dot org 2008-05-20 13:33 -------
(In reply to comment #3)
> I wonder what else it breaks :)
Apparently, nothing. It was apparently introduced by Paul and I during the
efforts to fix PR31608, and is probably just copied from the lines above.
Anyway, the testsuite regtests fine on x86_64-linux with it, and CP2K still
compiles. As I don't see a logic for that line, let's just remove it!
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |fxcoudert at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
Last reconfirmed|2008-05-18 10:03:00 |2008-05-20 13:33:47
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36257
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters
2008-05-17 18:04 [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables fxcoudert at gcc dot gnu dot org
` (3 preceding siblings ...)
2008-05-20 13:34 ` fxcoudert at gcc dot gnu dot org
@ 2008-05-21 16:03 ` fxcoudert at gcc dot gnu dot org
2008-05-21 16:13 ` fxcoudert at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-05-21 16:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from fxcoudert at gcc dot gnu dot org 2008-05-21 16:02 -------
Subject: Bug 36257
Author: fxcoudert
Date: Wed May 21 16:01:08 2008
New Revision: 135723
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135723
Log:
PR fortran/36257
* gfortran.dg/char_length_12.f90: New test.
* iresolve.c (check_charlen_present): Don't force the rank to 1.
Added:
trunk/gcc/testsuite/gfortran.dg/char_length_12.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/iresolve.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36257
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters
2008-05-17 18:04 [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables fxcoudert at gcc dot gnu dot org
` (4 preceding siblings ...)
2008-05-21 16:03 ` fxcoudert at gcc dot gnu dot org
@ 2008-05-21 16:13 ` fxcoudert at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-05-21 16:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from fxcoudert at gcc dot gnu dot org 2008-05-21 16:12 -------
Fixed.
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36257
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-05-21 16:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-17 18:04 [Bug fortran/36257] New: SPREAD gives wrong results with CHARACTER variables fxcoudert at gcc dot gnu dot org
2008-05-18 10:03 ` [Bug fortran/36257] " pault at gcc dot gnu dot org
2008-05-18 10:43 ` [Bug fortran/36257] SPREAD gives wrong results with array CHARACTER parameters tkoenig at gcc dot gnu dot org
2008-05-18 14:56 ` fxcoudert at gcc dot gnu dot org
2008-05-20 13:34 ` fxcoudert at gcc dot gnu dot org
2008-05-21 16:03 ` fxcoudert at gcc dot gnu dot org
2008-05-21 16:13 ` fxcoudert at gcc dot gnu dot 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).