I see this problem with mainline and with GNAT GPL 2007.
A pointer is not being default initialized to NULL in
Ada.Containers.Hashed_Maps. This causes segmentation faults
on large programs. On the small testcase (see end of message)
you need valgrind to see it, since almost always you get NULL
by accident. This problem seems awfully similar to ACT bug
EA23-003.
Note that in Ada.Containers.Hashed_Maps.Insert.New_Node there is
return new Node_Type'(Key => Key,
Element => <>,
Next => Next);
If I get rid of the <> then the problem goes away.
$ gnatmake -gnat05 p
gcc -c -gnat05 p.adb
gnatbind -x p.ali
gnatlink p.ali
$ valgrind --tool=memcheck ./p
...
==25467== Conditional jump or move depends on uninitialised value(s)
==25467== at 0x804AA2F: _ada_p (in /home/duncan/Programming/Bugs/bug_103/p)
==25467== by 0x80497F6: main (in /home/duncan/Programming/Bugs/bug_103/p)
Testcase:
--chop here--
with Ada.Containers.Hashed_Maps;
procedure P is
function H (I : Integer) return Ada.Containers.Hash_Type is
begin
return Ada.Containers.Hash_Type'Mod (I);
end;
type Item_Pointer is access Boolean;
package M is new Ada.Containers.Hashed_Maps (Integer, Item_Pointer, H, "=");
Z : M.Map;
Position : M.Cursor;
Inserted : Boolean;
Item : Item_Pointer;
begin
M.Insert (Z, 2, Position, Inserted); -- default initialization for new item
Item := M.Element (Position);
if Item = null then -- Item contains a random value here
Item := new Boolean;
end if;
end;
--
Summary: Default pointer initialization not occuring - due to the
use of <>
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: baldrick at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32234