[Ada] Crash when attribute declared in an unknown package

Arnaud Charlet charlet@adacore.com
Thu Jan 28 14:08:00 GMT 2010


When in a project file an attribute is declared in an unknown package
that has already been seen elsewhere, the Project Manager crashes with
Storage_Error.
The test for this is to invoke
   gnatmake -q -P prj2.gpr
It should succeed silently.

with "prj.gpr";
project Prj2 is
   for Source_Files use ();
   package Link is
      for Switches use ("toto");
   end Link;
end Prj2;

project Prj is
   for Source_Files use ();
   package Link is
      for Switches use ("toto");
   end Link;
end Prj;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-01-28  Vincent Celier  <celier@adacore.com>

	* prj-attr-pm.adb (Add_Attribute): Do nothing if To_Package is
	Unknown_Package.

-------------- next part --------------
Index: prj-attr-pm.adb
===================================================================
--- prj-attr-pm.adb	(revision 156313)
+++ prj-attr-pm.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2004-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 2004-2010, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -35,19 +35,21 @@ package body Prj.Attr.PM is
       Attribute_Node : out Attribute_Node_Id)
    is
    begin
-      --  Only add the attribute if the package is already defined
+      --  Only add attribute if package is already defined and is not unknown
+
+      if To_Package /= Empty_Package   and then
+         To_Package /= Unknown_Package
+      then
+         Attrs.Append (
+           (Name           => Attribute_Name,
+            Var_Kind       => Undefined,
+            Optional_Index => False,
+            Attr_Kind      => Unknown,
+            Read_Only      => False,
+            Others_Allowed => False,
+            Next           =>
+              Package_Attributes.Table (To_Package.Value).First_Attribute));
 
-      if To_Package /= Empty_Package then
-         Attrs.Increment_Last;
-         Attrs.Table (Attrs.Last) :=
-           (Name              => Attribute_Name,
-            Var_Kind          => Undefined,
-            Optional_Index    => False,
-            Attr_Kind         => Unknown,
-            Read_Only         => False,
-            Others_Allowed    => False,
-            Next              =>
-              Package_Attributes.Table (To_Package.Value).First_Attribute);
          Package_Attributes.Table (To_Package.Value).First_Attribute :=
            Attrs.Last;
          Attribute_Node := (Value => Attrs.Last);


More information about the Gcc-patches mailing list