glibc/misc/tst-atomic.c

265 lines
6.4 KiB
C
Raw Normal View History

* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
/* Tests for atomic.h macros.
Copyright (C) 2003-2025 Free Software Foundation, Inc.
* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
Prefer https to http for gnu.org and fsf.org URLs Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
<https://www.gnu.org/licenses/>. */
* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
tst-atomic.c: Mark as UNSUPPORTED when compiled with Clang Since Clang can't remove the dead statement and issues an error: tst-atomic.c:463:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*&mem)' (aka 'int') 463 | if (catomic_exchange_and_add (&mem, 11) != 2 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add' 213 | __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 | mem, value) | ~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body' 198 | : "=r" (__result), "=m" (*mem) \ | ~~~~~~~~ 199 | : "0" ((int64_t) cast_to_integer (__addval)), \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tst-atomic.c:487:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*(&mem))' (aka 'int') 487 | if (catomic_increment_val (&mem) != 3) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/atomic.h:313:38: note: expanded from macro 'catomic_increment_val' 313 | # define catomic_increment_val(mem) (catomic_exchange_and_add ((mem), 1) + 1) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add' 213 | __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 | mem, value) | ~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body' 198 | : "=r" (__result), "=m" (*mem) \ | ~~~~~~~~ 199 | : "0" ((int64_t) cast_to_integer (__addval)), \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tst-atomic.c:501:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*(&mem))' (aka 'int') 501 | if (catomic_decrement_val (&mem) != 15) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/atomic.h:340:38: note: expanded from macro 'catomic_decrement_val' 340 | # define catomic_decrement_val(mem) (catomic_exchange_and_add ((mem), -1) - 1) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add' 213 | __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 | mem, value) | ~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body' 198 | : "=r" (__result), "=m" (*mem) \ | ~~~~~~~~ 199 | : "0" ((int64_t) cast_to_integer (__addval)), \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mark tst-atomic.c as UNSUPPORTED when compiled with Clang. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-16 10:56:55 +00:00
#ifndef __clang__
* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
#include <stdio.h>
#include <atomic.h>
#ifndef atomic_t
# define atomic_t int
#endif
/* Test various atomic.h macros. */
static int
do_test (void)
{
atomic_t mem, expected;
* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
int ret = 0;
#ifdef atomic_compare_and_exchange_val_acq
mem = 24;
if (atomic_compare_and_exchange_val_acq (&mem, 35, 24) != 24
|| mem != 35)
{
puts ("atomic_compare_and_exchange_val_acq test 1 failed");
ret = 1;
}
mem = 12;
if (atomic_compare_and_exchange_val_acq (&mem, 10, 15) != 12
|| mem != 12)
{
puts ("atomic_compare_and_exchange_val_acq test 2 failed");
ret = 1;
}
mem = -15;
if (atomic_compare_and_exchange_val_acq (&mem, -56, -15) != -15
|| mem != -56)
{
puts ("atomic_compare_and_exchange_val_acq test 3 failed");
ret = 1;
}
mem = -1;
if (atomic_compare_and_exchange_val_acq (&mem, 17, 0) != -1
|| mem != -1)
{
puts ("atomic_compare_and_exchange_val_acq test 4 failed");
ret = 1;
}
* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
#endif
mem = 24;
if (atomic_compare_and_exchange_bool_acq (&mem, 35, 24)
|| mem != 35)
{
puts ("atomic_compare_and_exchange_bool_acq test 1 failed");
ret = 1;
}
mem = 12;
if (! atomic_compare_and_exchange_bool_acq (&mem, 10, 15)
|| mem != 12)
{
puts ("atomic_compare_and_exchange_bool_acq test 2 failed");
ret = 1;
}
mem = -15;
if (atomic_compare_and_exchange_bool_acq (&mem, -56, -15)
|| mem != -56)
{
puts ("atomic_compare_and_exchange_bool_acq test 3 failed");
ret = 1;
}
mem = -1;
if (! atomic_compare_and_exchange_bool_acq (&mem, 17, 0)
|| mem != -1)
{
puts ("atomic_compare_and_exchange_bool_acq test 4 failed");
ret = 1;
}
* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
mem = 1;
if (atomic_decrement_if_positive (&mem) != 1
|| mem != 0)
{
puts ("atomic_decrement_if_positive test 1 failed");
ret = 1;
}
mem = 0;
if (atomic_decrement_if_positive (&mem) != 0
|| mem != 0)
{
puts ("atomic_decrement_if_positive test 2 failed");
ret = 1;
}
mem = -1;
if (atomic_decrement_if_positive (&mem) != -1
|| mem != -1)
{
puts ("atomic_decrement_if_positive test 3 failed");
ret = 1;
}
/* Tests for C11-like atomics. */
mem = 11;
if (atomic_load_relaxed (&mem) != 11 || atomic_load_acquire (&mem) != 11)
{
puts ("atomic_load_{relaxed,acquire} test failed");
ret = 1;
}
atomic_store_relaxed (&mem, 12);
if (mem != 12)
{
puts ("atomic_store_relaxed test failed");
ret = 1;
}
atomic_store_release (&mem, 13);
if (mem != 13)
{
puts ("atomic_store_release test failed");
ret = 1;
}
mem = 14;
expected = 14;
if (!atomic_compare_exchange_weak_relaxed (&mem, &expected, 25)
|| mem != 25 || expected != 14)
{
puts ("atomic_compare_exchange_weak_relaxed test 1 failed");
ret = 1;
}
if (atomic_compare_exchange_weak_relaxed (&mem, &expected, 14)
|| mem != 25 || expected != 25)
{
puts ("atomic_compare_exchange_weak_relaxed test 2 failed");
ret = 1;
}
mem = 14;
expected = 14;
if (!atomic_compare_exchange_weak_acquire (&mem, &expected, 25)
|| mem != 25 || expected != 14)
{
puts ("atomic_compare_exchange_weak_acquire test 1 failed");
ret = 1;
}
if (atomic_compare_exchange_weak_acquire (&mem, &expected, 14)
|| mem != 25 || expected != 25)
{
puts ("atomic_compare_exchange_weak_acquire test 2 failed");
ret = 1;
}
mem = 14;
expected = 14;
if (!atomic_compare_exchange_weak_release (&mem, &expected, 25)
|| mem != 25 || expected != 14)
{
puts ("atomic_compare_exchange_weak_release test 1 failed");
ret = 1;
}
if (atomic_compare_exchange_weak_release (&mem, &expected, 14)
|| mem != 25 || expected != 25)
{
puts ("atomic_compare_exchange_weak_release test 2 failed");
ret = 1;
}
mem = 23;
if (atomic_exchange_acquire (&mem, 42) != 23 || mem != 42)
{
puts ("atomic_exchange_acquire test failed");
ret = 1;
}
mem = 23;
if (atomic_exchange_release (&mem, 42) != 23 || mem != 42)
{
puts ("atomic_exchange_release test failed");
ret = 1;
}
mem = 23;
if (atomic_fetch_add_relaxed (&mem, 1) != 23 || mem != 24)
{
puts ("atomic_fetch_add_relaxed test failed");
ret = 1;
}
mem = 23;
if (atomic_fetch_add_acquire (&mem, 1) != 23 || mem != 24)
{
puts ("atomic_fetch_add_acquire test failed");
ret = 1;
}
mem = 23;
if (atomic_fetch_add_release (&mem, 1) != 23 || mem != 24)
{
puts ("atomic_fetch_add_release test failed");
ret = 1;
}
mem = 23;
if (atomic_fetch_add_acq_rel (&mem, 1) != 23 || mem != 24)
{
puts ("atomic_fetch_add_acq_rel test failed");
ret = 1;
}
mem = 3;
if (atomic_fetch_and_acquire (&mem, 2) != 3 || mem != 2)
{
puts ("atomic_fetch_and_acquire test failed");
ret = 1;
}
mem = 4;
if (atomic_fetch_or_relaxed (&mem, 2) != 4 || mem != 6)
{
puts ("atomic_fetch_or_relaxed test failed");
ret = 1;
}
mem = 4;
if (atomic_fetch_or_acquire (&mem, 2) != 4 || mem != 6)
{
puts ("atomic_fetch_or_acquire test failed");
ret = 1;
}
/* This is a single-threaded test, so we can't test the effects of the
fences. */
atomic_thread_fence_acquire ();
atomic_thread_fence_release ();
atomic_thread_fence_seq_cst ();
* include/atomic.h (atomic_increment_and_test): Invert sense of test. Add comment. (atomic_decrement_and_test): Add comment. 2003-03-22 Jakub Jelinek <jakub@redhat.com> * include/atomic.h (atomic_compare_and_exchange_val_acq): Add comment. Don't define if __arch_compare_and_exchange_val_32_acq is not defined. (atomic_compare_and_exchange_bool_acq): Add comment. Don't use __oldval variable in the macro, since it might be macro argument. (atomic_decrement_if_positive): Initialize __memp, remove setting of non-existent variable. (atomic_bit_test_set): Cast 1 to __typeof (*mem) before shifting. * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Implement using atomic_compare_and_exchange_val_acq. (atomic_decrement_if_positive, atomic_bit_test_set): Define. * sysdeps/s390/bits/atomic.h (__arch_compare_and_exchange_val_8_acq): Renamed from... (__arch_compare_and_exchange_bool_8_acq): ... this. (__arch_compare_and_exchange_val_16_acq): Renamed from... (__arch_compare_and_exchange_bool_16_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_32_acq): ... this. (__arch_compare_and_exchange_val_64_acq): Return old value. Renamed from... (__arch_compare_and_exchange_bool_64_acq): ... this. (__arch_compare_and_exchange_val_32_acq): Use __typeof for local variables types instead of assuming int. Change prefix of local variables to __arch. * sysdeps/generic/bits/atomic.h (arch_compare_and_exchange_acq): Remove. (atomic_compare_and_exchange_val_acq, atomic_compare_and_exchange_bool_acq): Define. * csu/tst-atomic.c: New test. * csu/tst-atomic-long.c: New test. * csu/Makefile (tests): Add tst-atomic and tst-atomic-long. * malloc/memusagestat.c (main): Kill warning if uint64_t is ulong. * sysdeps/s390/Versions: Add trailing newline. * sysdeps/unix/sysv/linux/sysconf.c (__sysconf): Kill warning if INTERNAL_SYSCALL_ERROR_P doesn't use its first argument.
2003-03-22 23:01:01 +00:00
return ret;
}
#include <support/test-driver.c>
tst-atomic.c: Mark as UNSUPPORTED when compiled with Clang Since Clang can't remove the dead statement and issues an error: tst-atomic.c:463:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*&mem)' (aka 'int') 463 | if (catomic_exchange_and_add (&mem, 11) != 2 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add' 213 | __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 | mem, value) | ~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body' 198 | : "=r" (__result), "=m" (*mem) \ | ~~~~~~~~ 199 | : "0" ((int64_t) cast_to_integer (__addval)), \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tst-atomic.c:487:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*(&mem))' (aka 'int') 487 | if (catomic_increment_val (&mem) != 3) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/atomic.h:313:38: note: expanded from macro 'catomic_increment_val' 313 | # define catomic_increment_val(mem) (catomic_exchange_and_add ((mem), 1) + 1) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add' 213 | __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 | mem, value) | ~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body' 198 | : "=r" (__result), "=m" (*mem) \ | ~~~~~~~~ 199 | : "0" ((int64_t) cast_to_integer (__addval)), \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tst-atomic.c:501:7: error: unsupported inline asm: input with type 'int64_t' (aka 'long') matching output with type 'typeof (*(&mem))' (aka 'int') 501 | if (catomic_decrement_val (&mem) != 15) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/atomic.h:340:38: note: expanded from macro 'catomic_decrement_val' 340 | # define catomic_decrement_val(mem) (catomic_exchange_and_add ((mem), -1) - 1) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:213:3: note: expanded from macro 'catomic_exchange_and_add' 213 | __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 | mem, value) | ~~~~~~~~~~~ ../sysdeps/x86/atomic-machine.h:199:12: note: expanded from macro '__arch_exchange_and_add_body' 198 | : "=r" (__result), "=m" (*mem) \ | ~~~~~~~~ 199 | : "0" ((int64_t) cast_to_integer (__addval)), \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mark tst-atomic.c as UNSUPPORTED when compiled with Clang. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-16 10:56:55 +00:00
#else
#include <support/test-driver.h>
int
main (void)
{
return EXIT_UNSUPPORTED;
}
#endif