This fixes a failure to properly diagnose a bad Depends operand.
The following program used to provoke this crash:

     1. procedure DependsCrash is
     2.    type R is record
     3.       B : Boolean;
     4.    end record;
     5.
     6.    procedure Test (X : R; B : out Boolean)
                           |
        >>> item "X" must appear in at least one input list
            of aspect Depends

     7.      with Depends => (B => X.B);
                                    |
        >>> item must denote variable, state or formal
            parameter

     8.
     9.    procedure Test (X : R; B : out Boolean)
    10.    is begin null; end;
    11.
    12. begin
    13.    null;
    14. end DependsCrash;

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

2014-01-24  Robert Dewar  <de...@adacore.com>

        * sem_prag.adb (Analyze_Input_Output): Add missing error check
        for junk operand.
        * sem_util.adb (Is_Refined_State): Add defense against junk
        tree from error.

Index: sem_prag.adb
===================================================================
--- sem_prag.adb        (revision 207026)
+++ sem_prag.adb        (working copy)
@@ -783,9 +783,9 @@
 
                Item_Id := Entity_Of (Item);
 
-               Record_Possible_Body_Reference (Item, Item_Id);
+               if Present (Item_Id) then
+                  Record_Possible_Body_Reference (Item, Item_Id);
 
-               if Present (Item_Id) then
                   if Ekind_In (Item_Id, E_Abstract_State,
                                         E_In_Parameter,
                                         E_In_Out_Parameter,
Index: sem_util.adb
===================================================================
--- sem_util.adb        (revision 207026)
+++ sem_util.adb        (working copy)
@@ -3723,6 +3723,12 @@
          else
             Item_Id := Entity_Of (Item);
 
+            --  Defend against junk
+
+            if No (Item_Id) then
+               return False;
+            end if;
+
             return
               Ekind (Item_Id) = E_Abstract_State
                 and then Has_Visible_Refinement (Item_Id);

Reply via email to