public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix s390* atomic.h
@ 2003-03-21 23:49 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2003-03-21 23:49 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

Hi!

This is on top of my earlier atomic.h patch.
Due to a typo tst-atomic seemed to suceed on some arches altough it actually
failed (like on s390*).
s390/bits/atomic.h had 2 problems: __old clashed with __old use in
include/atomic.h and then there was an aliasing problem: if mem type
is not unsigned int, but say unsigned long or pointer (on 32-bit),
then code using atomic_compare_and_exchange_val_acq would access the
same object using different types (this resulted in 2 checks failed
in tst-atomic-long with -O2 and -O3).

2003-03-22  Jakub Jelinek  <jakub@redhat.com>

	* csu/tst-atomic.c (do_test): Return ret, not 0.
	* sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_32_acq):
	Use __typeof for local variables types instead of assuming int.
	Change prefix of local variables to __arch.

--- libc/csu/tst-atomic.c.jj	2003-03-21 11:41:50.000000000 -0500
+++ libc/csu/tst-atomic.c	2003-03-21 17:48:53.000000000 -0500
@@ -269,7 +269,7 @@ do_test (void)
     }
 #endif
 
-  return 0;
+  return ret;
 }
 
 #define TEST_FUNCTION do_test ()
--- libc/sysdeps/s390/bits/atomic.h.jj	2003-03-21 08:23:32.000000000 -0500
+++ libc/sysdeps/s390/bits/atomic.h	2003-03-21 18:23:44.000000000 -0500
@@ -52,21 +52,21 @@ typedef uintmax_t uatomic_max_t;
   (abort (), 0)
 
 #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
-  ({ unsigned int *__mem = (unsigned int *) (mem);			      \
-     unsigned int __old = (unsigned int) (oldval);			      \
+  ({ __typeof (mem) __archmem = (mem);					      \
+     __typeof (*mem) __archold = (oldval);				      \
      __asm __volatile ("cs %0,%2,%1"					      \
-		       : "+d" (__old), "=Q" (*__mem)			      \
-		       : "d" (newval), "m" (*__mem) : "cc" );		      \
-     __old; })
+		       : "+d" (__archold), "=Q" (*__archmem)		      \
+		       : "d" (newval), "m" (*__archmem) : "cc" );	      \
+     __archold; })
 
 #ifdef __s390x__
 # define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
-  ({ unsigned long int *__mem = (unsigned long int *) (mem);		      \
-     unsigned long int __old = (unsigned long int) (oldval);		      \
+  ({ __typeof (mem) __archmem = (mem);					      \
+     __typeof (*mem) __archold = (oldval);				      \
      __asm __volatile ("csg %0,%2,%1"					      \
-		       : "+d" (__old), "=Q" (*__mem)			      \
-		       : "d" (newval), "m" (*__mem) : "cc" );		      \
-     __old; })
+		       : "+d" (__archold), "=Q" (*__archmem)		      \
+		       : "d" (newval), "m" (*__archmem) : "cc" );	      \
+     __archold; })
 #else
 /* For 31 bit we do not really need 64-bit compare-and-exchange. We can
    implement them by use of the csd instruction. The straightforward

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-03-21 23:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-21 23:49 [PATCH] Fix s390* atomic.h 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).