public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/guojiufu/heads/guojiufu-branch)] [Ada] Fix handling of 'Enum_Rep and renamings
@ 2020-06-10 3:44 Jiu Fu Guo
0 siblings, 0 replies; only message in thread
From: Jiu Fu Guo @ 2020-06-10 3:44 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:8eda13a49e566270f04323dbec11b2e86d3ddccc
commit 8eda13a49e566270f04323dbec11b2e86d3ddccc
Author: Arnaud Charlet <charlet@adacore.com>
Date: Fri Feb 14 11:50:12 2020 -0500
[Ada] Fix handling of 'Enum_Rep and renamings
2020-06-08 Arnaud Charlet <charlet@adacore.com>
gcc/ada/
* sem_eval.adb (Eval_Type_Conversion): Fix handling of
enumeration to integer conversions.
* exp_attr.adb (Expand_N_Attribute_Reference
[Attribute_Enum_Rep]): Remove special casing for first-level
renaming, best left to the general folding mechanism via
Eval_Type_Conversion.
Diff:
---
gcc/ada/exp_attr.adb | 15 ---------------
gcc/ada/sem_eval.adb | 8 ++++++--
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index aac5972c6f9..c282e767ad6 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -3168,21 +3168,6 @@ package body Exp_Attr is
Rewrite (N,
Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Expr))));
- -- If this is a renaming of a literal, recover the representation
- -- of the original. If it renames an expression there is nothing to
- -- fold.
-
- elsif Nkind (Expr) in N_Has_Entity
- and then Ekind (Entity (Expr)) = E_Constant
- and then Present (Renamed_Object (Entity (Expr)))
- and then Is_Entity_Name (Renamed_Object (Entity (Expr)))
- and then Ekind (Entity (Renamed_Object (Entity (Expr)))) =
- E_Enumeration_Literal
- then
- Rewrite (N,
- Make_Integer_Literal (Loc,
- Enumeration_Rep (Entity (Renamed_Object (Entity (Expr))))));
-
-- If not constant-folded above, Enum_Type'Enum_Rep (X) or
-- X'Enum_Rep expands to
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index 2fab4bb9a6f..96d6b9315ff 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -4031,8 +4031,13 @@ package body Sem_Eval is
-- Real to integer conversion
- else
+ elsif To_Be_Treated_As_Real (Source_Type) then
Result := UR_To_Uint (Expr_Value_R (Operand));
+
+ -- Enumeration to integer conversion, aka 'Enum_Rep
+
+ else
+ Result := Expr_Rep_Value (Operand);
end if;
-- If fixed-point type (Conversion_OK must be set), then the
@@ -4076,7 +4081,6 @@ package body Sem_Eval is
if Is_Out_Of_Range (N, Etype (N), Assume_Valid => True) then
Out_Of_Range (N);
end if;
-
end Eval_Type_Conversion;
-------------------
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-06-10 3:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10 3:44 [gcc(refs/users/guojiufu/heads/guojiufu-branch)] [Ada] Fix handling of 'Enum_Rep and renamings Jiu Fu Guo
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).