public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Shut up gcc on include/ctype.h
@ 2003-07-29 17:17 Jakub Jelinek
  2003-07-29 22:31 ` Roland McGrath
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2003-07-29 17:17 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

Hi!

I remember we were discussing this, but don't remember the results.
Anyway, this patch seems to make zero difference on generated code
while shutting up the warning.

2003-07-29  Jakub Jelinek  <jakub@redhat.com>

	* include/ctype.h (__ctype_b_loc, __ctype_toupper_loc,
	__ctype_tolower_loc): Avoid "dereferencing type-punned pointer will
	break strict-aliasing rules" warnings.

--- libc/include/ctype.h.jj	2003-03-17 19:37:46.000000000 -0500
+++ libc/include/ctype.h	2003-07-29 13:12:30.000000000 -0400
@@ -25,31 +25,43 @@ __libc_tsd_define (extern, CTYPE_TOLOWER
 CTYPE_EXTERN_INLINE const uint16_t ** __attribute__ ((const))
 __ctype_b_loc (void)
 {
-  const uint16_t **tablep =
-    (const uint16_t **) __libc_tsd_address (CTYPE_B);
-  if (__builtin_expect (*tablep == NULL, 0))
-    *tablep = (const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128;
-  return tablep;
+  union
+    {
+      void **ptr;
+      const uint16_t **tablep;
+    } u;
+  u.ptr = __libc_tsd_address (CTYPE_B);
+  if (__builtin_expect (*u.tablep == NULL, 0))
+    *u.tablep = (const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128;
+  return u.tablep;
 }
 
 CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
 __ctype_toupper_loc (void)
 {
-  const int32_t **tablep =
-    (const int32_t **) __libc_tsd_address (CTYPE_TOUPPER);
-  if (__builtin_expect (*tablep == NULL, 0))
-    *tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128);
-  return tablep;
+  union
+    {
+      void **ptr;
+      const int32_t **tablep;
+    } u;
+  u.ptr = __libc_tsd_address (CTYPE_TOUPPER);
+  if (__builtin_expect (*u.tablep == NULL, 0))
+    *u.tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128);
+  return u.tablep;
 }
 
 CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
 __ctype_tolower_loc (void)
 {
-  const int32_t **tablep =
-    (const int32_t **) __libc_tsd_address (CTYPE_TOLOWER);
-  if (__builtin_expect (*tablep == NULL, 0))
-    *tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128);
-  return tablep;
+  union
+    {
+      void **ptr;
+      const int32_t **tablep;
+    } u;
+  u.ptr = __libc_tsd_address (CTYPE_TOLOWER);
+  if (__builtin_expect (*u.tablep == NULL, 0))
+    *u.tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128);
+  return u.tablep;
 }
 
 # endif	/* Not NOT_IN_libc.  */

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Shut up gcc on include/ctype.h
  2003-07-29 17:17 [PATCH] Shut up gcc on include/ctype.h Jakub Jelinek
@ 2003-07-29 22:31 ` Roland McGrath
  2003-07-29 23:34   ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Roland McGrath @ 2003-07-29 22:31 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers

> I remember we were discussing this, but don't remember the results.
> Anyway, this patch seems to make zero difference on generated code
> while shutting up the warning.

Hmm.  We went a few rounds on this at the beginning, and my recollection
was that I couldn't find a formulation that didn't produce some warning or
other.  Did the compiler change?  Or did I just overlook the obvious fix?


Thanks,
Roland

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Shut up gcc on include/ctype.h
  2003-07-29 22:31 ` Roland McGrath
@ 2003-07-29 23:34   ` Jakub Jelinek
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2003-07-29 23:34 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Ulrich Drepper, Glibc hackers

On Tue, Jul 29, 2003 at 03:31:49PM -0700, Roland McGrath wrote:
> > I remember we were discussing this, but don't remember the results.
> > Anyway, this patch seems to make zero difference on generated code
> > while shutting up the warning.
> 
> Hmm.  We went a few rounds on this at the beginning, and my recollection
> was that I couldn't find a formulation that didn't produce some warning or
> other.  Did the compiler change?  Or did I just overlook the obvious fix?

I don't think it did.
But certainly I don't get a single warning about ctype.h with the posted
patch in gcc-3.3-16 (and gcc-3.2.x did not even had that warning).

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-29 23:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-29 17:17 [PATCH] Shut up gcc on include/ctype.h Jakub Jelinek
2003-07-29 22:31 ` Roland McGrath
2003-07-29 23:34   ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).