aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2009-01-14 16:45:22 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2009-01-14 16:45:22 +0000
commit10bd6c5c4ab2fd182fc4e24ae539a97a9245774f (patch)
tree8fa08c2737a3ac983b265b46753713f8c3d356b3 /gcc
parent7fe8ccdae51b85dd812af0d06df6f1a730064bc1 (diff)
downloadgcc-10bd6c5c4ab2fd182fc4e24ae539a97a9245774f.zip
gcc-10bd6c5c4ab2fd182fc4e24ae539a97a9245774f.tar.gz
gcc-10bd6c5c4ab2fd182fc4e24ae539a97a9245774f.tar.bz2
re PR tree-optimization/38826 (points-to result wrong for reads from call-clobbered vars)
2009-01-14 Richard Guenther <rguenther@suse.de> PR tree-optimization/38826 PR middle-end/38477 * tree-ssa-structalias.c (emit_alias_warning): Emit the pointer initialization notes only if we actually emitted a warning. (intra_create_variable_infos): Add constraints for a result decl that is passed by hidden reference. (build_pred_graph): Mark all related variables non-direct on address-taking. * gcc.dg/Wstrict-aliasing-bogus-pta-1.c: New testcase. From-SVN: r143374
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c19
-rw-r--r--gcc/tree-ssa-structalias.c35
4 files changed, 65 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d6a6ab9..97e9742 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2009-01-14 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/38826
+ PR middle-end/38477
+ * tree-ssa-structalias.c (emit_alias_warning): Emit the pointer
+ initialization notes only if we actually emitted a warning.
+ (intra_create_variable_infos): Add constraints for a result decl
+ that is passed by hidden reference.
+ (build_pred_graph): Mark all related variables non-direct on
+ address-taking.
+
2009-01-14 Nick Clifton <nickc@redhat.com>
* ira-conflicts.c: Include addresses.h for the definition of
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 27f60f9..8432ec6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2009-01-14 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/38826
+ PR middle-end/38477
+ * gcc.dg/Wstrict-aliasing-bogus-pta-1.c: New testcase.
+
2009-01-13 Sebastian Pop <sebastian.pop@amd.com>
* gcc.dg/graphite/pr38786.c: Fix commit problem.
diff --git a/gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c b/gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c
new file mode 100644
index 0000000..a488274
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+struct S { int *p; int *q; };
+
+void foo (struct S *);
+
+int bar (int b)
+{
+ struct S s;
+ int *p;
+ float f;
+ foo (&s);
+ if (b)
+ p = s.q;
+ else
+ p = (int *)&f;
+ return *p;
+}
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 3d64c1c..8b49556b 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -1129,6 +1129,8 @@ build_pred_graph (void)
}
else if (rhs.type == ADDRESSOF)
{
+ varinfo_t v;
+
/* x = &y */
if (graph->points_to[lhsvar] == NULL)
graph->points_to[lhsvar] = BITMAP_ALLOC (&predbitmap_obstack);
@@ -1141,7 +1143,19 @@ build_pred_graph (void)
/* Implicitly, *x = y */
add_implicit_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+ /* All related variables are no longer direct nodes. */
RESET_BIT (graph->direct_nodes, rhsvar);
+ v = get_varinfo (rhsvar);
+ if (!v->is_full_var)
+ {
+ v = lookup_vi_for_tree (v->decl);
+ do
+ {
+ RESET_BIT (graph->direct_nodes, v->id);
+ v = v->next;
+ }
+ while (v != NULL);
+ }
bitmap_set_bit (graph->address_taken, rhsvar);
}
else if (lhsvar > anything_id
@@ -4561,6 +4575,16 @@ intra_create_variable_infos (void)
}
}
+ /* Add a constraint for a result decl that is passed by reference. */
+ if (DECL_RESULT (cfun->decl)
+ && DECL_BY_REFERENCE (DECL_RESULT (cfun->decl)))
+ {
+ varinfo_t p, result_vi = get_vi_for_tree (DECL_RESULT (cfun->decl));
+
+ for (p = result_vi; p; p = p->next)
+ make_constraint_from (p, nonlocal_id);
+ }
+
/* Add a constraint for the incoming static chain parameter. */
if (cfun->static_chain_decl != NULL_TREE)
{
@@ -4735,7 +4759,7 @@ emit_alias_warning (tree ptr)
{
gimple use;
imm_use_iterator ui;
- unsigned warned = 0;
+ bool warned = false;
FOR_EACH_IMM_USE_STMT (use, ui, ptr)
{
@@ -4773,13 +4797,12 @@ emit_alias_warning (tree ptr)
&& !TREE_NO_WARNING (deref))
{
TREE_NO_WARNING (deref) = 1;
- warning_at (gimple_location (use), OPT_Wstrict_aliasing,
- "dereferencing pointer %qD does break strict-aliasing "
- "rules", SSA_NAME_VAR (ptr));
- ++warned;
+ warned |= warning_at (gimple_location (use), OPT_Wstrict_aliasing,
+ "dereferencing pointer %qD does break "
+ "strict-aliasing rules", SSA_NAME_VAR (ptr));
}
}
- if (warned > 0)
+ if (warned)
{
bitmap visited = BITMAP_ALLOC (NULL);
emit_pointer_definition (ptr, visited);