]> code.ossystems Code Review - openembedded-core.git/blob
fa83ccc5e68bafd9ccaf1c800892f121682a2d66
[openembedded-core.git] /
1 Upstream-Status: Inappropriate [Backport]
2 From d0c1a282504a0fa941a9ae22536c73f64d8c5762 Mon Sep 17 00:00:00 2001
3 From: rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
4 Date: Thu, 21 Apr 2011 14:40:53 +0000
5 Subject: [PATCH 162/200] 2011-04-21  Richard Guenther  <rguenther@suse.de>
6
7         PR middle-end/48695
8         * tree-ssa-alias.c (aliasing_component_refs_p): Compute base
9         objects and types here.  Adjust for their offset before
10         comparing.
11
12         * g++.dg/torture/pr48695.C: New testcase.
13
14
15 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@172831 138bc75d-0d04-0410-961f-82ee72b054a4
16
17 index e26c75d..3b0e585 100644
18 new file mode 100644
19 index 0000000..44e6c77
20 --- /dev/null
21 +++ b/gcc/testsuite/g++.dg/torture/pr48695.C
22 @@ -0,0 +1,38 @@
23 +// { dg-do run }
24 +
25 +typedef __SIZE_TYPE__ size_t;
26 +
27 +inline void *operator new (size_t, void *__p) throw() { return __p; }
28 +
29 +struct _Vector_impl
30 +{
31 +  int *_M_start;
32 +  int *_M_finish;
33 +  _Vector_impl () :_M_start (0), _M_finish (0) {}
34 +};
35 +
36 +struct vector
37 +{
38 +  _Vector_impl _M_impl;
39 +  int *_M_allocate (size_t __n)
40 +  {
41 +    return __n != 0 ? new int[__n] : 0;
42 +  }
43 +  void push_back ()
44 +  {
45 +    new (this->_M_impl._M_finish) int ();
46 +    this->_M_impl._M_finish =
47 +      this->_M_allocate (this->_M_impl._M_finish - this->_M_impl._M_start) + 1;
48 +  }
49 +};
50 +
51 +int
52 +main ()
53 +{
54 +  for (int i = 0; i <= 1; i++)
55 +    for (int j = 0; j <= 1; j++)
56 +      {
57 +       vector a[2];
58 +       a[i].push_back ();
59 +      }
60 +}
61 diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
62 index bd8953b..8434179 100644
63 --- a/gcc/tree-ssa-alias.c
64 +++ b/gcc/tree-ssa-alias.c
65 @@ -594,11 +594,11 @@ same_type_for_tbaa (tree type1, tree type2)
66     are the respective alias sets.  */
67  
68  static bool
69 -aliasing_component_refs_p (tree ref1, tree type1,
70 +aliasing_component_refs_p (tree ref1,
71                            alias_set_type ref1_alias_set,
72                            alias_set_type base1_alias_set,
73                            HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
74 -                          tree ref2, tree type2,
75 +                          tree ref2,
76                            alias_set_type ref2_alias_set,
77                            alias_set_type base2_alias_set,
78                            HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
79 @@ -610,9 +610,21 @@ aliasing_component_refs_p (tree ref1, tree type1,
80         struct A { int i; int j; } *q;
81         struct B { struct A a; int k; } *p;
82       disambiguating q->i and p->a.j.  */
83 +  tree base1, base2;
84 +  tree type1, type2;
85    tree *refp;
86    int same_p;
87  
88 +  /* Choose bases and base types to search for.  */
89 +  base1 = ref1;
90 +  while (handled_component_p (base1))
91 +    base1 = TREE_OPERAND (base1, 0);
92 +  type1 = TREE_TYPE (base1);
93 +  base2 = ref2;
94 +  while (handled_component_p (base2))
95 +    base2 = TREE_OPERAND (base2, 0);
96 +  type2 = TREE_TYPE (base2);
97 +
98    /* Now search for the type1 in the access path of ref2.  This
99       would be a common base for doing offset based disambiguation on.  */
100    refp = &ref2;
101 @@ -628,6 +640,8 @@ aliasing_component_refs_p (tree ref1, tree type1,
102        HOST_WIDE_INT offadj, sztmp, msztmp;
103        get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
104        offset2 -= offadj;
105 +      get_ref_base_and_extent (base1, &offadj, &sztmp, &msztmp);
106 +      offset1 -= offadj;
107        return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
108      }
109    /* If we didn't find a common base, try the other way around.  */
110 @@ -644,6 +658,8 @@ aliasing_component_refs_p (tree ref1, tree type1,
111        HOST_WIDE_INT offadj, sztmp, msztmp;
112        get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
113        offset1 -= offadj;
114 +      get_ref_base_and_extent (base2, &offadj, &sztmp, &msztmp);
115 +      offset2 -= offadj;
116        return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
117      }
118  
119 @@ -805,11 +821,10 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
120        && TREE_CODE (base1) != TARGET_MEM_REF
121        && (TREE_CODE (base1) != MEM_REF
122           || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1))
123 -    return aliasing_component_refs_p (ref1, TREE_TYPE (ptrtype1),
124 +    return aliasing_component_refs_p (ref1,
125                                       ref1_alias_set, base1_alias_set,
126                                       offset1, max_size1,
127 -                                     ref2, TREE_TYPE
128 -                                             (reference_alias_ptr_type (ref2)),
129 +                                     ref2,
130                                       ref2_alias_set, base2_alias_set,
131                                       offset2, max_size2, true);
132  
133 @@ -952,10 +967,10 @@ indirect_refs_may_alias_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
134           || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1)
135        && (TREE_CODE (base2) != MEM_REF
136           || same_type_for_tbaa (TREE_TYPE (base2), TREE_TYPE (ptrtype2)) == 1))
137 -    return aliasing_component_refs_p (ref1, TREE_TYPE (ptrtype1),
138 +    return aliasing_component_refs_p (ref1,
139                                       ref1_alias_set, base1_alias_set,
140                                       offset1, max_size1,
141 -                                     ref2, TREE_TYPE (ptrtype2),
142 +                                     ref2,
143                                       ref2_alias_set, base2_alias_set,
144                                       offset2, max_size2, false);
145  
146 -- 
147 1.7.0.4
148