This is a regression present on mainline and 4.7 branch for targets using SJLJ 
exceptions by default in Ada (e.g. ARM).  The error message is:

+===========================GNAT BUG DETECTED==============================+
| 4.8.0 20120716 (experimental) [trunk revision 189525] (x86_64-suse-linux) GCC 
error:|
| in set_lattice_value, at tree-ssa-ccp.c:452                              |
| Error detected around p.adb:16:4  

It's valid_lattice_transition returning false on a transition from INTEGER_CST 
to a constant &x.  It occurs for an array reference with non-constant index: on 
the first round, &x + i is non-constant so the algorithm computes an alignment 
factor which is an INTEGER_CST; on the second round, i is 0 so the new value is 
the constant &x.

valid_lattice_transition accepts the reverse transition.  The attached patch 
makes the function accept this transition as well.

Tested on x86_64-suse-linux, OK for the mainline and 4.7 branch?


2012-07-18  Eric Botcazou  <ebotca...@adacore.com>

        * tree-ssa-ccp.c (valid_lattice_transition): Allow transitioning from
        as well as to INTEGER_CST.


2012-07-18  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/loop_optimization11.adb: New test.
        * gnat.dg/loop_optimization11_pkg.ads: New helper.


-- 
Eric Botcazou
Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c	(revision 189525)
+++ tree-ssa-ccp.c	(working copy)
@@ -405,9 +405,9 @@ valid_lattice_transition (prop_value_t o
 
   /* Now both lattice values are CONSTANT.  */
 
-  /* Allow transitioning from &x to &x & ~3.  */
-  if (TREE_CODE (old_val.value) != INTEGER_CST
-      && TREE_CODE (new_val.value) == INTEGER_CST)
+  /* Allow transitioning from &x to &x & ~3 and vice versa.  */
+  if ((TREE_CODE (old_val.value) == INTEGER_CST)
+      != (TREE_CODE (new_val.value) == INTEGER_CST))
     return true;
 
   /* Bit-lattices have to agree in the still valid bits.  */
-- { dg-do compile }
-- { dg-options "-O" }

with Loop_Optimization11_Pkg; use Loop_Optimization11_Pkg;

procedure Loop_Optimization11 is
   Arr : array (Prot, Mem) of Integer := (others => (others => 0));
begin
   Put_Line (Img (0) & " ");
   for I in Arr'Range (1) loop
      for J in Arr'Range (2) loop
         declare
            Elem : Integer renames Arr (I, J);
         begin
            Put_Line (Img (Elem));
         end;
      end loop;
   end loop;
end;
package Loop_Optimization11_Pkg is

   function Img (X : Integer) return String;

   procedure Put_Line (Data : String);

   type Prot is (Execute, Execute_Read, Execute_Read_Write);

   type Mem is (Mem_Image, Mem_Mapped, Mem_Private, Unknown);

end Loop_Optimization11_Pkg;

Reply via email to