Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with streams using 64-bit compiler

0 views
Skip to first unread message

sjw

unread,
Jan 4, 2010, 5:46:37 PM1/4/10
to
While trying to build a 64-bit compiler for Mac OS X Snow Leopard, I
came across this undesirable behaviour: if the program (see end) is
compiled in 32-bit mode or in 64-bit mode with -O0 it works fine,
output is as expected:

$ ./streamy
1234
'z'
4.32100E-01
4.32100E-01

If compiled in 64-bit mode with -O2, output is

$ ./streamy
1234
NUL
0.00000E+00
0.00000E+00

This is a readback problem, the data file has the same content in all
cases.

Can anyone with access to an x86_64 compiler (Mac OS X Leopard, or a
Linux, 4.4+) have a try and see what happens?

Thanks in advance,

--S

--------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Streams.Stream_IO;

procedure Streamy is

type Kind is (I, C, F);

type Item (Of_Kind : Kind := I) is record
case Of_Kind is
when I => I : Integer;
when C => C : Character;
when F => F : Float;
end case;
end record;

File : Ada.Streams.Stream_IO.File_Type;

use Ada.Streams.Stream_IO;

begin

Create (File, Name => "test.dat");

Reset (File, Mode => Out_File);
Item'Output (Stream (File), Item'(I, 1234));
Item'Output (Stream (File), Item'(C, 'z'));
Item'Output (Stream (File), Item'(F, 0.4321));

Reset (File, Mode => In_File);
for N in 1 .. 3 loop
declare
It : constant Item := Item'Input (Stream (File));
begin
case It.Of_Kind is
when I =>
Put_Line (It.I'Img);
when C =>
Put_Line (It.C'Img);
when F =>
Put_Line (It.F'Img);
end case;
end;
end loop;

Reset (File, Mode => Out_File);
Item'Write (Stream (File), Item'(F, 0.4321));

Reset (File, Mode => In_File);
declare
Flt : Item (F);
begin
Item'Read (Stream (File), Flt);
Put_Line (Flt.F'Img);
end;

end Streamy;

Ludovic Brenta

unread,
Jan 4, 2010, 6:09:25 PM1/4/10
to
On Jan 4, 11:46 pm, sjw <simon.j.wri...@mac.com> wrote:
> While trying to build a 64-bit compiler for Mac OS X Snow Leopard, I
> came across this undesirable behaviour: if the program (see end) is
> compiled in 32-bit mode or in 64-bit mode with -O0 it works fine,
> output is as expected:
>
> $ ./streamy
>  1234
> 'z'
>  4.32100E-01
>  4.32100E-01
>
> If compiled in 64-bit mode with -O2, output is
>
> $ ./streamy
> 1234
> NUL
>  0.00000E+00
>  0.00000E+00
>
> This is a readback problem, the data file has the same content in all
> cases.
>
> Can anyone with access to an x86_64 compiler (Mac OS X Leopard, or a
> Linux, 4.4+) have a try and see what happens?
[...]

I get the same behavior as you on Debian:

gnat-4.4_4.4.2-5_amd64.deb:
-O0 OK
-O1 bug
-O2 bug
gnat-4.4_4.4.2-5_i386.deb:
-O0 OK
-O1 OK
-O2 OK

This version of GNAT is taken from the FSF's gcc-4_4-branch on
2009-12-28 so is very recent.

I suggest you report the bug to http://gcc.gnu.org/bugzilla. Since
you've got a perfect reproducer test case, the bug should be easy
enough to fix.

Maybe someone else can try GCC 4.5?

--
Ludovic Brenta.

sjw

unread,
Jan 4, 2010, 6:41:10 PM1/4/10
to

Thanks for that.

> I suggest you report the bug to http://gcc.gnu.org/bugzilla.  Since
> you've got a perfect reproducer test case, the bug should be easy
> enough to fix.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42618

> Maybe someone else can try GCC 4.5?

Last time I tried to build 4.5.0 I got a compiler bomb while compiling
a-direct.adb, no changes since then. Time to file a bug on that I
guess!

0 new messages