/*----------------------------------------------------------------*/
/* Note there are a whole bunch of ugly double casts of the form
- (Word*)(void*)&p. These placate gcc at -O2. The obvious form
+ (Word*)(HChar*)&p. These placate gcc at -O2. The obvious form
(Word*)&p causes gcc to complain that 'dereferencing a type-punned
pointer ill break strict-aliasing rules'. It stops complaining
- when the intermediate void* type is inserted. Is this a reasonable
- "fix"? I don't know. */
+ when the intermediate HChar* type is inserted.
+
+ HChar is the same as plain 'char' (see
+ VEX/pub/libvex_basictypes.h). The ANSI C standard says "An object
+ shall have its stored value accessed only by an lvalue that has one
+ of the following types: [..] A character type."
+
+ (http://gcc.gnu.org/ml/gcc/1999-09n/msg00419.html)
+
+ Hence it would appear that casting via an intermediate char* type
+ is a standards-compliant (== future-proof) way to circumvent the
+ aliasing rules in places where it is convenient to do so.
+*/
// FIXME what is supposed to happen to locks in memory which
// is relocated as a result of client realloc?
Thread* thr;
Word count;
HG_(initIterBag)( bag );
- while (HG_(nextIterBag)( bag, (Word*)(void*)&thr, &count )) {
+ while (HG_(nextIterBag)( bag, (Word*)(HChar*)&thr, &count )) {
if (count < 1) return False;
if (!is_sane_Thread(thr)) return False;
}
}
/* for each thread that holds this lock do ... */
HG_(initIterBag)( lk->heldBy );
- while (HG_(nextIterBag)( lk->heldBy, (Word*)(void*)&thr, NULL )) {
+ while (HG_(nextIterBag)( lk->heldBy, (Word*)(HChar*)&thr, NULL )) {
tl_assert(is_sane_Thread(thr));
tl_assert(HG_(elemWS)( univ_lsets,
thr->locksetA, (Word)lk ));
Word count;
VG_(printf)(" { ");
HG_(initIterBag)( lk->heldBy );
- while (HG_(nextIterBag)( lk->heldBy, (Word*)(void*)&thr, &count ))
+ while (HG_(nextIterBag)( lk->heldBy, (Word*)(HChar*)&thr, &count ))
VG_(printf)("%lu:%p ", count, thr);
HG_(doneIterBag)( lk->heldBy );
VG_(printf)("}");
space(d); VG_(printf)("map_locks (%d entries) {\n",
(Int)HG_(sizeFM)( map_locks ));
HG_(initIterFM)( map_locks );
- while (HG_(nextIterFM)( map_locks, (Word*)(void*)&gla,
- (Word*)(void*)&lk )) {
+ while (HG_(nextIterFM)( map_locks, (Word*)(HChar*)&gla,
+ (Word*)(HChar*)&lk )) {
space(d+3);
VG_(printf)("guest %p -> Lock %p\n", gla, lk);
}
space(d); VG_(printf)("map_segments (%d entries) {\n",
(Int)HG_(sizeFM)( map_segments ));
HG_(initIterFM)( map_segments );
- while (HG_(nextIterFM)( map_segments, (Word*)(void*)&segid,
- (Word*)(void*)&seg )) {
+ while (HG_(nextIterFM)( map_segments, (Word*)(HChar*)&segid,
+ (Word*)(HChar*)&seg )) {
space(d+3);
VG_(printf)("segid 0x%x -> Segment %p\n", (UInt)segid, seg);
}
SecMap* sm;
space(d); VG_(printf)("map_shmem_ShR_and_ShM_only {\n");
HG_(initIterFM)( map_shmem );
- while (HG_(nextIterFM)( map_shmem, (Word*)(void*)&ga,
- (Word*)(void*)&sm )) {
+ while (HG_(nextIterFM)( map_shmem, (Word*)(HChar*)&ga,
+ (Word*)(HChar*)&sm )) {
pp_SecMap_shared( d+3, sm, ga );
}
HG_(doneIterFM) ( map_shmem );
Lock* oldlock = NULL;
tl_assert(is_sane_ThreadId(tid));
found = HG_(lookupFM)( map_locks,
- NULL, (Word*)(void*)&oldlock, (Word)ga );
+ NULL, (Word*)(HChar*)&oldlock, (Word)ga );
if (!found) {
Lock* lock = mk_LockN(lkk, ga);
lock->appeared_at = VG_(record_ExeContext)( tid, 0 );
{
Bool found;
Lock* lk = NULL;
- found = HG_(lookupFM)( map_locks, NULL, (Word*)(void*)&lk, (Word)ga );
+ found = HG_(lookupFM)( map_locks, NULL, (Word*)(HChar*)&lk, (Word)ga );
tl_assert(found ? lk != NULL : lk == NULL);
if (found) {
// check the relevant secondary map has .mbHasLocks?
Addr ga2 = 0;
Lock* lk = NULL;
HG_(delFromFM)( map_locks,
- (Word*)(void*)&ga2, (Word*)(void*)&lk, (Word)ga );
+ (Word*)(HChar*)&ga2, (Word*)(HChar*)&lk, (Word)ga );
/* delFromFM produces the val which is being deleted, if it is
found. So assert it is non-null; that in effect asserts that we
are deleting a (ga, Lock) pair which actually exists. */
Segment* seg = NULL;
tl_assert( is_sane_SegmentID(segid) );
found = HG_(lookupFM)( map_segments,
- NULL, (Word*)(void*)&seg, (Word)segid );
+ NULL, (Word*)(HChar*)&seg, (Word)segid );
tl_assert(found);
tl_assert(seg != NULL);
return seg;
Segment* seg = NULL;
tl_assert( is_sane_SegmentID(segid) );
found = HG_(lookupFM)( map_segments,
- NULL, (Word*)(void*)&seg, (Word)segid );
+ NULL, (Word*)(HChar*)&seg, (Word)segid );
if (!found) tl_assert(seg == NULL);
return seg;
}
SecMap* sm = NULL;
Addr gaKey = shmem__round_to_SecMap_base(ga);
if (HG_(lookupFM)( map_shmem,
- NULL/*keyP*/, (Word*)(void*)&sm, (Word)gaKey )) {
+ NULL/*keyP*/, (Word*)(HChar*)&sm, (Word)gaKey )) {
/* Found; address of SecMap is in sm */
tl_assert(sm);
} else {
SecMap* sm;
Addr aKey = shmem__round_to_SecMap_base(a);
if (HG_(lookupFM)( map_shmem,
- NULL/*keyP*/, (Word*)(void*)&sm, (Word)aKey )) {
+ NULL/*keyP*/, (Word*)(HChar*)&sm, (Word)aKey )) {
/* Found */
return sm->mbHasLocks;
} else {
Addr aKey = shmem__round_to_SecMap_base(a);
tl_assert(b == False || b == True);
if (HG_(lookupFM)( map_shmem,
- NULL/*keyP*/, (Word*)(void*)&sm, (Word)aKey )) {
+ NULL/*keyP*/, (Word*)(HChar*)&sm, (Word)aKey )) {
/* Found; address of SecMap is in sm */
} else {
/* create a new one */
Addr aKey = shmem__round_to_SecMap_base(a);
tl_assert(b == False || b == True);
if (HG_(lookupFM)( map_shmem,
- NULL/*keyP*/, (Word*)(void*)&sm, (Word)aKey )) {
+ NULL/*keyP*/, (Word*)(HChar*)&sm, (Word)aKey )) {
/* Found; address of SecMap is in sm */
} else {
/* create a new one */
// gla == lk->guest_addr
HG_(initIterFM)( map_locks );
while (HG_(nextIterFM)( map_locks,
- (Word*)(void*)&gla, (Word*)(void*)&lk )) {
+ (Word*)(HChar*)&gla, (Word*)(HChar*)&lk )) {
if (lk->guestaddr != gla) BAD("2");
}
HG_(doneIterFM)( map_locks );
Word count;
HG_(initIterBag)( lk->heldBy );
while (HG_(nextIterBag)( lk->heldBy,
- (Word*)(void*)&thr, &count )) {
+ (Word*)(HChar*)&thr, &count )) {
// is_sane_LockN above ensures these
tl_assert(count >= 1);
tl_assert(is_sane_Thread(thr));
HG_(initIterFM)( map_shmem );
// for sm in SecMaps {
while (HG_(nextIterFM)( map_shmem,
- (Word*)(void*)&smga, (Word*)(void*)&sm )) {
+ (Word*)(HChar*)&smga, (Word*)(HChar*)&sm )) {
SecMapIter itr;
UInt* w32p;
Bool mbHasShared = False;
ExeContext* ec_hint = NULL;
if (ga_to_lastlock != NULL
&& HG_(lookupFM)(ga_to_lastlock,
- NULL, (Word*)(void*)&ec_hint, ga)) {
+ NULL, (Word*)(HChar*)&ec_hint, ga)) {
tl_assert(ec_hint != NULL);
return ec_hint;
} else {
/* FIXME: don't iterate over the complete lock set */
HG_(initIterFM)( map_locks );
while (HG_(nextIterFM)( map_locks,
- (Word*)(void*)&gla, (Word*)(void*)&lk )) {
+ (Word*)(HChar*)&gla, (Word*)(HChar*)&lk )) {
tl_assert(is_sane_LockN(lk));
if (gla < firstA || gla > lastA)
continue;
HG_(initIterFM)( map_shmem );
while (HG_(nextIterFM)( map_shmem,
- (Word*)(void*)&ga, (Word*)(void*)&sm )) {
+ (Word*)(HChar*)&ga, (Word*)(HChar*)&sm )) {
tl_assert(sm);
stats_SMs++;
/* Skip this SecMap if the summary bit indicates it is safe to
stats_SMs = stats_SMs_scanned = stats_reExcls = 0;
HG_(initIterFM)( map_shmem );
while (HG_(nextIterFM)( map_shmem,
- (Word*)(void*)&ga, (Word*)(void*)&sm )) {
+ (Word*)(HChar*)&ga, (Word*)(HChar*)&sm )) {
SecMapIter itr;
UInt* w32p;
tl_assert(sm);
edge back to it. */
signalling_seg = NULL;
found = HG_(lookupFM)( map_cond_to_Segment,
- NULL, (Word*)(void*)&signalling_seg,
+ NULL, (Word*)(HChar*)&signalling_seg,
(Word)cond );
if (found) {
tl_assert(is_sane_Segment(signalling_seg));
tl_assert(seg);
map_sem_to_Segment_stack_INIT();
if (HG_(lookupFM)( map_sem_to_Segment_stack,
- NULL, (Word*)(void*)&xa, (Word)sem )) {
+ NULL, (Word*)(HChar*)&xa, (Word)sem )) {
tl_assert(xa);
VG_(addToXA)( xa, &seg );
} else {
Segment* seg;
map_sem_to_Segment_stack_INIT();
if (HG_(lookupFM)( map_sem_to_Segment_stack,
- NULL, (Word*)(void*)&xa, (Word)sem )) {
+ NULL, (Word*)(HChar*)&xa, (Word)sem )) {
/* xa is the stack for this semaphore. */
Word sz = VG_(sizeXA)( xa );
tl_assert(sz >= 0);
HG_(initIterFM)( laog );
me = NULL;
links = NULL;
- while (HG_(nextIterFM)( laog, (Word*)(void*)&me,
- (Word*)(void*)&links )) {
+ while (HG_(nextIterFM)( laog, (Word*)(HChar*)&me,
+ (Word*)(HChar*)&links )) {
tl_assert(me);
tl_assert(links);
VG_(printf)(" node %p:\n", me);
/* Update the out edges for src */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)(void*)&links, (Word)src )) {
+ if (HG_(lookupFM)( laog, &keyW, (Word*)(HChar*)&links, (Word)src )) {
WordSetID outs_new;
tl_assert(links);
tl_assert(keyW == (Word)src);
/* Update the in edges for dst */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)(void*)&links, (Word)dst )) {
+ if (HG_(lookupFM)( laog, &keyW, (Word*)(HChar*)&links, (Word)dst )) {
WordSetID inns_new;
tl_assert(links);
tl_assert(keyW == (Word)dst);
/* Update the out edges for src */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)(void*)&links, (Word)src )) {
+ if (HG_(lookupFM)( laog, &keyW, (Word*)(HChar*)&links, (Word)src )) {
tl_assert(links);
tl_assert(keyW == (Word)src);
links->outs = HG_(delFromWS)( univ_laog, links->outs, (Word)dst );
/* Update the in edges for dst */
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)(void*)&links, (Word)dst )) {
+ if (HG_(lookupFM)( laog, &keyW, (Word*)(HChar*)&links, (Word)dst )) {
tl_assert(links);
tl_assert(keyW == (Word)dst);
links->inns = HG_(delFromWS)( univ_laog, links->inns, (Word)src );
LAOGLinks* links;
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)(void*)&links, (Word)lk )) {
+ if (HG_(lookupFM)( laog, &keyW, (Word*)(HChar*)&links, (Word)lk )) {
tl_assert(links);
tl_assert(keyW == (Word)lk);
return links->outs;
LAOGLinks* links;
keyW = 0;
links = NULL;
- if (HG_(lookupFM)( laog, &keyW, (Word*)(void*)&links, (Word)lk )) {
+ if (HG_(lookupFM)( laog, &keyW, (Word*)(HChar*)&links, (Word)lk )) {
tl_assert(links);
tl_assert(keyW == (Word)lk);
return links->inns;
me = NULL;
links = NULL;
if (0) VG_(printf)("laog sanity check\n");
- while (HG_(nextIterFM)( laog, (Word*)(void*)&me,
- (Word*)(void*)&links )) {
+ while (HG_(nextIterFM)( laog, (Word*)(HChar*)&me,
+ (Word*)(HChar*)&links )) {
tl_assert(me);
tl_assert(links);
HG_(getPayloadWS)( &ws_words, &ws_size, univ_laog, links->inns );
key.dst_ec = NULL;
found = NULL;
if (HG_(lookupFM)( laog_exposition,
- (Word*)(void*)&found, NULL, (Word)&key )) {
+ (Word*)(HChar*)&found, NULL, (Word)&key )) {
tl_assert(found != &key);
tl_assert(found->src_ga == key.src_ga);
tl_assert(found->dst_ga == key.dst_ga);
(void*)args[1]);
map_pthread_t_to_Thread_INIT();
found = HG_(lookupFM)( map_pthread_t_to_Thread,
- NULL, (Word*)(void*)&thr_q, (Word)args[1] );
+ NULL, (Word*)(HChar*)&thr_q, (Word)args[1] );
/* Can this fail? It would mean that our pthread_join
wrapper observed a successful join on args[1] yet that
thread never existed (or at least, it never lodged an
tl_assert(string_table);
}
if (HG_(lookupFM)( string_table,
- NULL, (Word*)(void*)©, (Word)str )) {
+ NULL, (Word*)(HChar*)©, (Word)str )) {
tl_assert(copy);
if (0) VG_(printf)("string_table_strdup: %p -> %p\n", str, copy );
return copy;
yaWFM = HG_(newFM)( hg_zalloc, hg_free, lock_unique_cmp );
tl_assert(yaWFM);
}
- if (!HG_(lookupFM)( yaWFM, NULL, (Word*)(void*)&lkp, (Word)lkn)) {
+ if (!HG_(lookupFM)( yaWFM, NULL, (Word*)(HChar*)&lkp, (Word)lkn)) {
lkp = hg_zalloc( sizeof(Lock) );
*lkp = *lkn;
lkp->admin = NULL;