[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Possible gnat-4.9 bug? Need a sanity check before I report it...



Experimenting with Gela as an ASIS implementation, I am finding
incorrect code generation with -O2 but correct without optimisation.

To reproduce...

0) My environment:
------------------------------------------------------------------------
uname -a
Linux Sparrowhawk 3.14-1-amd64 #1 SMP Debian 3.14.7-1 (2014-06-16)
x86_64 GNU/Linux
------------------------------------------------------------------------
gnat --version
GNAT 4.9
Copyright 1996-2014, Free Software Foundation, Inc.
------------------------------------------------------------------------
( via apt-get -t testing install gnat-4.9 )

1) From webpage http://gela.ada-ru.org/gela_asis
download and unpack the latest release (640kB)
http://www.ada-ru.org/files/gela-asis-0.3.2.tar.bz2

2) 
cd gela-asis-0.3.2
make generate

Symptoms:  it builds a (faulty) xml2ayacc, uses it to parse an Ada-2005
grammar written in XML, then xml2ayacc falls over with
------------------------------------------------------------------------
raised CONSTRAINT_ERROR : generate.adb:628 range check failed
------------------------------------------------------------------------

3) edit gela-asis-0.3.2/Makefile removing -O2 flag
----------------------------------
# gnatmake flags:
FLAGS            ?= -j0 -g -m 
# -O2 
----------------------------------
make clean
make generate
and it runs cleanly.




So the questions are: 
1) can anyone else reproduce it?
2) should I report as a Gnat bug?
3) If the latter (see below) would it be better to report it to Debian,
or gcc?

I have narrowed the problem down to one procedure, Find_Node, in
gela-asis-0.3.2/tools/xml2ayacc/nodes-database.adb

which, called with Name="_Node" 
returns Node= <random out-of-range value> and Found=true, e.g.
----------------------------------
Name _node node  7984 found? TRUE
----------------------------------

The valid range is declared as:
   type Node_Index is range 1 .. 250;
in gela-asis-0.3.2/tools/xml2ayacc/nodes-database.ads 

   procedure Find_Node
     (Name  : in     String;
      Node  :    out Node_Index;
      Found :    out Boolean)
   is
   begin
      for I in 1 .. Last_Node_Index loop
         if All_Nodes (I).Name = Name then
            Node := I;
            Found := True;
            return;
         end if;
      end loop;
      Found := False;
   end Find_Node;

Caller is function Get_Node_Type_Name from
gela-asis-0.3.2/tools/xml2ayacc/nodes.adb

   function Get_Node_Type_Name (Name : String) return String is
      use Nodes.Database;
      use Ada.Strings.Fixed;

      Type_Name : constant String := Capitalise (Name & "_Node");
      Node      : Node_Index;
      Found     : Boolean;
   begin
      ...
      Find_Node (Type_Name, Node, Found);
      -- diagnostics added...
      Put_Line ("Name " & Type_Name & " node " &
          Node_Index'image(Node) & " found? " & boolean'image(Found));
      ... rest of function irrelevant

So Get_Node_Type_Name called with an empty Name will search for "_Node",
which isn't very smart, but never mind...

Now my reading of Find_Node is that the only ways out are with Node
correctly set to an in-range value and Found=True, or with Node
uninitialised and Found=False. 

However at -O2 we find Node uninitialised and Found=True.
Initalising Node to 1 makes the problem "go away" but that's not a
satisfactory solution.

Adding -gnato to the compiler flags makes no effect I can see.

My own build of upstream gnat-4.9 (prerelease snapshot) does the same;
my own build of upstream gnat-4.8.2 does not, so I am leaning towards
the view that it's a Gnat-4.9 regression.
I haven't tried any of the Adacore builds.

Any light anyone can shed on this?

- Brian





Reply to: