aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2020-03-05 11:46:59 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2020-06-10 09:34:58 -0400
commitc64ac479d37f32198f75eee496d32c175fc4260b (patch)
tree85d00dc2b9d555ac89ace0bd3392574976a2e4f2
parent4322f3d99b7e5875de59c04939c4a4def1ffde5c (diff)
downloadgcc-c64ac479d37f32198f75eee496d32c175fc4260b.zip
gcc-c64ac479d37f32198f75eee496d32c175fc4260b.tar.gz
gcc-c64ac479d37f32198f75eee496d32c175fc4260b.tar.bz2
[Ada] Fold Enum_Rep attribute in evaluation and not in expansion
2020-06-10 Piotr Trojanek <trojanek@adacore.com> gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference): Remove folding for Enum_Rep attribute. * exp_spark.adb (Expand_SPARK_N_Attribute_Reference): Remove duplicated code for folding Enum_Rep attribute. * sem_attr.adb (Eval_Attribute): Relax condition for folding Enum_Rep attribute; previously dead code is now executed when the attribute prefix is an enumeration literal; refine type in processing of Enum_Val.
-rw-r--r--gcc/ada/exp_attr.adb15
-rw-r--r--gcc/ada/exp_spark.adb23
-rw-r--r--gcc/ada/sem_attr.adb8
3 files changed, 9 insertions, 37 deletions
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 67a18c6..356d3db 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -3159,17 +3159,8 @@ package body Exp_Attr is
Expr := Pref;
end if;
- -- If the expression is an enumeration literal, it is replaced by the
- -- literal value.
-
- if Nkind (Expr) in N_Has_Entity
- and then Ekind (Entity (Expr)) = E_Enumeration_Literal
- then
- Rewrite (N,
- Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Expr))));
-
- -- If not constant-folded above, Enum_Type'Enum_Rep (X) or
- -- X'Enum_Rep expands to
+ -- If not constant-folded, Enum_Type'Enum_Rep (X) or X'Enum_Rep
+ -- expands to
-- target-type (X)
@@ -3185,7 +3176,7 @@ package body Exp_Attr is
-- first convert to a small signed integer type in order not to lose
-- the size information.
- elsif Is_Enumeration_Type (Ptyp) then
+ if Is_Enumeration_Type (Ptyp) then
Psiz := RM_Size (Base_Type (Ptyp));
if Psiz < 8 then
diff --git a/gcc/ada/exp_spark.adb b/gcc/ada/exp_spark.adb
index c115a45..cab48f4 100644
--- a/gcc/ada/exp_spark.adb
+++ b/gcc/ada/exp_spark.adb
@@ -199,29 +199,6 @@ package body Exp_SPARK is
Parameter_Associations => New_List (Expr)));
Analyze_And_Resolve (N, Typ);
- -- Whenever possible, replace a prefix which is an enumeration literal
- -- by the corresponding literal value, just like it happens in the GNAT
- -- expander.
-
- elsif Attr_Id = Attribute_Enum_Rep then
- declare
- Exprs : constant List_Id := Expressions (N);
- begin
- if Is_Non_Empty_List (Exprs) then
- Expr := First (Exprs);
- else
- Expr := Prefix (N);
- end if;
-
- -- If the argument is a literal, expand it
-
- if Nkind (Expr) in N_Has_Entity
- and then Ekind (Entity (Expr)) = E_Enumeration_Literal
- then
- Exp_Attr.Expand_N_Attribute_Reference (N);
- end if;
- end;
-
elsif Attr_Id = Attribute_Object_Size
or else Attr_Id = Attribute_Size
or else Attr_Id = Attribute_Value_Size
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index e82082b..d2ac4c7 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -7719,7 +7719,11 @@ package body Sem_Attr is
-- purpose, a string literal counts as an object (attributes of string
-- literals can only appear in generated code).
- if Is_Object_Reference (P) or else Nkind (P) = N_String_Literal then
+ if Is_Object_Reference (P)
+ or else Nkind (P) = N_String_Literal
+ or else (Is_Entity_Name (P)
+ and then Ekind (Entity (P)) = E_Enumeration_Literal)
+ then
-- For Component_Size, the prefix is an array object, and we apply
-- the attribute to the type of the object. This is allowed for both
@@ -8533,7 +8537,7 @@ package body Sem_Attr is
--------------
when Attribute_Enum_Val => Enum_Val : declare
- Lit : Node_Id;
+ Lit : Entity_Id;
begin
-- We have something like Enum_Type'Enum_Val (23), so search for a