public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2071] [Ada] Fix bug in casing on composite values with -gnatX
@ 2021-07-06 14:49 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-07-06 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c6d8890c7d1e717c2f8ed5f2b04ca5a9b26cdfc1

commit r12-2071-gc6d8890c7d1e717c2f8ed5f2b04ca5a9b26cdfc1
Author: Steve Baird <baird@adacore.com>
Date:   Tue May 11 14:27:09 2021 -0700

    [Ada] Fix bug in casing on composite values with -gnatX
    
    gcc/ada/
    
            * exp_ch5.adb
            (Expand_N_Case_Statement.Expand_General_Case_Statement.Pattern_Match):
            When generating an equality test for a statically known discrete
            value, only generate the numeric value if the discrete type is
            not an enumeration type.  If it is an enumeration type, then
            call Get_Enum_Lit_From_Pos instead.

Diff:
---
 gcc/ada/exp_ch5.adb | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index 3e65084c65f..2559e56b90a 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -3384,9 +3384,17 @@ package body Exp_Ch5 is
               and then Is_Discrete_Type (Etype (Pattern))
               and then Compile_Time_Known_Value (Pattern)
             then
-               return Make_Op_Eq (Loc,
-                        Object,
-                        Make_Integer_Literal (Loc, Expr_Value (Pattern)));
+               declare
+                  Val : Node_Id;
+               begin
+                  if Is_Enumeration_Type (Etype (Pattern)) then
+                     Val := Get_Enum_Lit_From_Pos
+                              (Etype (Pattern), Expr_Value (Pattern), Loc);
+                  else
+                     Val := Make_Integer_Literal (Loc, Expr_Value (Pattern));
+                  end if;
+                  return Make_Op_Eq (Loc, Object, Val);
+               end;
             end if;
 
             case Nkind (Pattern) is


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-06 14:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 14:49 [gcc r12-2071] [Ada] Fix bug in casing on composite values with -gnatX Pierre-Marie de Rodat

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).