comp.lang.ada
 help / color / mirror / Atom feed
* Problem with streams using 64-bit compiler
@ 2010-01-04 22:46 sjw
  2010-01-04 23:09 ` Ludovic Brenta
  0 siblings, 1 reply; 3+ messages in thread
From: sjw @ 2010-01-04 22:46 UTC (permalink / raw)


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;



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with streams using 64-bit compiler
  2010-01-04 22:46 Problem with streams using 64-bit compiler sjw
@ 2010-01-04 23:09 ` Ludovic Brenta
  2010-01-04 23:41   ` sjw
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Brenta @ 2010-01-04 23:09 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with streams using 64-bit compiler
  2010-01-04 23:09 ` Ludovic Brenta
@ 2010-01-04 23:41   ` sjw
  0 siblings, 0 replies; 3+ messages in thread
From: sjw @ 2010-01-04 23:41 UTC (permalink / raw)


On Jan 4, 11:09 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> 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.

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!



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-04 23:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-04 22:46 Problem with streams using 64-bit compiler sjw
2010-01-04 23:09 ` Ludovic Brenta
2010-01-04 23:41   ` sjw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox