This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: Fix PR tree-optimization/21407


Whee.
We pass the address of a derived class to the a call, then upcast it
back to the base class, effectively giving you the structure which
wasn't passed.  You can't do something like this in C, luckily :).

Thus, we can only assume things about address of a structure field when
their is not inheritance involved in the thing we are taking the address
of.
Thus, a TYPE_BINFO check is necessary on the thing whose address if
being taken.

Where do we put execute test cases for C++?  There is no g
++.torture/execute or anything of the sort, and I don't see any.


2005-05-09  Daniel Berlin  <dberlin@dberlin.org>
	
	Fix PR tree-optimization/21407
	* tree-ssa-operands.c (note_addressable):  Can't
	use COMPONENT_REF target unless there is no inheritance
	involved.
Index: tree-ssa-operands.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-operands.c,v
retrieving revision 2.82
diff -u -p -r2.82 tree-ssa-operands.c
--- tree-ssa-operands.c	6 May 2005 14:04:11 -0000	2.82
+++ tree-ssa-operands.c	10 May 2005 01:53:14 -0000
@@ -1894,12 +1894,16 @@ note_addressable (tree var, stmt_ann_t s
   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 this is a COMPONENT_REF, and we know exactly what it touches,
+     we only take the address of the subvariables it will touch.  This
+     is not the case if we are taking the address of a record with
+     inheritance, as one can simply upcast to get back to the original
+     record.  In these cases, and if we can't tell what the
+     COMPONENT_REF touches, we take the address of all the
+     subvariables, plus the real ones.  */
 
   if (var && TREE_CODE (var) == COMPONENT_REF 
+      && TYPE_BINFO (TREE_TYPE (var)) == NULL
       && (ref = okay_component_ref_for_subvars (var, &offset, &size)))
     {
       subvar_t sv;
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 (); }
int main () { struct T c; c.b = 2; foo (&c); return 0; }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]