]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
sem_ch4.adb (Is_Empty_Range): Use bounds of index type to determine whether an array...
authorEd Schonberg <schonberg@adacore.com>
Tue, 2 Oct 2012 08:10:54 +0000 (08:10 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Tue, 2 Oct 2012 08:10:54 +0000 (10:10 +0200)
2012-10-02  Ed Schonberg  <schonberg@adacore.com>

* sem_ch4.adb (Is_Empty_Range): Use bounds of index type
to determine whether an array is empty when optimizing
a quantified expression over a null range. Use of RM_Size
was incorrect. Analyze condition before constant-folding the
expression to catch potential errors. Modify the error message
to avoid mathematical terminology.

From-SVN: r191958

gcc/ada/ChangeLog
gcc/ada/sem_ch4.adb

index 99ee5a2b27ead144899d43131e3e041ba9862191..fa0c5153003703f58c5333948e677f61d2885fa4 100644 (file)
@@ -1,3 +1,12 @@
+2012-10-02  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch4.adb (Is_Empty_Range): Use bounds of index type
+       to determine whether an array is empty when optimizing
+       a quantified expression over a null range. Use of RM_Size
+       was incorrect. Analyze condition before constant-folding the
+       expression to catch potential errors. Modify the error message
+       to avoid mathematical terminology.
+
 2012-10-02  Robert Dewar  <dewar@adacore.com>
 
        * usage.adb, gnat_rm.texi, vms_data.ads: Add entry for
index 93f6d3684464c7b48ccfeb20c235e6c5db71f034..ef13222b83e40339092930e461c4ef69a003db4a 100644 (file)
@@ -3404,27 +3404,37 @@ package body Sem_Ch4 is
    procedure Analyze_Quantified_Expression (N : Node_Id) is
       QE_Scop : Entity_Id;
 
-      function  Is_Empty_Range (Typ : Entity_Id) return Boolean;
+      function Is_Empty_Range (Typ : Entity_Id) return Boolean;
       --  If the iterator is part of a quantified expression, and the range is
       --  known to be statically empty, emit a warning and replace expression
-      --  with its static value.
+      --  with its static value. Returns True if the replacement occurs.
 
-      function  Is_Empty_Range (Typ : Entity_Id) return Boolean is
-         Loc     : constant Source_Ptr := Sloc (N);
+      --------------------
+      -- Is_Empty_Range --
+      --------------------
+
+      function Is_Empty_Range (Typ : Entity_Id) return Boolean is
+         Loc : constant Source_Ptr := Sloc (N);
 
       begin
          if Is_Array_Type (Typ)
-           and then Size_Known_At_Compile_Time (Typ)
-           and then RM_Size (Typ) = 0
+           and then Compile_Time_Known_Bounds (Typ)
+           and then
+             (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ))))
+               > Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
          then
+            Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
+
             if All_Present (N) then
-               Error_Msg_N ("?universal quantified expression "
-               & "over a null range has value True", N);
+               Error_Msg_N
+                 ("?quantified expression with ALL "
+                  & "over a null range has value True", N);
                Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
 
             else
-               Error_Msg_N ("?existential quantified expression "
-               & "over a null range has value False", N);
+               Error_Msg_N
+                 ("?quantified expression with SOME "
+                  & "over a null range has value False", N);
                Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
             end if;
 
@@ -3436,6 +3446,8 @@ package body Sem_Ch4 is
          end if;
       end Is_Empty_Range;
 
+   --  Start of processing for Analyze_Quantified_Expression
+
    begin
       Check_SPARK_Restriction ("quantified expression is not allowed", N);