Fix PR ada/101970

This is a regression present on the mainline and 11 branch in the form of an
ICE for an enumeration type with a full signed representation for its size.

gcc/ada/
	PR ada/101970
	* exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_Enum_Rep>:
	Use an unchecked conversion instead of a regular conversion in the
	enumeration case and remove Conversion_OK flag in the integer case.
	<Attribute_Pos>: Remove superfluous test.

gcc/testsuite/
	* gnat.dg/enum_rep2.adb: New test.
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index f074521..fc6b0ef 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -3252,14 +3252,15 @@
          --  If not constant-folded, Enum_Type'Enum_Rep (X) or X'Enum_Rep
          --  expands to
 
-         --    target-type (X)
+         --    target-type!(X)
 
-         --  This is simply a direct conversion from the enumeration type to
-         --  the target integer type, which is treated by the back end as a
-         --  normal integer conversion, treating the enumeration type as an
-         --  integer, which is exactly what we want. We set Conversion_OK to
-         --  make sure that the analyzer does not complain about what otherwise
-         --  might be an illegal conversion.
+         --  This is an unchecked conversion from the enumeration type to the
+         --  target integer type, which is treated by the back end as a normal
+         --  integer conversion, treating the enumeration type as an integer,
+         --  which is exactly what we want. Unlike for the Pos attribute, we
+         --  cannot use a regular conversion since the associated check would
+         --  involve comparing the converted bounds, i.e. would involve the use
+         --  of 'Pos instead 'Enum_Rep for these bounds.
 
          --  However the target type is universal integer in most cases, which
          --  is a very large type, so in the case of an enumeration type, we
@@ -3267,11 +3268,13 @@
          --  the size information.
 
          if Is_Enumeration_Type (Ptyp) then
-            Rewrite (N, OK_Convert_To (Get_Integer_Type (Ptyp), Expr));
+            Rewrite (N, Unchecked_Convert_To (Get_Integer_Type (Ptyp), Expr));
             Convert_To_And_Rewrite (Typ, N);
 
+         --  Deal with integer types (replace by conversion)
+
          else
-            Rewrite (N, OK_Convert_To (Typ, Expr));
+            Rewrite (N, Convert_To (Typ, Expr));
          end if;
 
          Analyze_And_Resolve (N, Typ);
@@ -5420,7 +5423,7 @@
 
          --  Deal with integer types (replace by conversion)
 
-         elsif Is_Integer_Type (Etyp) then
+         else
             Rewrite (N, Convert_To (Typ, Expr));
          end if;
 
