[PATCH] ada/15915: Storage_Pool attribute must denote a variable

Samuel Tardieu sam@rfc1149.net
Fri Apr 11 19:48:00 GMT 2008


GNAT didn't check that the storage pool attributes denotes a variable,
as mandated by RM 13.11(15). The test program, which previously compiled
without error, now gives:

     6.    for T1'Storage_Pool use (x1);
                                    |
        >>> storage pool must denote a variable

Regtested on i686-pc-linux-gnu.

Ok for trunk?

    gcc/ada/
	* sem_util.ads, sem_util.adb (Denotes_Variable): New function.
	* sem_ch12.adb (Instantiate_Object): Use it.
	* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Ensure that
	storage pool denotes a variable as per RM 13.11(15).

    gcc/testsuite/
	* gnat.dg/specs/storage.ads: New.
---
 gcc/ada/sem_ch12.adb                    |    2 +-
 gcc/ada/sem_ch13.adb                    |    5 +++++
 gcc/ada/sem_util.adb                    |    9 +++++++++
 gcc/ada/sem_util.ads                    |    3 +++
 gcc/testsuite/gnat.dg/specs/storage.ads |    8 ++++++++
 5 files changed, 26 insertions(+), 1 deletions(-)
 create mode 100644 gcc/testsuite/gnat.dg/specs/storage.ads

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index b22af91..3ee96d1 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -8212,7 +8212,7 @@ package body Sem_Ch12 is
 
          Resolve (Actual, Ftyp);
 
-         if not Is_Variable (Actual) or else Paren_Count (Actual) > 0 then
+         if not Denotes_Variable (Actual) then
             Error_Msg_NE
               ("actual for& must be a variable", Actual, Formal_Id);
 
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 1b6eece..f366112 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -1478,6 +1478,11 @@ package body Sem_Ch13 is
                return;
             end if;
 
+            if not Denotes_Variable (Expr) then
+               Error_Msg_N ("storage pool must denote a variable", Expr);
+               return;
+            end if;
+
             Analyze_And_Resolve
               (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
 
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 38796a6..0bb7c28 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -2143,6 +2143,15 @@ package body Sem_Util is
 
    end Denotes_Discriminant;
 
+   ----------------------
+   -- Denotes_Variable --
+   ----------------------
+
+   function Denotes_Variable (N : Node_Id) return Boolean is
+   begin
+      return Is_Variable (N) and then Paren_Count (N) = 0;
+   end Denotes_Variable;
+
    -----------------------------
    -- Depends_On_Discriminant --
    -----------------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index cf771d8..e434f28 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -245,6 +245,9 @@ package Sem_Util is
    --  components of protected types, and constraint checks on entry
    --  families constrained by discriminants.
 
+   function Denotes_Variable (N : Node_Id) return Boolean;
+   --  Returns True if node N denotes a single variable without parentheses.
+
    function Depends_On_Discriminant (N : Node_Id) return Boolean;
    --  Returns True if N denotes a discriminant or if N is a range, a subtype
    --  indication or a scalar subtype where one of the bounds is a
diff --git a/gcc/testsuite/gnat.dg/specs/storage.ads b/gcc/testsuite/gnat.dg/specs/storage.ads
new file mode 100644
index 0000000..4793ee8
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/storage.ads
@@ -0,0 +1,8 @@
+-- { dg-do compile }
+with System.Pool_Global;
+package Storage is
+   x1: System.Pool_Global.Unbounded_No_Reclaim_Pool;
+   type T1 is access integer;
+   for T1'Storage_Pool use (x1);  -- { dg-error "denote a variable" }
+end Storage;
+
-- 
1.5.5.144.g3e42



More information about the Gcc-patches mailing list