* tree-ssa-loop-ivopts.c (may_be_nonaddressable_p): New function.
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Jun 2006 15:09:36 +0000 (15:09 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Jun 2006 15:09:36 +0000 (15:09 +0000)
(find_interesting_uses_address): Punt if above function returns true.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114851 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/loop_unchecked_conversion.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/loop_unchecked_conversion.ads [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.c

index c866d36..f612b09 100644 (file)
@@ -1,3 +1,8 @@
+2006-06-21  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * tree-ssa-loop-ivopts.c (may_be_nonaddressable_p): New function.
+       (find_interesting_uses_address): Punt if above function returns true.
+
 2006-06-21  Richard Guenther  <rguenther@suse.de>
 
        * configure: Regenerated.
index 93cb39e..3e9165c 100644 (file)
@@ -1,3 +1,7 @@
+2006-06-21  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/loop_unchecked_conversion.ad[bs]: New test.
+
 2006-06-21  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc.c-torture/execute/complex-7.c: New.
diff --git a/gcc/testsuite/gnat.dg/loop_unchecked_conversion.adb b/gcc/testsuite/gnat.dg/loop_unchecked_conversion.adb
new file mode 100644 (file)
index 0000000..e87c415
--- /dev/null
@@ -0,0 +1,33 @@
+-- { dg-do compile }
+-- { dg-options "-gnatws -O" }
+
+with Unchecked_Conversion;
+
+package body loop_unchecked_conversion is
+
+   type Byte is mod 2**8;
+
+   type List is array (Natural range <>) of Byte;
+
+   subtype Integer_List is List (1 .. 4);
+
+   function Integer_Down is new
+     Unchecked_Conversion (Source => Integer, Target => Integer_List);
+
+   type Storage (Size : Integer) is
+      record
+         Data : List (1 .. Size);
+      end record;
+
+   type Storage_Pointer is access Storage;
+
+   The_Data_Storage : Storage_Pointer;
+
+   procedure slice is
+   begin
+      for I in 0 .. 1 loop
+         The_Data_Storage.Data (I+1 .. I+4) := Integer_Down (I);
+      end loop;
+   end;
+
+end loop_unchecked_conversion;
diff --git a/gcc/testsuite/gnat.dg/loop_unchecked_conversion.ads b/gcc/testsuite/gnat.dg/loop_unchecked_conversion.ads
new file mode 100644 (file)
index 0000000..5ce43e5
--- /dev/null
@@ -0,0 +1,5 @@
+package loop_unchecked_conversion is
+
+   procedure slice;
+
+end loop_unchecked_conversion;
index 0f98604..8a69664 100644 (file)
@@ -1466,6 +1466,36 @@ may_be_unaligned_p (tree ref)
   return false;
 }
 
+/* Return true if EXPR may be non-addressable.   */
+
+static bool
+may_be_nonaddressable_p (tree expr)
+{
+  switch (TREE_CODE (expr))
+    {
+    case COMPONENT_REF:
+      return DECL_NONADDRESSABLE_P (TREE_OPERAND (expr, 1))
+            || may_be_nonaddressable_p (TREE_OPERAND (expr, 0));
+
+    case ARRAY_REF:
+    case ARRAY_RANGE_REF:
+      return may_be_nonaddressable_p (TREE_OPERAND (expr, 0));
+
+    case VIEW_CONVERT_EXPR:
+      /* This kind of view-conversions may wrap non-addressable objects
+        and make them look addressable.  After some processing the
+        non-addressability may be uncovered again, causing ADDR_EXPRs
+        of inappropriate objects to be built.  */
+      return AGGREGATE_TYPE_P (TREE_TYPE (expr))
+            && !AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 0)));
+
+    default:
+      break;
+    }
+
+  return false;
+}
+
 /* Finds addresses in *OP_P inside STMT.  */
 
 static void
@@ -1482,9 +1512,10 @@ find_interesting_uses_address (struct ivopts_data *data, tree stmt, tree *op_p)
 
   /* Ignore bitfields for now.  Not really something terribly complicated
      to handle.  TODO.  */
-  if (TREE_CODE (base) == BIT_FIELD_REF
-      || (TREE_CODE (base) == COMPONENT_REF
-         && DECL_NONADDRESSABLE_P (TREE_OPERAND (base, 1))))
+  if (TREE_CODE (base) == BIT_FIELD_REF)
+    goto fail;
+
+  if (may_be_nonaddressable_p (base))
     goto fail;
 
   if (STRICT_ALIGNMENT