diff --git a/gcc/testsuite/gnat.dg/enum_rep2.adb b/gcc/testsuite/gnat.dg/enum_rep2.adb
new file mode 100644
index 0000000..6554ad4
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/enum_rep2.adb
@@ -0,0 +1,117 @@
+--  { dg-do compile }
+
+with Ada.Integer_Text_IO;
+with Ada.Text_IO;
+
+procedure Enum_Rep2 is
+
+   type T is
+     (E80, E81, E82, E83, E84, E85, E86, E87, E88, E89, E8A, E8B, E8C, E8D, E8E, E8F,
+      E90, E91, E92, E93, E94, E95, E96, E97, E98, E99, E9A, E9B, E9C, E9D, E9E, E9F,
+      EA0, EA1, EA2, EA3, EA4, EA5, EA6, EA7, EA8, EA9, EAA, EAB, EAC, EAD, EAE, EAF,
+      EB0, EB1, EB2, EB3, EB4, EB5, EB6, EB7, EB8, EB9, EBA, EBB, EBC, EBD, EBE, EBF,
+      EC0, EC1, EC2, EC3, EC4, EC5, EC6, EC7, EC8, EC9, ECA, ECB, ECC, ECD, ECE, ECF,
+      ED0, ED1, ED2, ED3, ED4, ED5, ED6, ED7, ED8, ED9, EDA, EDB, EDC, EDD, EDE, EDF,
+      EE0, EE1, EE2, EE3, EE4, EE5, EE6, EE7, EE8, EE9, EEA, EEB, EEC, EED, EEE, EEF,
+      EF0, EF1, EF2, EF3, EF4, EF5, EF6, EF7, EF8, EF9, EFA, EFB, EFC, EFD, EFE, EFF,
+      E00, E01, E02, E03, E04, E05, E06, E07, E08, E09, E0A, E0B, E0C, E0D, E0E, E0F,
+      E10, E11, E12, E13, E14, E15, E16, E17, E18, E19, E1A, E1B, E1C, E1D, E1E, E1F,
+      E20, E21, E22, E23, E24, E25, E26, E27, E28, E29, E2A, E2B, E2C, E2D, E2E, E2F,
+      E30, E31, E32, E33, E34, E35, E36, E37, E38, E39, E3A, E3B, E3C, E3D, E3E, E3F,
+      E40, E41, E42, E43, E44, E45, E46, E47, E48, E49, E4A, E4B, E4C, E4D, E4E, E4F,
+      E50, E51, E52, E53, E54, E55, E56, E57, E58, E59, E5A, E5B, E5C, E5D, E5E, E5F,
+      E60, E61, E62, E63, E64, E65, E66, E67, E68, E69, E6A, E6B, E6C, E6D, E6E, E6F,
+      E70, E71, E72, E73, E74, E75, E76, E77, E78, E79, E7A, E7B, E7C, E7D, E7E, E7F);
+   for T use
+     (E80 => -16#80#, E81 => -16#7F#, E82 => -16#7E#, E83 => -16#7D#,
+      E84 => -16#7C#, E85 => -16#7B#, E86 => -16#7A#, E87 => -16#79#,
+      E88 => -16#78#, E89 => -16#77#, E8A => -16#76#, E8B => -16#75#,
+      E8C => -16#74#, E8D => -16#73#, E8E => -16#72#, E8F => -16#71#,
+      
+      E90 => -16#70#, E91 => -16#6F#, E92 => -16#6E#, E93 => -16#6D#,
+      E94 => -16#6C#, E95 => -16#6B#, E96 => -16#6A#, E97 => -16#69#,
+      E98 => -16#68#, E99 => -16#67#, E9A => -16#66#, E9B => -16#65#,
+      E9C => -16#64#, E9D => -16#63#, E9E => -16#62#, E9F => -16#61#,
+      
+      EA0 => -16#60#, EA1 => -16#5F#, EA2 => -16#5E#, EA3 => -16#5D#,
+      EA4 => -16#5C#, EA5 => -16#5B#, EA6 => -16#5A#, EA7 => -16#59#,
+      EA8 => -16#58#, EA9 => -16#57#, EAA => -16#56#, EAB => -16#55#,
+      EAC => -16#54#, EAD => -16#53#, EAE => -16#52#, EAF => -16#51#,
+      
+      EB0 => -16#50#, EB1 => -16#4F#, EB2 => -16#4E#, EB3 => -16#4D#,
+      EB4 => -16#4C#, EB5 => -16#4B#, EB6 => -16#4A#, EB7 => -16#49#,
+      EB8 => -16#48#, EB9 => -16#47#, EBA => -16#46#, EBB => -16#45#,
+      EBC => -16#44#, EBD => -16#43#, EBE => -16#42#, EBF => -16#41#,
+      
+      EC0 => -16#40#, EC1 => -16#3F#, EC2 => -16#3E#, EC3 => -16#3D#,
+      EC4 => -16#3C#, EC5 => -16#3B#, EC6 => -16#3A#, EC7 => -16#39#,
+      EC8 => -16#38#, EC9 => -16#37#, ECA => -16#36#, ECB => -16#35#,
+      ECC => -16#34#, ECD => -16#33#, ECE => -16#32#, ECF => -16#31#,
+      
+      ED0 => -16#30#, ED1 => -16#2F#, ED2 => -16#2E#, ED3 => -16#2D#,
+      ED4 => -16#2C#, ED5 => -16#2B#, ED6 => -16#2A#, ED7 => -16#29#,
+      ED8 => -16#28#, ED9 => -16#27#, EDA => -16#26#, EDB => -16#25#,
+      EDC => -16#24#, EDD => -16#23#, EDE => -16#22#, EDF => -16#21#,
+      
+      EE0 => -16#20#, EE1 => -16#1F#, EE2 => -16#1E#, EE3 => -16#1D#,
+      EE4 => -16#1C#, EE5 => -16#1B#, EE6 => -16#1A#, EE7 => -16#19#,
+      EE8 => -16#18#, EE9 => -16#17#, EEA => -16#16#, EEB => -16#15#,
+      EEC => -16#14#, EED => -16#13#, EEE => -16#12#, EEF => -16#11#,
+      
+      EF0 => -16#10#, EF1 => -16#0F#, EF2 => -16#0E#, EF3 => -16#0D#,
+      EF4 => -16#0C#, EF5 => -16#0B#, EF6 => -16#0A#, EF7 => -16#09#,
+      EF8 => -16#08#, EF9 => -16#07#, EFA => -16#06#, EFB => -16#05#,
+      EFC => -16#04#, EFD => -16#03#, EFE => -16#02#, EFF => -16#01#,
+      
+      E00 => 16#00#, E01 => 16#01#, E02 => 16#02#, E03 => 16#03#,
+      E04 => 16#04#, E05 => 16#05#, E06 => 16#06#, E07 => 16#07#,
+      E08 => 16#08#, E09 => 16#09#, E0A => 16#0A#, E0B => 16#0B#,
+      E0C => 16#0C#, E0D => 16#0D#, E0E => 16#0E#, E0F => 16#0F#,
+      
+      E10 => 16#10#, E11 => 16#11#, E12 => 16#12#, E13 => 16#13#,
+      E14 => 16#14#, E15 => 16#15#, E16 => 16#16#, E17 => 16#17#,
+      E18 => 16#18#, E19 => 16#19#, E1A => 16#1A#, E1B => 16#1B#,
+      E1C => 16#1C#, E1D => 16#1D#, E1E => 16#1E#, E1F => 16#1F#,
+      
+      E20 => 16#20#, E21 => 16#21#, E22 => 16#22#, E23 => 16#23#,
+      E24 => 16#24#, E25 => 16#25#, E26 => 16#26#, E27 => 16#27#,
+      E28 => 16#28#, E29 => 16#29#, E2A => 16#2A#, E2B => 16#2B#,
+      E2C => 16#2C#, E2D => 16#2D#, E2E => 16#2E#, E2F => 16#2F#,
+      
+      E30 => 16#30#, E31 => 16#31#, E32 => 16#32#, E33 => 16#33#,
+      E34 => 16#34#, E35 => 16#35#, E36 => 16#36#, E37 => 16#37#,
+      E38 => 16#38#, E39 => 16#39#, E3A => 16#3A#, E3B => 16#3B#,
+      E3C => 16#3C#, E3D => 16#3D#, E3E => 16#3E#, E3F => 16#3F#,
+      
+      E40 => 16#40#, E41 => 16#41#, E42 => 16#42#, E43 => 16#43#,
+      E44 => 16#44#, E45 => 16#45#, E46 => 16#46#, E47 => 16#47#,
+      E48 => 16#48#, E49 => 16#49#, E4A => 16#4A#, E4B => 16#4B#,
+      E4C => 16#4C#, E4D => 16#4D#, E4E => 16#4E#, E4F => 16#4F#,
+      
+      E50 => 16#50#, E51 => 16#51#, E52 => 16#52#, E53 => 16#53#,
+      E54 => 16#54#, E55 => 16#55#, E56 => 16#56#, E57 => 16#57#,
+      E58 => 16#58#, E59 => 16#59#, E5A => 16#5A#, E5B => 16#5B#,
+      E5C => 16#5C#, E5D => 16#5D#, E5E => 16#5E#, E5F => 16#5F#,
+      
+      E60 => 16#60#, E61 => 16#61#, E62 => 16#62#, E63 => 16#63#,
+      E64 => 16#64#, E65 => 16#65#, E66 => 16#66#, E67 => 16#67#,
+      E68 => 16#68#, E69 => 16#69#, E6A => 16#6A#, E6B => 16#6B#,
+      E6C => 16#6C#, E6D => 16#6D#, E6E => 16#6E#, E6F => 16#6F#,
+      
+      E70 => 16#70#, E71 => 16#71#, E72 => 16#72#, E73 => 16#73#,
+      E74 => 16#74#, E75 => 16#75#, E76 => 16#76#, E77 => 16#77#,
+      E78 => 16#78#, E79 => 16#79#, E7A => 16#7A#, E7B => 16#7B#,
+      E7C => 16#7C#, E7D => 16#7D#, E7E => 16#7E#, E7F => 16#7F#);
+   for T'Size use 8;
+
+   procedure Print (X : T) is
+   begin
+      Ada.Integer_Text_IO.Put (T'Pos (X));
+      Ada.Integer_Text_IO.Put (T'Enum_Rep (X));
+      Ada.Text_IO.New_Line;
+   end;
+
+begin
+   Print (T'First);
+   Print (T'Last);
+end;