* [patch, libgfortran] PR107031 - endfile truncates file at wrong position
@ 2024-03-26 3:18 Jerry D
2024-03-26 17:43 ` Harald Anlauf
0 siblings, 1 reply; 3+ messages in thread
From: Jerry D @ 2024-03-26 3:18 UTC (permalink / raw)
To: gfortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 803 bytes --]
Hi all,
There has been a bit of discussio on which way to go on this.
I took a look today and this trivial patch gives the behavior concluded
on Fortran Discourse. See the bugzilla for all the relevant information.
Regresion tested on x86-64.
I will do the appropriate changelog.
OK for trunk?
Attached is a new test case and the patch here:
diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c
index 2bc05b293f8..d169961f997 100644
--- a/libgfortran/io/file_pos.c
+++ b/libgfortran/io/file_pos.c
@@ -352,7 +352,6 @@ st_endfile (st_parameter_filepos *fpp)
dtp.common = fpp->common;
memset (&dtp.u.p, 0, sizeof (dtp.u.p));
dtp.u.p.current_unit = u;
- next_record (&dtp, 1);
}
unit_truncate (u, stell (u->s), &fpp->common);
[-- Attachment #2: endfile_5.f90 --]
[-- Type: text/x-fortran, Size: 650 bytes --]
! { dg-do run }
! PR107031 Check that endfile truncates at end of record 5.
program test_truncate
integer :: num_rec, tmp, i, nr, j
open(10, file="in.dat", action='readwrite')
do i=1,10
write(10, *) i
end do
rewind (10)
num_rec = 5
i = 1
ioerr = 0
do while (i <= num_rec .and. ioerr == 0)
read(10, *, iostat=ioerr) tmp
i = i + 1
enddo
endfile(10)
rewind (10)
i = 0
ioerr = 0
do while (i <= num_rec + 1 .and. ioerr == 0)
read(10, *, iostat=ioerr) j
i = i + 1
end do
close(10, status='delete')
if (i - 1 /= 5) stop 1
end program test_truncate
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch, libgfortran] PR107031 - endfile truncates file at wrong position
2024-03-26 3:18 [patch, libgfortran] PR107031 - endfile truncates file at wrong position Jerry D
@ 2024-03-26 17:43 ` Harald Anlauf
2024-03-26 17:43 ` Harald Anlauf
0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2024-03-26 17:43 UTC (permalink / raw)
To: Jerry D, gfortran; +Cc: gcc-patches
Hi Jerry,
Am 26.03.24 um 04:18 schrieb Jerry D:
> Hi all,
>
> There has been a bit of discussio on which way to go on this.
>
> I took a look today and this trivial patch gives the behavior concluded
> on Fortran Discourse. See the bugzilla for all the relevant information.
>
> Regresion tested on x86-64.
>
> I will do the appropriate changelog.
>
> OK for trunk?
>
> Attached is a new test case and the patch here:
>
> diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c
> index 2bc05b293f8..d169961f997 100644
> --- a/libgfortran/io/file_pos.c
> +++ b/libgfortran/io/file_pos.c
> @@ -352,7 +352,6 @@ st_endfile (st_parameter_filepos *fpp)
> dtp.common = fpp->common;
> memset (&dtp.u.p, 0, sizeof (dtp.u.p));
> dtp.u.p.current_unit = u;
> - next_record (&dtp, 1);
> }
>
> unit_truncate (u, stell (u->s), &fpp->common);
this is OK from my side.
Given the discussion on "dg-do run", wouldn't this be a perfect
example where it is sufficient to run the testcase just once?
The change is in libgfortran, not in the frontend or middle-end.
Thanks for the patch!
Harald
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch, libgfortran] PR107031 - endfile truncates file at wrong position
2024-03-26 17:43 ` Harald Anlauf
@ 2024-03-26 17:43 ` Harald Anlauf
0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2024-03-26 17:43 UTC (permalink / raw)
To: gcc-patches; +Cc: fortran
Hi Jerry,
Am 26.03.24 um 04:18 schrieb Jerry D:
> Hi all,
>
> There has been a bit of discussio on which way to go on this.
>
> I took a look today and this trivial patch gives the behavior concluded
> on Fortran Discourse. See the bugzilla for all the relevant information.
>
> Regresion tested on x86-64.
>
> I will do the appropriate changelog.
>
> OK for trunk?
>
> Attached is a new test case and the patch here:
>
> diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c
> index 2bc05b293f8..d169961f997 100644
> --- a/libgfortran/io/file_pos.c
> +++ b/libgfortran/io/file_pos.c
> @@ -352,7 +352,6 @@ st_endfile (st_parameter_filepos *fpp)
> dtp.common = fpp->common;
> memset (&dtp.u.p, 0, sizeof (dtp.u.p));
> dtp.u.p.current_unit = u;
> - next_record (&dtp, 1);
> }
>
> unit_truncate (u, stell (u->s), &fpp->common);
this is OK from my side.
Given the discussion on "dg-do run", wouldn't this be a perfect
example where it is sufficient to run the testcase just once?
The change is in libgfortran, not in the frontend or middle-end.
Thanks for the patch!
Harald
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-26 17:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26 3:18 [patch, libgfortran] PR107031 - endfile truncates file at wrong position Jerry D
2024-03-26 17:43 ` Harald Anlauf
2024-03-26 17:43 ` Harald Anlauf
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).