]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/45919
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Oct 2010 21:17:30 +0000 (21:17 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Oct 2010 21:17:30 +0000 (21:17 +0000)
* tree-ssa-ccp.c (fold_nonarray_ctor_reference): Handle flexible
array members.

* gcc.c-torture/compile/pr45919.c: New test.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr45919.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index 352be15761a6c6fbae5872102188defd5b71819d..5fc321d012d90e7c216260e054bbea6929b76fde 100644 (file)
@@ -1,5 +1,9 @@
 2010-10-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/45919
+       * tree-ssa-ccp.c (fold_nonarray_ctor_reference): Handle flexible
+       array members.
+
        PR tree-optimization/46066
        * tree-parloops.c (create_parallel_loop): Use gsi_last_nondebug_bb
        instead of gsi_last_bb.
index 665f8a5df4a97913ce80845d505c18d07f08312a..5abf927bf9a9d5f8f5572b82bd2d42a6ed1a4ae5 100644 (file)
@@ -1,5 +1,8 @@
 2010-10-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/45919
+       * gcc.c-torture/compile/pr45919.c: New test.
+
        PR tree-optimization/46066
        * gcc.dg/autopar/pr46066.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr45919.c b/gcc/testsuite/gcc.c-torture/compile/pr45919.c
new file mode 100644 (file)
index 0000000..caf518d
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR tree-optimization/45919 */
+
+const struct S { int a; int b[]; } s = { 0, { 0 }};
+
+int
+foo (void)
+{
+  return s.b[0];
+}
index 650494144cdac8ea35c5f43caaf12f0f434cd3a7..2d9c1233ea92b32e3c44e32c53862f12cdff06c9 100644 (file)
@@ -1523,23 +1523,30 @@ fold_nonarray_ctor_reference (tree type, tree ctor,
       double_int bits_per_unit_cst = uhwi_to_double_int (BITS_PER_UNIT);
       double_int bitoffset_end;
 
-      /* Variable sized objects in static constructors makes no sense.  */
+      /* Variable sized objects in static constructors makes no sense,
+        but field_size can be NULL for flexible array members.  */
       gcc_assert (TREE_CODE (field_offset) == INTEGER_CST
                  && TREE_CODE (byte_offset) == INTEGER_CST
-                 && TREE_CODE (field_size) == INTEGER_CST);
+                 && (field_size != NULL_TREE
+                     ? TREE_CODE (field_size) == INTEGER_CST
+                     : TREE_CODE (TREE_TYPE (cfield)) == ARRAY_TYPE));
 
       /* Compute bit offset of the field.  */
       bitoffset = double_int_add (tree_to_double_int (field_offset),
                                  double_int_mul (byte_offset_cst,
                                                  bits_per_unit_cst));
       /* Compute bit offset where the field ends.  */
-      bitoffset_end = double_int_add (bitoffset,
-                                     tree_to_double_int (field_size));
+      if (field_size != NULL_TREE)
+       bitoffset_end = double_int_add (bitoffset,
+                                       tree_to_double_int (field_size));
+      else
+       bitoffset_end = double_int_zero;
 
       /* Is OFFSET in the range (BITOFFSET, BITOFFSET_END)? */
       if (double_int_cmp (uhwi_to_double_int (offset), bitoffset, 0) >= 0
-         && double_int_cmp (uhwi_to_double_int (offset),
-                            bitoffset_end, 0) < 0)
+         && (field_size == NULL_TREE
+             || double_int_cmp (uhwi_to_double_int (offset),
+                                bitoffset_end, 0) < 0))
        {
          double_int access_end = double_int_add (uhwi_to_double_int (offset),
                                                  uhwi_to_double_int (size));