* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
@ 2007-05-09 0:10 ` jvdelisle at gcc dot gnu dot org
2007-05-09 0:33 ` jvdelisle at gcc dot gnu dot org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-05-09 0:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from jvdelisle at gcc dot gnu dot org 2007-05-09 01:10 -------
I will look this over tonight.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
2007-05-09 0:10 ` [Bug fortran/31867] " jvdelisle at gcc dot gnu dot org
@ 2007-05-09 0:33 ` jvdelisle at gcc dot gnu dot org
2007-05-09 6:33 ` burnus at gcc dot gnu dot org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-05-09 0:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from jvdelisle at gcc dot gnu dot org 2007-05-09 01:33 -------
I get:
words = 'two three'
On x86-64-gnu/linux with latest 4.3
I wonder if this is one that we recently fixed. Can you try with a more recent
build?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
2007-05-09 0:10 ` [Bug fortran/31867] " jvdelisle at gcc dot gnu dot org
2007-05-09 0:33 ` jvdelisle at gcc dot gnu dot org
@ 2007-05-09 6:33 ` burnus at gcc dot gnu dot org
2007-05-09 14:27 ` beliavsky at aol dot com
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-05-09 6:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from burnus at gcc dot gnu dot org 2007-05-09 07:33 -------
valgrind shows:
==7067== Syscall param write(buf) points to uninitialised byte(s)
==7067== at 0x5603550: write (in /lib64/libc-2.5.so)
==7067== by 0x4EC1130: do_write (unix.c:336)
==7067== by 0x4EC11D1: fd_flush (unix.c:386)
==7067== by 0x4EC1E17: fd_write (unix.c:761)
==7067== by 0x4EBE905: _gfortrani_next_record (transfer.c:2530)
==7067== by 0x4EBED15: finalize_transfer (transfer.c:2667)
==7067== by 0x4EBED58: _gfortran_st_write_done (transfer.c:2805)
==7067== by 0x40126D: MAIN__ (in /dev/shm/a.out)
==7067== by 0x4012AB: main (fmain.c:22)
--
burnus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (2 preceding siblings ...)
2007-05-09 6:33 ` burnus at gcc dot gnu dot org
@ 2007-05-09 14:27 ` beliavsky at aol dot com
2007-05-10 11:34 ` burnus at gcc dot gnu dot org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: beliavsky at aol dot com @ 2007-05-09 14:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from beliavsky at aol dot com 2007-05-09 15:27 -------
(In reply to comment #2)
> I get:
> words = 'two three'
> On x86-64-gnu/linux with latest 4.3
> I wonder if this is one that we recently fixed. Can you try with a more recent
> build?
Using Mingw 20070506, the problem persists. The behavior of the compiled
program is erratic. Running the compiled program in one Windows console
(command line) I get different "garbage" characters appended to the correct
output than when running it in a different Windows console. Running the program
repeatedly in the same console gives the same results.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (3 preceding siblings ...)
2007-05-09 14:27 ` beliavsky at aol dot com
@ 2007-05-10 11:34 ` burnus at gcc dot gnu dot org
2007-05-11 11:09 ` pault at gcc dot gnu dot org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-05-10 11:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from burnus at gcc dot gnu dot org 2007-05-10 12:34 -------
Reduced test case, which gives still the same valgrind error. In addition,
len(join(words)) should give 8 not 10.
Using "len=5" instead of "len=*" or "words(2)" instead of "words(:) fixes both.
(=> "8" and no valgrind error)
program xjoin
implicit none
character (len=5) :: words(2) = (/"two ","three"/)
write (*,*) len(join(words)) ! should be 8 is 10
write (*,*) join(words) ! valgrind error
contains
function join(words) result(str)
character (len=*), intent(in) :: words(:)
character (len=sum(len_trim(words))) :: str
str = ''
end function join
end program xjoin
--
burnus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2007-05-10 12:34:22
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (4 preceding siblings ...)
2007-05-10 11:34 ` burnus at gcc dot gnu dot org
@ 2007-05-11 11:09 ` pault at gcc dot gnu dot org
2007-05-11 12:13 ` pault at gcc dot gnu dot org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-11 11:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from pault at gcc dot gnu dot org 2007-05-11 12:09 -------
This gives the correct result:
pure integer function lensum (words, sep)
character (len=*), intent(in) :: words(:), sep
lensum = (size (words)-1) * len (sep) + sum (len_trim (words))
end function
module util_mod
implicit none
interface
pure integer function lensum (words, sep)
character (len=*), intent(in) :: words(:), sep
end function
end interface
contains
function join (words, sep) result(str)
! trim and concatenate a vector of character variables,
! inserting sep between them
character (len=*), intent(in) :: words(:), sep
character (len=lensum (words, sep)) :: str
integer :: i, nw
nw = size (words)
str = ""
if (nw < 1) then
return
else
str = words(1)
end if
do i=2,nw
str = trim (str) // sep // words(i)
end do
end function join
end module util_mod
!
program xjoin
use util_mod, only: join
implicit none
character (len=5) :: words(2) = (/"two ","three"/)
write (*,"(1x,'words = ',a)") "'"//join (words, "&")//"'"
end program xjoin
So I suspect that the problem lies in the interfacing around
gfc_conv_function_call but I just don't see it yet.
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (5 preceding siblings ...)
2007-05-11 11:09 ` pault at gcc dot gnu dot org
@ 2007-05-11 12:13 ` pault at gcc dot gnu dot org
2007-05-14 19:51 ` pault at gcc dot gnu dot org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-11 12:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from pault at gcc dot gnu dot org 2007-05-11 13:13 -------
(In reply to comment #6)
> So I suspect that the problem lies in the interfacing around
> gfc_conv_function_call but I just don't see it yet.
Indeed this is the case:
In Tobias' #5, changing the declaration for 'words' to -
character (len=5) :: words(0:1) = (/"two ","three"/)
produces a code that works correctly.
Looking at the code, the hidden calculation of len=sum(len_trim(words)), made
by the interface for the function call has an offset of 0, rather than -1.
Now to find out why!
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (6 preceding siblings ...)
2007-05-11 12:13 ` pault at gcc dot gnu dot org
@ 2007-05-14 19:51 ` pault at gcc dot gnu dot org
2007-05-15 9:56 ` pault at gcc dot gnu dot org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-14 19:51 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2625 bytes --]
------- Comment #8 from pault at gcc dot gnu dot org 2007-05-14 20:51 -------
The patch below works and regtests OK. I am not convince that this is the
whole story and need to think about it for a day or two.
Paul
Index: gcc/fortran/trans-array.c
===================================================================
*** gcc/fortran/trans-array.c (révision 124614)
--- gcc/fortran/trans-array.c (copie de travail)
*************** gfc_conv_expr_descriptor (gfc_se * se, g
*** 4563,4569 ****
limits will be the limits of the section.
A function may decide to repack the array to speed up access, but
we're not bothered about that here. */
! int dim, ndim;
tree parm;
tree parmtype;
tree stride;
--- 4563,4569 ----
limits will be the limits of the section.
A function may decide to repack the array to speed up access, but
we're not bothered about that here. */
! int dim, ndim, stride_ne_one;
tree parm;
tree parmtype;
tree stride;
*************** gfc_conv_expr_descriptor (gfc_se * se, g
*** 4613,4623 ****
--- 4613,4628 ----
else
base = NULL_TREE;
+ stride_ne_one = 0;
+
ndim = info->ref ? info->ref->u.ar.dimen : info->dimen;
for (n = 0; n < ndim; n++)
{
stride = gfc_conv_array_stride (desc, n);
+ if (!integer_onep (info->stride[dim]))
+ stride_ne_one = 1;
+
/* Work out the offset. */
if (info->ref
&& info->ref->u.ar.dimen_type[n] == DIMEN_ELEMENT)
*************** gfc_conv_expr_descriptor (gfc_se * se, g
*** 4710,4715 ****
--- 4715,4725 ----
/* Set the offset. */
tmp = gfc_conv_descriptor_offset (parm);
gfc_add_modify_expr (&loop.pre, tmp, base);
+ }
+ else if (GFC_ARRAY_TYPE_P (TREE_TYPE (desc)) && !stride_ne_one)
+ {
+ tmp = gfc_conv_descriptor_offset (parm);
+ gfc_add_modify_expr (&loop.pre, tmp, gfc_conv_array_offset (desc));
}
else
{
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pault at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2007-05-10 12:34:22 |2007-05-14 20:51:10
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (7 preceding siblings ...)
2007-05-14 19:51 ` pault at gcc dot gnu dot org
@ 2007-05-15 9:56 ` pault at gcc dot gnu dot org
2007-05-15 12:40 ` patchapp at dberlin dot org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-15 9:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from pault at gcc dot gnu dot org 2007-05-15 10:56 -------
(In reply to comment #8)
> The patch below works and regtests OK.
I told a lie - the version that regtests OK has the line
+ if (!integer_onep (info->stride[dim]))
+ stride_ne_one = 1;
a bit further down, within the subsequent 'else' block.
In fact, I have analysed this problem fully and am now regtesting a 'proper'
patch, which I hope to submit tonight.
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (8 preceding siblings ...)
2007-05-15 9:56 ` pault at gcc dot gnu dot org
@ 2007-05-15 12:40 ` patchapp at dberlin dot org
2007-05-21 13:16 ` pault at gcc dot gnu dot org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: patchapp at dberlin dot org @ 2007-05-15 12:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from patchapp at dberlin dot org 2007-05-15 13:40 -------
Subject: Bug number PR31867
A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2007-05/msg00961.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (9 preceding siblings ...)
2007-05-15 12:40 ` patchapp at dberlin dot org
@ 2007-05-21 13:16 ` pault at gcc dot gnu dot org
2007-05-21 13:19 ` [Bug fortran/31867] [4.2 only] " pault at gcc dot gnu dot org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-21 13:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from pault at gcc dot gnu dot org 2007-05-21 14:16 -------
Subject: Bug 31867
Author: pault
Date: Mon May 21 13:16:06 2007
New Revision: 124903
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124903
Log:
2007-05-21 Paul Thomas <pault@gcc.gnu.org>
PR fortran/31867
PR fortran/31994
* trans-array.c (gfc_conv_expr_descriptor): Obtain the stored
offset for non-descriptor, source arrays and correct for stride
not equal to one before writing to field of output descriptor.
2007-05-21 Paul Thomas <pault@gcc.gnu.org>
PR fortran/31867
* gfortran.dg/char_length_5.f90: New test.
PR fortran/31994
* gfortran.dg/array_reference_1.f90: New test.
Added:
trunk/gcc/testsuite/gfortran.dg/array_reference_1.f90
trunk/gcc/testsuite/gfortran.dg/char_length_5.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-array.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] [4.2 only] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (10 preceding siblings ...)
2007-05-21 13:16 ` pault at gcc dot gnu dot org
@ 2007-05-21 13:19 ` pault at gcc dot gnu dot org
2007-05-31 18:51 ` pault at gcc dot gnu dot org
2007-05-31 18:53 ` pault at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-21 13:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from pault at gcc dot gnu dot org 2007-05-21 14:18 -------
Fixed on trunk
Paul
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|function result with |[4.2 only] function result
|character LEN computed at |with character LEN computed
|run time |at run time
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] [4.2 only] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (11 preceding siblings ...)
2007-05-21 13:19 ` [Bug fortran/31867] [4.2 only] " pault at gcc dot gnu dot org
@ 2007-05-31 18:51 ` pault at gcc dot gnu dot org
2007-05-31 18:53 ` pault at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-31 18:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #13 from pault at gcc dot gnu dot org 2007-05-31 18:51 -------
Subject: Bug 31867
Author: pault
Date: Thu May 31 18:50:56 2007
New Revision: 125235
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125235
Log:
2007-05-31 Paul Thomas <pault@gcc.gnu.org>
backport from trunk
PR fortran/31483
* trans-expr.c (gfc_conv_function_call): Give a dummy
procedure the correct type if it has alternate returns.
PR fortran/31540
* resolve.c (resolve_fl_procedure): Resolve constant character
lengths.
PR fortran/31867
PR fortran/31994
* trans-array.c (gfc_conv_expr_descriptor): Obtain the stored
offset for non-descriptor, source arrays and correct for stride
not equal to one before writing to field of output descriptor.
2007-05-31 Paul Thomas <pault@gcc.gnu.org>
backport from trunk
PR fortran/31483
* gfortran.dg/altreturn_5.f90: New test.
PR fortran/31540
* gfortran.dg/char_result_5.f90: New test.
PR fortran/31867
* gfortran.dg/char_length_5.f90: New test.
PR fortran/31994
* gfortran.dg/array_reference_1.f90: New test.
Added:
branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/altreturn_5.f90
branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/array_reference_1.f90
branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/char_length_5.f90
branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/char_result_13.f90
Modified:
branches/gcc-4_2-branch/gcc/fortran/ChangeLog
branches/gcc-4_2-branch/gcc/fortran/resolve.c
branches/gcc-4_2-branch/gcc/fortran/trans-array.c
branches/gcc-4_2-branch/gcc/fortran/trans-expr.c
branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug fortran/31867] [4.2 only] function result with character LEN computed at run time
2007-05-08 15:28 [Bug fortran/31867] New: function result with character LEN computed at run time beliavsky at aol dot com
` (12 preceding siblings ...)
2007-05-31 18:51 ` pault at gcc dot gnu dot org
@ 2007-05-31 18:53 ` pault at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-05-31 18:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #14 from pault at gcc dot gnu dot org 2007-05-31 18:53 -------
Fixed
Paul
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31867
^ permalink raw reply [flat|nested] 15+ messages in thread