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]

[vta/trunk] don't violate strict aliasing rules in type_hash_add


I noticed we cast a (void**) to (struct type_hash **) and then assign
to the dereferenced pointer.  This is wrong.  What we want is to cast
the (struct type_hash *) object to (void*) and then assign to the
dereferenced (void**), which mirrors the way we read from the hash
table: dereferencing the void** and then casting the void* to (struct
type_hash *).

Ok for the trunk?  Installing in vta.

for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* tree.c (type_hash_add): Don't violate strict aliasing rules.

Index: gcc/tree.c
===================================================================
--- gcc/tree.c.orig	2007-11-11 20:33:13.000000000 -0200
+++ gcc/tree.c	2007-11-11 20:32:52.000000000 -0200
@@ -4685,7 +4685,7 @@ type_hash_add (hashval_t hashcode, tree 
   h->hash = hashcode;
   h->type = type;
   loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
-  *(struct type_hash **) loc = h;
+  *loc = (void*)h;
 }
 
 /* Given TYPE, and HASHCODE its hash code, return the canonical
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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