public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/52724] New: Internal read with character(kind=4) data
@ 2012-03-26 13:10 tkoenig at gcc dot gnu.org
2012-03-26 16:25 ` [Bug fortran/52724] " tkoenig at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-03-26 13:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
Bug #: 52724
Summary: Internal read with character(kind=4) data
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: tkoenig@gcc.gnu.org
This code in io/unit.c looks fishy:
/* Set initial values for unit parameters. */
if (dtp->common.unit)
{
iunit->s = open_internal4 (dtp->internal_unit - start_record,
dtp->internal_unit_len, -start_record);
fbuf_init (iunit, 256);
}
else
iunit->s = open_internal (dtp->internal_unit - start_record,
dtp->internal_unit_len, -start_record);
because it supposes that an internal unit for character(kind=4) data
has an internal unit number which is unequal to zero.
And, in fact, this fails:
ig25@linux-fd1f:~/Krempel/Opt> cat foo.f90
!234567
character buffer4(100)
integer i
buffer4 = 4_'123'
read(buffer4,*) i
print *,i
end
ig25@linux-fd1f:~/Krempel/Opt> gfortran foo.f90
ig25@linux-fd1f:~/Krempel/Opt> ./a.out
1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/52724] Internal read with character(kind=4) data
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
@ 2012-03-26 16:25 ` tkoenig at gcc dot gnu.org
2012-03-29 1:44 ` jvdelisle at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-03-26 16:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jvdelisle at gcc dot
| |gnu.org
--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-03-26 16:14:36 UTC ---
Hi Jerry,
do you have any idea?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/52724] Internal read with character(kind=4) data
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
2012-03-26 16:25 ` [Bug fortran/52724] " tkoenig at gcc dot gnu.org
@ 2012-03-29 1:44 ` jvdelisle at gcc dot gnu.org
2012-04-02 20:01 ` burnus at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2012-03-29 1:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
--- Comment #2 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2012-03-29 01:05:20 UTC ---
I am curious about what this line is doing:
buffer4 = 4_'123'
buffer4 is a kind=1 variable. have you tried: character(kind=4) buffer4(100) ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/52724] Internal read with character(kind=4) data
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
2012-03-26 16:25 ` [Bug fortran/52724] " tkoenig at gcc dot gnu.org
2012-03-29 1:44 ` jvdelisle at gcc dot gnu.org
@ 2012-04-02 20:01 ` burnus at gcc dot gnu.org
2012-04-08 8:55 ` tkoenig at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-04-02 20:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-04-02
CC| |burnus at gcc dot gnu.org
Ever Confirmed|0 |1
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-04-02 20:01:08 UTC ---
(In reply to comment #2)
> I am curious about what this line is doing:
character buffer4(100)
buffer4 = 4_'123'
Well, that line does what it should do: It assign the value '123' - trimmed to
one character (namely '1') to the array buffer4. The array4 then contains 100
times the value '1'.
(In reply to comment #0)
> read(buffer4,*) i
> print *,i
> end
> ig25@linux-fd1f:~/Krempel/Opt> gfortran foo.f90
> ig25@linux-fd1f:~/Krempel/Opt> ./a.out
> 1
And seemingly that's also what Thomas gets.
* * *
(In reply to comment #2)
> buffer4 is a kind=1 variable. have you tried:
> character(kind=4) buffer4(100) ?
Well, with len=1,kind=4 or with len=2,kind=2 one gets, respectively, 1 and 12 -
which is the expected result.
However, the following fails:
character(len=2,kind=4) buffer4(100)
integer i
buffer4 = 4_'123'
read(buffer4,*) i
print *,i
end
Fortran runtime error: Bad integer for item 1 in list input
Printing the value of the array as "print *, buffer4", one gets the expected "
121212...." as output.
And reading the line as
read(buffer4,'(i5)') i
works and yields "12". Only when replacing the formatted read by a
list-directed read, it fails.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/52724] Internal read with character(kind=4) data
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
` (2 preceding siblings ...)
2012-04-02 20:01 ` burnus at gcc dot gnu.org
@ 2012-04-08 8:55 ` tkoenig at gcc dot gnu.org
2012-09-24 18:07 ` tkoenig at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-04-08 8:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
--- Comment #4 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-04-08 08:55:42 UTC ---
Yes, my original test case was bogus.
Slightly reduced test case:
program main
implicit none
integer :: i
character(len=100,kind=4) :: buffer
buffer = 4_"123"
read(buffer,*) i
print *,i
end program main
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/52724] Internal read with character(kind=4) data
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
` (3 preceding siblings ...)
2012-04-08 8:55 ` tkoenig at gcc dot gnu.org
@ 2012-09-24 18:07 ` tkoenig at gcc dot gnu.org
2012-09-29 17:39 ` tkoenig at gcc dot gnu.org
2012-10-28 20:51 ` tkoenig at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-09-24 18:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
--- Comment #5 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-09-24 18:07:17 UTC ---
This patch looks promising:
Index: list_read.c
===================================================================
--- list_read.c (Revision 191649)
+++ list_read.c (Arbeitskopie)
@@ -199,9 +199,16 @@ next_char (st_parameter_dt *dtp)
if (is_internal_unit (dtp))
{
- char cc;
- length = sread (dtp->u.p.current_unit->s, &cc, 1);
- c = cc;
+ /* Check for kind=4 internal unit. */
+ if (dtp->common.unit)
+ length = sread (dtp->u.p.current_unit->s, &c, sizeof (gfc_char4_t));
+ else
+ {
+ char cc;
+ length = sread (dtp->u.p.current_unit->s, &cc, 1);
+ c = cc;
+ }
+
if (length < 0)
{
generate_error (&dtp->common, LIBERROR_OS, NULL);
Index: unix.c
===================================================================
--- unix.c (Revision 191649)
+++ unix.c (Arbeitskopie)
@@ -959,7 +959,7 @@ open_internal4 (char *base, int length, gfc_offset
s->buffer = base;
s->buffer_offset = offset;
- s->active = s->file_length = length;
+ s->active = s->file_length = length * sizeof (gfc_char4_t);
s->st.vptr = &mem4_vtable;
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/52724] Internal read with character(kind=4) data
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
` (4 preceding siblings ...)
2012-09-24 18:07 ` tkoenig at gcc dot gnu.org
@ 2012-09-29 17:39 ` tkoenig at gcc dot gnu.org
2012-10-28 20:51 ` tkoenig at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-09-29 17:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
--- Comment #6 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-09-29 17:38:50 UTC ---
Author: tkoenig
Date: Sat Sep 29 17:38:46 2012
New Revision: 191854
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191854
Log:
2012-09-29 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52724
* list_read.c (next_char): Handle kind=4 characters.
* unix.c (open_internal4): Correct lenth of internal file.
2012-09-29 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52724
* gfortran.dg/internal_readwrite_3.f90: New test.
Added:
trunk/gcc/testsuite/gfortran.dg/internal_readwrite_3.f90
Modified:
trunk/gcc/testsuite/ChangeLog
trunk/libgfortran/ChangeLog
trunk/libgfortran/io/list_read.c
trunk/libgfortran/io/unix.c
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/52724] Internal read with character(kind=4) data
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
` (5 preceding siblings ...)
2012-09-29 17:39 ` tkoenig at gcc dot gnu.org
@ 2012-10-28 20:51 ` tkoenig at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-10-28 20:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52724
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #7 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-10-28 20:51:37 UTC ---
Fixed on trunk, closing.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-10-28 20:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26 13:10 [Bug fortran/52724] New: Internal read with character(kind=4) data tkoenig at gcc dot gnu.org
2012-03-26 16:25 ` [Bug fortran/52724] " tkoenig at gcc dot gnu.org
2012-03-29 1:44 ` jvdelisle at gcc dot gnu.org
2012-04-02 20:01 ` burnus at gcc dot gnu.org
2012-04-08 8:55 ` tkoenig at gcc dot gnu.org
2012-09-24 18:07 ` tkoenig at gcc dot gnu.org
2012-09-29 17:39 ` tkoenig at gcc dot gnu.org
2012-10-28 20:51 ` tkoenig 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).