comp.lang.ada
 help / color / mirror / Atom feed
* Large arrays (again), problem case for GNAT
@ 2005-04-13 12:46 Dr. Adrian Wrigley
  2005-04-13 13:10 ` Larry Kilgallen
                   ` (4 more replies)
  0 siblings, 5 replies; 40+ messages in thread
From: Dr. Adrian Wrigley @ 2005-04-13 12:46 UTC (permalink / raw)


Hi guys!

A month or two back I hinted that I had been having problems
the GNAT code accessing large data structures.  It seemed that
incorrect code was silently being generated.  Since I didn't
have a test case available, no progress could be made.

I have encountered the problem again, and produced a test case.

In summary:

Certain uses of arrays over about 800MB cause code to fail.
In particular, 'Address is sometimes incorrect
Accessing high elements is incorrect, depending on exact code to
  generate the index.

The problems only seem to occur if the upper bound of the array
is compile-time constant.

Can someone test this on later versions of GNAT please?
-- 
Adrian Wrigley, Cambridge, UK


with Text_IO;
with System.Address_Image;

procedure TestBug is

-- Test devised by Adrian Wrigley, amtw@linuxchip.demon.co.uk.uk.uk (one uk is enough)
-- I disclaim all rights to this code.  Do what you wish with it!

-- This test case illustrates a problem with code
-- compiled on GNAT 3.15p for x86 under Linux

-- It shows that the 'Address of elements of large
-- arrays can be silently incorrect

-- Notes:
--
-- This test works if the word "constant" is removed
--
-- The test also works if the value is less than 200_000_000
-- Indexing element also works with computed index
   Size : constant Integer := 210_000_000;

   type Big_T is array (1 .. Size) of aliased Float;

   type Big_A is access Big_T;

   Big : Big_A;

   function GetSomeMemory (X : Integer) return Big_A;
   pragma Import (C, GetSomeMemory, "malloc");

begin

   Big := GetSomeMemory (Size*4 + 16); -- This seems to work OK for now

   Text_IO.Put_Line ("First element attribute " & Integer'Image (Big_T'First));
   Text_IO.Put_Line ("Last element attribute  " & Integer'Image (Big_T'Last));

   Text_IO.Put_Line ("Address of first element is " & System.Address_Image (Big (Big_T'First)'Address));
   Text_IO.Put_Line ("Address of last element is  " & System.Address_Image (Big (Big_T'Last)'Address)); -- Fails!!!!!
   Text_IO.Put_Line ("(Last element should be at higher address than first)");


   declare
      J : Integer := Size;
   begin
      Text_IO.Put_Line ("Address of last element is " & System.Address_Image (Big (J)'Address));
   end;

   Text_IO.Put_Line ("Writing to all elements in loop");
   for I in Big_T'Range loop
      Big (I) := 0.0;
   end loop;

   Text_IO.Put_Line ("Writing to 'Last element");

--raised STORAGE_ERROR : stack overflow (or erroneous memory access):
   Big (Big_T'Last) := 0.0; -- Fails!!!!!

end TestBug;

I get
$ gnatmake -O3  testbug
$ ./testbug

First element attribute  1
Last element attribute   210000000
Address of first element is 4212F008
Address of last element is  34245204
Last element should be at higher address than first
Address of last element is 74245204
Writing to all elements in loop
Writing to 'Last element

raised STORAGE_ERROR : stack overflow (or erroneous memory access)





^ permalink raw reply	[flat|nested] 40+ messages in thread
* Re: Large arrays (again), problem case for GNAT
@ 2005-04-13 13:52 Duncan Sands
  2005-04-13 14:20 ` Dr. Adrian Wrigley
  0 siblings, 1 reply; 40+ messages in thread
From: Duncan Sands @ 2005-04-13 13:52 UTC (permalink / raw)
  To: comp.lang.ada

> Can someone test this on later versions of GNAT please?

gcc version 3.4.4 20050328 (prerelease) for GNAT Pro 5.04w (20050326)

$ ./testbug
First element attribute  1
Last element attribute   210000000

raised CONSTRAINT_ERROR : testbug.adb:39 access check failed

Ciao,

Duncan.

PS: I couldn't reply directly to Adrian:

RCPT TO <amtw@linuxchip.demon.co.uk.uk.uk> failed: Requested action not
taken: mailbox unavailable.




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

end of thread, other threads:[~2005-04-15 19:06 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-13 12:46 Large arrays (again), problem case for GNAT Dr. Adrian Wrigley
2005-04-13 13:10 ` Larry Kilgallen
2005-04-13 13:24   ` Alex R. Mosteo
2005-04-13 13:31   ` Marc A. Criley
2005-04-13 19:52 ` Jeffrey Carter
2005-04-13 19:54 ` Randy Brukardt
2005-04-13 22:01   ` (see below)
2005-04-14  0:16     ` Robert A Duff
2005-04-14  1:11       ` Alexander E. Kopilovich
2005-04-14  7:29         ` Dmitry A. Kazakov
2005-04-14  7:45           ` Duncan Sands
     [not found]           ` <1113464720.9829.20.camel@localhost.localdomain>
2005-04-14 13:59             ` Marius Amado Alves
2005-04-14 14:09               ` Dr. Adrian Wrigley
2005-04-14 14:40                 ` (see below)
     [not found]             ` <389d1596e98f95f0fdddc40afc0647b7@netcabo.pt>
2005-04-14 14:14               ` Duncan Sands
2005-04-14 15:18         ` Robert A Duff
2005-04-14 15:24           ` Robert A Duff
2005-04-15  5:21             ` Randy Brukardt
2005-04-15 11:49               ` Dr. Adrian Wrigley
2005-04-15 13:21                 ` Dmitry A. Kazakov
2005-04-15 14:31                   ` Dr. Adrian Wrigley
2005-04-15 14:57                     ` Dmitry A. Kazakov
2005-04-14 15:39           ` Dr. Adrian Wrigley
2005-04-14 15:48           ` Dmitry A. Kazakov
2005-04-14 21:19             ` Robert A Duff
2005-04-15  8:23               ` Dmitry A. Kazakov
2005-04-15  8:38                 ` Duncan Sands
2005-04-15  9:16                   ` Dmitry A. Kazakov
2005-04-15 18:30               ` Mark Lorenzen
2005-04-15 19:06                 ` Robert A Duff
     [not found]       ` <iSSDSN2L04G1@VB1162.spb.edu>
2005-04-14  7:34         ` Duncan Sands
2005-04-13 22:35 ` Robert A Duff
2005-04-14 11:40   ` Dr. Adrian Wrigley
2005-04-14 10:44 ` Dr. Adrian Wrigley
2005-04-14 15:03   ` Robert A Duff
2005-04-14 16:46     ` Dmitry A. Kazakov
2005-04-14 18:30       ` Pascal Obry
2005-04-14 19:45         ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
2005-04-13 13:52 Duncan Sands
2005-04-13 14:20 ` Dr. Adrian Wrigley

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