aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-17 19:44:35 +0000
committerdnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-17 19:44:35 +0000
commit07448bd19813fdbf68f205ada5027d5885a81930 (patch)
tree8e134cbc7256dd3f04eeba1be16ab2520d56f2b4
parent9aa5e60325ecf2928a9b3ec2d6e62adde79f2a0c (diff)
PR optimization/14511
* tree-ssa-alias.c (compute_flow_insensitive_aliasing): Do not ignore read-only variables. (may_alias_p): Fix pointer-to-var calculation when 'var' is an array. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/tree-ssa-20020619-branch@79599 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog.tree-ssa8
-rw-r--r--gcc/testsuite/ChangeLog.tree-ssa5
-rw-r--r--gcc/testsuite/g++.dg/README1
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/20040317-1.C38
-rw-r--r--gcc/tree-ssa-alias.c11
5 files changed, 58 insertions, 5 deletions
diff --git a/gcc/ChangeLog.tree-ssa b/gcc/ChangeLog.tree-ssa
index bfa7439aeab..ae6223b2724 100644
--- a/gcc/ChangeLog.tree-ssa
+++ b/gcc/ChangeLog.tree-ssa
@@ -1,3 +1,11 @@
+2004-03-17 Diego Novillo <dnovillo@redhat.com>
+
+ PR optimization/14511
+ * tree-ssa-alias.c (compute_flow_insensitive_aliasing): Do not
+ ignore read-only variables.
+ (may_alias_p): Fix pointer-to-var calculation when 'var' is an
+ array.
+
2004-03-17 Jan Hubicka <jh@suse.cz>
* tree-ssa.c (rewrite_into_ssa, compute_global_livein): Fix.
diff --git a/gcc/testsuite/ChangeLog.tree-ssa b/gcc/testsuite/ChangeLog.tree-ssa
index c3515108308..37d7e4be8d6 100644
--- a/gcc/testsuite/ChangeLog.tree-ssa
+++ b/gcc/testsuite/ChangeLog.tree-ssa
@@ -1,3 +1,8 @@
+2004-03-17 Diego Novillo <dnovillo@redhat.com>
+
+ PR optimization/14511
+ * g++.dg/tree-ssa/20040317-1.C: New test.
+
2004-03-13 Diego Novillo <dnovillo@redhat.com>
PR optimization/14553
diff --git a/gcc/testsuite/g++.dg/README b/gcc/testsuite/g++.dg/README
index 27f6a5a80cf..d96e8990ee3 100644
--- a/gcc/testsuite/g++.dg/README
+++ b/gcc/testsuite/g++.dg/README
@@ -21,6 +21,7 @@ rtti Tests for run-time type identification (typeid, dynamic_cast, etc.)
special Tests requiring individual processing.
template Tests for templates.
tls Tests for support of thread-local data.
+tree-ssa Tests for Tree SSA optimizations.
warn Tests for compiler warnings.
other Tests that don't fit into one of the other categories.
diff --git a/gcc/testsuite/g++.dg/tree-ssa/20040317-1.C b/gcc/testsuite/g++.dg/tree-ssa/20040317-1.C
new file mode 100644
index 00000000000..e2f3dcdceb8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/20040317-1.C
@@ -0,0 +1,38 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+/* Test provided by Brian Ryner in PR 14511. The alias analyzer was
+ not handling structures containing arrays properly. In this case,
+ the static cast was introducing two assignments of the form
+
+ this_6->_vptr.IFoo = &_ZTV4IFoo[2];
+ this_4->_vptr.IFoo = &_ZTV3Bar[2];
+
+ which were not considered to alias each other because the alias
+ analyzer was not computing a proper pointer to array elements.
+ Another related bug was the type based alias analyzer not computing
+ alias relations to _ZTV4IFoo and _ZTV3Bar. Since those variables
+ are read-only, it was disregarding alias information for them.
+ So, the memory tags for the two 'this' variables were not being
+ marked as aliased with these variables. Resulting in the two
+ assignments not aliasing each other.
+
+ This was causing the optimizers to generate a call to the virtual
+ method Foo() instead of the overloaded version. */
+
+struct IFoo
+{
+ virtual void Foo() = 0;
+};
+
+struct Bar : IFoo
+{
+ void Foo() { }
+};
+
+int main(int argc, char **argv)
+{
+ Bar* b = new Bar();
+ static_cast<IFoo*>(b)->Foo();
+ return 0;
+}
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index eabce62df5c..ff7ef9a6c9a 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -797,10 +797,6 @@ compute_flow_insensitive_aliasing (struct alias_info *ai)
if (!tag_stored_p && !var_stored_p)
continue;
- /* Skip memory tags which are written if the variable is readonly. */
- if (tag_stored_p && TREE_READONLY (var))
- continue;
-
if (may_alias_p (p_map->var, p_map->set, var, v_map->set))
{
size_t num_tag_refs = ai->num_references[tag_ann->uid];
@@ -1337,7 +1333,12 @@ may_alias_p (tree ptr, HOST_WIDE_INT mem_alias_set,
if (AGGREGATE_TYPE_P (TREE_TYPE (mem))
|| AGGREGATE_TYPE_P (TREE_TYPE (var)))
{
- tree ptr_to_var = TYPE_POINTER_TO (TREE_TYPE (var));
+ tree ptr_to_var;
+
+ if (TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
+ ptr_to_var = TYPE_POINTER_TO (TREE_TYPE (TREE_TYPE (var)));
+ else
+ ptr_to_var = TYPE_POINTER_TO (TREE_TYPE (var));
/* If no pointer-to VAR exists, then MEM can't alias VAR. */
if (ptr_to_var == NULL_TREE)