* [COMMITTED] ada: Evaluate static expressions in Range attributes
@ 2023-07-06 11:39 Marc Poulhiès
0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-07-06 11:39 UTC (permalink / raw)
To: gcc-patches; +Cc: Viljar Indus
From: Viljar Indus <indus@adacore.com>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_attr.adb | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 7a47abdb625..e00addd0152 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -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)
--
2.40.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-06 11:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 11:39 [COMMITTED] ada: Evaluate static expressions in Range attributes Marc Poulhiès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).