re PR tree-optimization/21407 (wrong code with downcast in C++)
authorDaniel Berlin <dberlin@dberlin.org>
Wed, 18 May 2005 13:26:20 +0000 (13:26 +0000)
committerDaniel Berlin <dberlin@gcc.gnu.org>
Wed, 18 May 2005 13:26:20 +0000 (13:26 +0000)
2005-05-18  Daniel Berlin  <dberlin@dberlin.org>

Fix PR tree-optimization/21407

* tree-ssa-operands.c (note_addressable): Change
COMPONENT_REF handling in response to aliasing
discussion.

From-SVN: r99896

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

index 3a1e6066948e16b509e34a4abfef1c11b57f5014..11b9bc3ec4b46ff2b05fdb5bbe49394436937021 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-18  Daniel Berlin  <dberlin@dberlin.org>
+       
+       Fix PR tree-optimization/21407
+
+       * tree-ssa-operands.c (note_addressable): Change
+       COMPONENT_REF handling in response to aliasing
+       discussion.
+
 2005-05-18  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * config/sparc/sol2.h (TARGET_DEFAULT): Add back MASK_APP_REGS.
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr21407.C b/gcc/testsuite/g++.dg/tree-ssa/pr21407.C
new file mode 100644 (file)
index 0000000..561dc70
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+extern "C" void abort(void);
+struct T1 {int a, b; virtual void f(){}};
+struct T : T1 { struct T1 w;  int b; };
+void foo (struct T1 *p) { struct T *q = dynamic_cast<T*>(p); if (q->b != 2) abort (); }
+/* We shouldn't kill the store to c.b, because foo uses it.  */
+int main () { struct T c; c.b = 2; foo (&c); return 0; }
index ccc2033dbc0daf880642267bd7ca7d7460f114aa..e43b6030726a7893d73f2431f3f1655a5788b705 100644 (file)
@@ -1886,35 +1886,14 @@ add_stmt_operand (tree *var_p, stmt_ann_t s_ann, int flags)
 static void
 note_addressable (tree var, stmt_ann_t s_ann)
 {
-  tree ref;
   subvar_t svars;
-  HOST_WIDE_INT offset;
-  HOST_WIDE_INT size;
 
   if (!s_ann)
     return;
   
-  /* If this is a COMPONENT_REF, and we know exactly what it touches, we only
-     take the address of the subvariables it will touch.
-     Otherwise, we take the address of all the subvariables, plus the real
-     ones.  */
-
-  if (var && TREE_CODE (var) == COMPONENT_REF 
-      && (ref = okay_component_ref_for_subvars (var, &offset, &size)))
-    {
-      subvar_t sv;
-      svars = get_subvars_for_var (ref);
-      
-      if (s_ann->addresses_taken == NULL)
-       s_ann->addresses_taken = BITMAP_GGC_ALLOC ();      
-      
-      for (sv = svars; sv; sv = sv->next)
-       {
-         if (overlap_subvar (offset, size, sv, NULL))
-           bitmap_set_bit (s_ann->addresses_taken, var_ann (sv->var)->uid);
-       }
-      return;
-    }
+  /* Note that it is *NOT OKAY* to use the target of a COMPONENT_REF
+     as the only thing we take the address of.
+     See PR 21407 and the ensuing mailing list discussion.  */
   
   var = get_base_address (var);
   if (var && SSA_VAR_P (var))