Patchwork [Ada] Allocation from empty storage pool is error, not warning

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 7, 2010, 1:06 p.m.
Message ID <20101007130630.GA14031@adacore.com>
Download mbox | patch
Permalink /patch/67053/
State New
Headers show

Comments

Arnaud Charlet - Oct. 7, 2010, 1:06 p.m.
Ada specifies that allocation from an empty storage pool (one for which
a static storage size of zero was given) is an error, but previously we
were just generating a warning. This patch corrects that oversight.

The following shows the new error message (compiled with -gnat05)

     1. procedure BadUCnew is
     2.    type R is access all integer;
     3.    for R'Storage_Size use 0;
     4.    RR : R;
     5. begin
     6.    RR := new Integer'(3);
                 |
        >>> allocation from empty storage pool

     7. end;

Note: the patch restricts these messages to static expressions with a
value of zero to correspond exactly to the language rules.

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

2010-10-07  Robert Dewar  <dewar@adacore.com>

	* einfo.ads (No_Pool_Assigned): Update documentation.
	* sem_ch13.adb (Analyze_Attribute_Definition_Clause, case
	Storage_Size): We only set No_Pool_Assigned if the expression is a
	static constant and zero.
	* sem_res.adb (Resolve_Allocator): Allocation from empty storage pool
	should be an error not a warning.

Patch

Index: einfo.ads
===================================================================
--- einfo.ads	(revision 165082)
+++ einfo.ads	(working copy)
@@ -3035,12 +3035,12 @@  package Einfo is
 --       interpreted as true. Currently this is set true for derived Boolean
 --       types which have a convention of C, C++ or Fortran.
 
---    No_Pool_Assigned (Flag131) [root type only]
---       Present in access types. Set if a storage size clause applies to
---       the variable with a compile time known value of zero. This flag is
---       used to generate warnings if any attempt is made to allocate or free
---       an instance of such an access type. This is set only in the root
---       type, since derived types must have the same pool.
+--    No_Pool_Assigned (Flag131) [root type only] Present in access types.
+--       Set if a storage size clause applies to the variable with a static
+--       expression value of zero. This flag is used to generate errors if any
+--       attempt is made to allocate or free an instance of such an access
+--       type. This is set only in the root type, since derived types must
+--       have the same pool.
 
 --    No_Return (Flag113)
 --       Present in all entities. Always false except in the case of procedures
Index: sem_res.adb
===================================================================
--- sem_res.adb	(revision 165092)
+++ sem_res.adb	(working copy)
@@ -4296,15 +4296,7 @@  package body Sem_Res is
       --  Check for allocation from an empty storage pool
 
       if No_Pool_Assigned (Typ) then
-         declare
-            Loc : constant Source_Ptr := Sloc (N);
-         begin
-            Error_Msg_N ("?allocation from empty storage pool!", N);
-            Error_Msg_N ("\?Storage_Error will be raised at run time!", N);
-            Insert_Action (N,
-              Make_Raise_Storage_Error (Loc,
-                Reason => SE_Empty_Storage_Pool));
-         end;
+         Error_Msg_N ("allocation from empty storage pool!", N);
 
       --  If the context is an unchecked conversion, as may happen within
       --  an inlined subprogram, the allocator is being resolved with its
Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb	(revision 165084)
+++ sem_ch13.adb	(working copy)
@@ -1859,7 +1859,7 @@  package body Sem_Ch13 is
                      return;
                   end if;
 
-                  if Compile_Time_Known_Value (Expr)
+                  if Is_OK_Static_Expression (Expr)
                     and then Expr_Value (Expr) = 0
                   then
                      Set_No_Pool_Assigned (Btype);