This is the mail archive of the mailing list for the glibc 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]

Re: [PATCH] aliasing warning in ctype.h

On Fri, Mar 21, 2003 at 01:22:27AM +0100, Jakub Jelinek wrote:
> The code gcc warns about always accesses that word of memory using
> a const uint16_t ** pointer which is ok from the standard point of view.
> GCC cannot know though if you don't access the same piece of memory
> somewhere using the declared type.
> The code in the patch Ian posted compares that word of memory with NULL
> using void ** pointer, stores it through that pointer if it was NULL
> too, but then reads through that pointer using const uint16_t ** pointer
> (this is already not in __ctype_b_loc, but in the function
> which inlines it; e.g. isctype does
> ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
> ).

ok just so i'm sure i understand, the problem is that 

+    *tablep = ((void *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128);

casts the value pointed to by tablep to void*, but isctype sees the
return from __ctype_b_loc as uint16_t ** thus dereferences the return
to a uint16_t*.  ergo the same memory is accessed as two different

in that case, what about using a union?  

CTYPE_EXTERN_INLINE const uint16_t ** __attribute__ ((const))
__ctype_b_loc (void)
  union {
    const uint16_t **t;
    void ** p;
  } tablep;
  tablep.p = __libc_tsd_address (CTYPE_B);
  if (__builtin_expect (*tablep.p == NULL, 0))
    *tablep.t = (const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128;
  return tablep.t;


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