Author: sewardj
Date: 2007-11-10 22:50:13 +0000 (Sat, 10 Nov 2007)
New Revision: 7141

Log:
Followup to r7105: stop gcc complaining about violations of ANSI C
aliasing rules by casting through (char*) as an intermediate type,
rather than through (void*).  This seems at least moderately
justifiable since the ANSI C standard explicitly says that any object
may be accessed through a char pointer.

Modified:
   trunk/helgrind/hg_main.c
   trunk/helgrind/hg_wordset.c


Modified: trunk/helgrind/hg_main.c
===================================================================
--- trunk/helgrind/hg_main.c    2007-11-10 22:19:42 UTC (rev 7140)
+++ trunk/helgrind/hg_main.c    2007-11-10 22:50:13 UTC (rev 7141)
@@ -60,12 +60,23 @@
 /*----------------------------------------------------------------*/
 
 /* 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?
 
@@ -630,7 +641,7 @@
    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;
    }
@@ -825,7 +836,7 @@
    }
    /* 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 ));
@@ -1107,7 +1118,7 @@
       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)("}");
@@ -1141,8 +1152,8 @@
    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);
    }
@@ -1189,8 +1200,8 @@
    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);
    }
@@ -1309,8 +1320,8 @@
    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 );
@@ -1522,7 +1533,7 @@
    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 );
@@ -1546,7 +1557,7 @@
 {
    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?
@@ -1560,7 +1571,7 @@
    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. */
@@ -1584,7 +1595,7 @@
    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;
@@ -1596,7 +1607,7 @@
    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;
 }
@@ -2346,7 +2357,7 @@
    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 {
@@ -2368,7 +2379,7 @@
    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 {
@@ -2382,7 +2393,7 @@
    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 */
@@ -2399,7 +2410,7 @@
    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 */
@@ -2559,7 +2570,7 @@
    //      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 );
@@ -2582,7 +2593,7 @@
          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));
@@ -2673,7 +2684,7 @@
    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;
@@ -2944,7 +2955,7 @@
    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 {
@@ -4942,7 +4953,7 @@
    /* 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;
@@ -4991,7 +5002,7 @@
 
      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
@@ -5655,7 +5666,7 @@
    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);
@@ -6150,7 +6161,7 @@
          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));
@@ -6346,7 +6357,7 @@
    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 {
@@ -6361,7 +6372,7 @@
    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);
@@ -6569,8 +6580,8 @@
    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);
@@ -6607,7 +6618,7 @@
    /* 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);
@@ -6623,7 +6634,7 @@
    /* 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);
@@ -6674,7 +6685,7 @@
    /* 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 );
@@ -6682,7 +6693,7 @@
    /* 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 );
@@ -6695,7 +6706,7 @@
    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;
@@ -6710,7 +6721,7 @@
    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;
@@ -6731,8 +6742,8 @@
    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 );
@@ -6866,7 +6877,7 @@
       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);
@@ -7504,7 +7515,7 @@
                      (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
@@ -7656,7 +7667,7 @@
       tl_assert(string_table);
    }
    if (HG_(lookupFM)( string_table,
-                      NULL, (Word*)(void*)&copy, (Word)str )) {
+                      NULL, (Word*)(HChar*)&copy, (Word)str )) {
       tl_assert(copy);
       if (0) VG_(printf)("string_table_strdup: %p -> %p\n", str, copy );
       return copy;
@@ -7690,7 +7701,7 @@
       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;

Modified: trunk/helgrind/hg_wordset.c
===================================================================
--- trunk/helgrind/hg_wordset.c 2007-11-10 22:19:42 UTC (rev 7140)
+++ trunk/helgrind/hg_wordset.c 2007-11-10 22:50:13 UTC (rev 7141)
@@ -281,7 +281,7 @@
       causes failures on a 64-bit platform. */
    tl_assert(wv_new->owner == wsu);
    have = HG_(lookupFM)( wsu->vec2ix, 
-                         (Word*)(void*)&wv_old, (Word*)&ix_old,
+                         (Word*)(HChar*)&wv_old, (Word*)&ix_old,
                          (Word)wv_new );
    if (have) {
       tl_assert(wv_old != wv_new);


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to