re PR tree-optimization/46149 (26_numerics/valarray/27867.cc FAILs with -O2 -fno...
authorRichard Guenther <rguenther@suse.de>
Tue, 2 Nov 2010 17:00:09 +0000 (17:00 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 2 Nov 2010 17:00:09 +0000 (17:00 +0000)
2010-11-02  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/46149
* tree-ssa-structalias.c (get_constraint_for_1): Properly handle
non-indirect MEM_REF variants.

* g++.dg/torture/pr46149.C: New testcase.

From-SVN: r166204

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr46149.C [new file with mode: 0644]
gcc/tree-ssa-structalias.c

index 4a2611a3806227c5f9c2119febd9bfcf41b5b95e..796653212aedd5d39897249dd10e09d5d4ac3560 100644 (file)
@@ -1,3 +1,9 @@
+2010-11-02  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/46149
+       * tree-ssa-structalias.c (get_constraint_for_1): Properly handle
+       non-indirect MEM_REF variants.
+
 2010-11-02  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/46216
index 32fedf6b43cd4572dbc91ae6e364a08cb03fa6c1..d7135d88c2dae8bd7834e5f38efbbea291c75ada 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-02  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/46149
+       * g++.dg/torture/pr46149.C: New testcase.
+
 2010-11-02  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/46216
diff --git a/gcc/testsuite/g++.dg/torture/pr46149.C b/gcc/testsuite/g++.dg/torture/pr46149.C
new file mode 100644 (file)
index 0000000..bdc3d77
--- /dev/null
@@ -0,0 +1,51 @@
+// { dg-do run }
+// { dg-options "-fno-tree-sra" }
+
+struct S
+{
+  S ():p ((char *) __builtin_calloc (1, 1))
+  {
+  }
+  char *p;
+};
+
+template < class T > struct A
+{
+  A (const S & __m1, const T & __m2):m1 (__m1), m2 (__m2)
+  {
+  }
+  const S & m1;
+  const T & m2;
+};
+
+struct B:A < S >
+{
+  B (const S & __v):A < S > (__v, __v)
+  {
+  }
+};
+
+struct C:A < B >
+{
+  C (const S & __e1, const B & __e2):A < B > (__e1, __e2)
+  {
+  }
+};
+
+struct D
+{
+  D (const C & __c):c (__c)
+  {
+  }
+  const C c;
+};
+
+int
+main ()
+{
+  S s;
+  B b (s);
+  C c (s, b);
+  D d (c);
+  return d.c.m2.m2.p[0];
+}
index ed05178c23d47e70b779b3a943109693c1543a38..315bef6f0da077eace8bc0e3f1414adb30e1d99e 100644 (file)
@@ -3339,9 +3339,41 @@ get_constraint_for_1 (tree t, VEC (ce_s, heap) **results, bool address_p,
          {
          case MEM_REF:
            {
+             struct constraint_expr *c;
+             varinfo_t vi, curr;
              tree off = double_int_to_tree (sizetype, mem_ref_offset (t));
              get_constraint_for_ptr_offset (TREE_OPERAND (t, 0), off, results);
              do_deref (results);
+
+             /* If we are not taking the address then make sure to process
+                all subvariables we might access.  */
+             c = VEC_last (ce_s, *results);
+             if (address_p
+                 || c->type != SCALAR)
+               return;
+
+             vi = get_varinfo (c->var);
+             curr = vi->next;
+             if (!vi->is_full_var
+                 && curr)
+               {
+                 unsigned HOST_WIDE_INT size;
+                 if (host_integerp (TYPE_SIZE (TREE_TYPE (t)), 1))
+                   size = TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (t)));
+                 else
+                   size = -1;
+                 for (; curr; curr = curr->next)
+                   {
+                     if (curr->offset - vi->offset < size)
+                       {
+                         struct constraint_expr cs = *c;
+                         cs.var = curr->id;
+                         VEC_safe_push (ce_s, heap, *results, &cs);
+                       }
+                     else
+                       break;
+                   }
+               }
              return;
            }
          case ARRAY_REF: