[Ada] Do not use Long_Long_Long_Integer'Image with pragma Discard_Names
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 4 Sep 2020 10:34:02 +0000 (12:34 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 23 Oct 2020 08:24:58 +0000 (04:24 -0400)
gcc/ada/

* exp_imgv.adb (Expand_Image_Attribute): For an enumeration type
subject to pragma Discard_Names, convert 'Pos to Long_Long_Integer
before applying 'Img to the result.

gcc/ada/exp_imgv.adb

index 5850b5d2fe140cc2645f044694fc663986053b53..40cb51462b8352f79c69a92af3c53419f7065b8b 100644 (file)
@@ -619,15 +619,18 @@ package body Exp_Imgv is
            or else No (Lit_Strings (Rtyp))
          then
             --  When pragma Discard_Names applies to the first subtype, build
-            --  (Pref'Pos (Expr))'Img.
+            --  (Long_Long_Integer (Pref'Pos (Expr)))'Img. The conversion is
+            --  there to avoid applying 'Img directly in Universal_Integer,
+            --  which can be a very large type. See also the handling of 'Val.
 
             Rewrite (N,
               Make_Attribute_Reference (Loc,
                 Prefix =>
-                   Make_Attribute_Reference (Loc,
-                     Prefix         => Pref,
-                     Attribute_Name => Name_Pos,
-                     Expressions    => New_List (Expr)),
+                  Convert_To (Standard_Long_Long_Integer,
+                    Make_Attribute_Reference (Loc,
+                    Prefix         => Pref,
+                    Attribute_Name => Name_Pos,
+                    Expressions    => New_List (Expr))),
                 Attribute_Name =>
                   Name_Img));
             Analyze_And_Resolve (N, Standard_String);