This is a regression present on the mainline and 4.9 branch for a corner case: 
a superflat array indexed by an enumeration type with representation clause.

Tested on x86_64-suse-linux, applied on the mainline and 4.9 branch.


2014-05-18  Eric Botcazou  <ebotca...@adacore.com>

        * gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Subtype>: Do not
        consider that regular packed arrays can never be superflat.


2014-05-18  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/enum3.adb: New test.


-- 
Eric Botcazou
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 210579)
+++ gcc-interface/decl.c	(working copy)
@@ -2420,8 +2420,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 		 we can just use the high bound of the index type.  */
 	      else if ((Nkind (gnat_index) == N_Range
 		        && cannot_be_superflat_p (gnat_index))
-		       /* Packed Array Types are never superflat.  */
-		       || Is_Packed_Array_Type (gnat_entity))
+		       /* Bit-Packed Array Types are never superflat.  */
+		       || (Is_Packed_Array_Type (gnat_entity)
+			   && Is_Bit_Packed_Array
+			      (Original_Array_Type (gnat_entity))))
 		gnu_high = gnu_max;
 
 	      /* Otherwise, if the high bound is constant but the low bound is
-- { dg-do run }

procedure Enum3 is
   type Enum is (Aaa, Bbb, Ccc);
   for Enum use (1,2,4);
begin
   for Lo in Enum loop
      for Hi in Enum loop
         declare
            subtype S is Enum range Lo .. Hi;
            type Vector is array (S) of Integer;
            Vec : Vector;
         begin
            for I in S loop
               Vec (I) := 0;
            end loop;
            if Vec /= (S => 0) then
               raise Program_Error;
            end if;
         end;
      end loop;
   end loop;
end;

Reply via email to