[PATCH] Fix PR39358, some more wrong PTA
Richard Guenther
rguenther@suse.de
Wed Mar 4 12:33:00 GMT 2009
This PR uncovers that on the trunk we fail to identify the
ESCAPED = *ESCAPED constraint properly and thus mis-compute
the escaped solution and the rest.
Fixed with the following, bootstrapped and tested on
x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2009-03-04 Richard Guenther <rguenther@suse.de>
PR tree-optimization/39358
* tree-ssa-structalias.c (do_sd_constraint): Fix check for
escaped_id and callused_id.
(solve_graph): Likewise.
* g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C: New testcase.
* g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C: Likewise.
Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c (revision 144599)
--- gcc/tree-ssa-structalias.c (working copy)
*************** do_sd_constraint (constraint_graph_t gra
*** 1524,1531 ****
of a variable can also reach all other fields of the variable
we simply have to expand the solution to contain all sub-fields
if one sub-field is contained. */
! if (c->rhs.var == escaped_id
! || c->rhs.var == callused_id)
{
bitmap vars = NULL;
/* In a first pass record all variables we need to add all
--- 1524,1531 ----
of a variable can also reach all other fields of the variable
we simply have to expand the solution to contain all sub-fields
if one sub-field is contained. */
! if (c->rhs.var == find (escaped_id)
! || c->rhs.var == find (callused_id))
{
bitmap vars = NULL;
/* In a first pass record all variables we need to add all
*************** do_sd_constraint (constraint_graph_t gra
*** 1594,1602 ****
/* Merging the solution from ESCAPED needlessly increases
the set. Use ESCAPED as representative instead.
Same for CALLUSED. */
! else if (get_varinfo (t)->id == escaped_id
! || get_varinfo (t)->id == callused_id)
! flag |= bitmap_set_bit (sol, get_varinfo (t)->id);
else if (add_graph_edge (graph, lhs, t))
flag |= bitmap_ior_into (sol, get_varinfo (t)->solution);
}
--- 1594,1603 ----
/* Merging the solution from ESCAPED needlessly increases
the set. Use ESCAPED as representative instead.
Same for CALLUSED. */
! else if (get_varinfo (t)->id == find (escaped_id))
! flag |= bitmap_set_bit (sol, escaped_id);
! else if (get_varinfo (t)->id == find (callused_id))
! flag |= bitmap_set_bit (sol, callused_id);
else if (add_graph_edge (graph, lhs, t))
flag |= bitmap_ior_into (sol, get_varinfo (t)->solution);
}
*************** solve_graph (constraint_graph_t graph)
*** 2516,2523 ****
if (!solution_empty
/* Do not propagate the ESCAPED/CALLUSED solutions. */
! && i != escaped_id
! && i != callused_id)
{
bitmap_iterator bi;
--- 2517,2524 ----
if (!solution_empty
/* Do not propagate the ESCAPED/CALLUSED solutions. */
! && i != find (escaped_id)
! && i != find (callused_id))
{
bitmap_iterator bi;
Index: gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C
===================================================================
*** gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C (revision 0)
--- gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C (revision 0)
***************
*** 0 ****
--- 1,19 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -Wstrict-aliasing" } */
+
+ #include<list>
+
+ struct A
+ {
+ virtual ~A();
+ };
+
+ A* foo();
+
+ void bar(std::list<int> x)
+ {
+ std::list<int> y = x;
+ if (*y.rbegin())
+ delete foo();
+ }
+
Index: gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C
===================================================================
*** gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C (revision 0)
--- gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C (revision 0)
***************
*** 0 ****
--- 1,35 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -Wstrict-aliasing" } */
+
+ struct Node_base {};
+
+ struct Node : Node_base
+ {
+ int data;
+ };
+
+ struct List
+ {
+ Node_base node, *prev;
+
+ List() : prev(&node) { xyz(); }
+
+ void xyz();
+
+ int back() { return static_cast<Node*>(prev)->data; }
+ };
+
+ struct A
+ {
+ virtual ~A();
+ };
+
+ A* foo();
+
+ void bar()
+ {
+ List y;
+ if (y.back())
+ delete foo();
+ }
+
More information about the Gcc-patches
mailing list