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]

[tree-ssa] Fix type comparison bug


After the types_compatible_p langhook went in, we started failing
libmudflap.c/fail14-frag.c because of a typo in same_translation_unit_p.

We were erroneously thinking that two structures declared inside a
function were compatible because one of them was one field bigger than
the other and same_translation_unit_p was returning false, so we were
doing a loose compatibility test.


     1. struct a { int x; int y; char z; };
     2. struct b { int x; int y; };
     3. 
     4. volatile struct b k;
     5. volatile struct a *p;
     6. p = (struct a*) &k;
     7. p->z = 'q';

This was causing the gimplifier to drop the type cast in statement 6,
which in turn was allowing the optimizers to do the invalid propagation

	k.z = 'q';

Finally, mudflap was not catching the illegal transformation because we
do not instrument structure references, only pointer and array
references.

Anyway, the obvious patch.  I'll apply the same to mainline.


Diego.


	* c-typeck.c (same_translation_unit_p): Fix pasto.

Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.196.2.43
diff -d -c -p -d -u -p -r1.196.2.43 c-typeck.c
--- c-typeck.c	16 Mar 2004 22:16:29 -0000	1.196.2.43
+++ c-typeck.c	22 Mar 2004 22:49:45 -0000
@@ -632,7 +632,7 @@ same_translation_unit_p (tree t1, tree t
   while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
     switch (TREE_CODE_CLASS (TREE_CODE (t2)))
       {
-      case 'd': t2 = DECL_CONTEXT (t1); break;
+      case 'd': t2 = DECL_CONTEXT (t2); break;
       case 't': t2 = TYPE_CONTEXT (t2); break;
       case 'b': t2 = BLOCK_SUPERCONTEXT (t2); break;
       default: abort ();




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