]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
s-stausa.adb (Fill_Stack): Fixed pragma assert and top pattern mark in the case of...
authorQuentin Ochem <ochem@adacore.com>
Wed, 6 Aug 2008 08:32:09 +0000 (10:32 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Wed, 6 Aug 2008 08:32:09 +0000 (10:32 +0200)
2008-08-06  Quentin Ochem  <ochem@adacore.com>

* s-stausa.adb (Fill_Stack): Fixed pragma assert and top pattern mark
in the case of an empty pattern size.
(Compute_Result): Do not do any computation in the case of an empty
pattern size.
(Report_Result): Fixed computation of the overflow guard.

From-SVN: r138771

gcc/ada/s-stausa.adb

index d9b972d8b2899d9edb94eb9340501c2c8c2483f4..ff5f86e1668c7cfb19d2631e9384dae97f18dd24 100644 (file)
@@ -298,7 +298,7 @@ package body System.Stack_Usage is
               To_Stack_Address (Stack (Top_Slot_Index_In (Stack))'Address);
          else
             Analyzer.Bottom_Pattern_Mark := To_Stack_Address (Stack'Address);
-            Analyzer.Bottom_Pattern_Mark := To_Stack_Address (Stack'Address);
+            Analyzer.Top_Pattern_Mark := To_Stack_Address (Stack'Address);
          end if;
 
          --  If Arr has been packed, the following assertion must be true (we
@@ -306,7 +306,8 @@ package body System.Stack_Usage is
          --    Min (Analyzer.Inner_Pattern_Mark, Analyzer.Outer_Pattern_Mark)):
 
          pragma Assert
-           (Analyzer.Pattern_Size =
+           (Analyzer.Pattern_Size = 0 or else
+            Analyzer.Pattern_Size =
               Stack_Size
                 (Analyzer.Top_Pattern_Mark, Analyzer.Bottom_Pattern_Mark));
       end;
@@ -381,6 +382,10 @@ package body System.Stack_Usage is
    begin
       Analyzer.Topmost_Touched_Mark := Analyzer.Bottom_Pattern_Mark;
 
+      if Analyzer.Pattern_Size = 0 then
+         return;
+      end if;
+
       --  Look backward from the topmost possible end of the marked stack to
       --  the bottom of it. The first index not equals to the patterns marks
       --  the beginning of the used stack.
@@ -559,20 +564,23 @@ package body System.Stack_Usage is
                    Min_Measure    => 0,
                    Max_Measure    => 0);
 
+      Overflow_Guard : constant Integer :=
+        Analyzer.Stack_Size
+          - Stack_Size (Analyzer.Top_Pattern_Mark, Analyzer.Bottom_Of_Stack);
+
    begin
       if Analyzer.Pattern_Size = 0 then
          --  If we have that result, it means that we didn't do any computation
          --  at all. In other words, we used at least everything (and possibly
          --  more).
 
-         Result.Min_Measure := Analyzer.Stack_Size;
+         Result.Min_Measure := Analyzer.Stack_Size - Overflow_Guard;
          Result.Max_Measure := Analyzer.Stack_Size;
       else
          Result.Min_Measure := Stack_Size
                     (Analyzer.Topmost_Touched_Mark,
                      Analyzer.Bottom_Of_Stack);
-         Result.Max_Measure := Result.Min_Measure +
-           (Analyzer.Stack_Size - Analyzer.Pattern_Size);
+         Result.Max_Measure := Result.Min_Measure + Overflow_Guard;
       end if;
 
       if Analyzer.Result_Id in Result_Array'Range then