]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Evaluate static expressions in Range attributes
authorViljar Indus <indus@adacore.com>
Wed, 21 Jun 2023 13:22:37 +0000 (16:22 +0300)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 6 Jul 2023 11:36:10 +0000 (13:36 +0200)
Gigi assumes that the value of range expressions is an integer literal.
Force evaluation of such expressions since static non-literal expressions
are not always evaluated to a literal form by gnat.

gcc/ada/

* sem_attr.adb (analyze_attribute.check_array_type): Replace valid
indexes with their staticly evaluated values.

gcc/ada/sem_attr.adb

index 7a47abdb625c5cce666dd23398a8c62cc9ef0d31..e00addd0152f90cc889c90a31db4c2a286f1a5e3 100644 (file)
@@ -2013,10 +2013,20 @@ package body Sem_Attr is
                Flag_Non_Static_Expr
                  ("expression for dimension must be static!", E1);
                Error_Attr;
-
-            elsif Expr_Value (E1) > D or else Expr_Value (E1) < 1 then
-               Error_Attr ("invalid dimension number for array type", E1);
             end if;
+
+            declare
+               Value : constant Uint := Expr_Value (E1);
+            begin
+
+               if Value > D or else Value < 1 then
+                  Error_Attr ("invalid dimension number for array type", E1);
+               end if;
+
+               --  Replace the static value to simplify the tree for gigi
+               Fold_Uint (E1, Value, True);
+            end;
+
          end if;
 
          if (Style_Check and Style_Check_Array_Attribute_Index)