Ivan Maidanski [Mon, 20 Feb 2017 19:16:54 +0000 (22:16 +0300)]
Eliminate 'condition sizeof(long)>4 is always true' cppcheck style warning
* src/atomic_ops_malloc.c (msb): Cast (s >> 32) to unsigned int type
before assigning the result to v; check __SIZEOF_SIZE_T__ value (if
defined) to decide whether (s >> 32) is needed; move condition
(sizeof(size_t) > 4) to SIZEOF_SIZE_T_GT_4 macro (to eliminate cppcheck
false report that the condition is always true).
Ivan Maidanski [Mon, 20 Feb 2017 08:10:07 +0000 (11:10 +0300)]
Workaround 'AM_EXTRA_RECURSIVE_TARGETS not found in library' autoconf error
(fix commit 3b7e732)
* Makefile.am (.PHONY): Add check-nolink, check-nolink-local targets.
* Makefile.am (check-nolink): New target (which invokes existing
check-nolink-local in this Makefile and in tests/Makefile).
* configure.ac (AM_EXTRA_RECURSIVE_TARGETS): Remove (this directive
is not supported by autoconf-1.12 and earlier).
Ivan Maidanski [Sat, 18 Feb 2017 07:23:33 +0000 (10:23 +0300)]
Add Makefile target to run all tests without test-driver
This could be used to catch errors reported by MemorySanitizer
(the traditional "make check" shows the tests with MSan errors as
skipped, so it does not lead to a non-zero exit code of make itself).
* tests/Makefile.am (check-without-test-driver): New phony target (to
compile, link and execute all tests not using test-driver).
Ivan Maidanski [Sat, 18 Feb 2017 06:21:58 +0000 (09:21 +0300)]
Add Makefile target (check-nolink) to compile all source without linking
Note: it is assumed --enable-shared is not passed to configure.
* Makefile.am (check-nolink-local): New Makefile phony target (just
redirects to "all").
* configure.ac: Define check-nolink by AM_EXTRA_RECURSIVE_TARGETS.
* tests/Makefile.am (TEST_OBJS): New variable (with a list of the test
.o files).
* tests/Makefile.am (check-nolink-local): New Makefile phony target
(forces all tests to be compiled but not linked).
Ivan Maidanski [Fri, 17 Feb 2017 20:48:23 +0000 (23:48 +0300)]
Refine documentation in Makefile.msft how to run all tests (MS VC)
* src/Makefile.msft: Refine comment about all tests execution
("make check" is redundant, it is enough to run only "make" to
auto-generate list_atomic.c and test_atomic_include.h).
Ivan Maidanski [Fri, 17 Feb 2017 20:27:19 +0000 (23:27 +0300)]
Move libraries version info to the beginning of Makefile.am
(code refactoring)
* src/Makefile.am (LIBATOMIC_OPS_VER_INFO, LIBATOMIC_OPS_GPL_VER_INFO):
New variable; add comment about the version update rule.
* src/Makefile.am (libatomic_ops_la_LDFLAGS,
libatomic_ops_gpl_la_LDFLAGS): Use LIBATOMIC_OPS_[GPL_]VER_INFO
instead direct hard-coding of version info.
Ivan Maidanski [Fri, 17 Feb 2017 08:51:30 +0000 (11:51 +0300)]
Travis CI: Also test with Memory and Unexpected Behavior sanitizers
Note: Currently an error found by MSan/UBSan does not cause Travis build
to fail, the log should be examined manually for the absence of
"MemorySanitizer" and "runtime error" character sequences (the error
messages are shown in red).
Ivan Maidanski [Fri, 27 Jan 2017 16:35:20 +0000 (19:35 +0300)]
Use generalized load/store if AO_PREFER_GENERALIZED (gcc/generic)
Note: AO_PREFER_GENERALIZED macro is for testing generalize.h mainly.
* src/atomic_ops/sysdeps/gcc/generic-small.template (AO_XSIZE_load,
AO_XSIZE_load_acquire, AO_XSIZE_store, AO_XSIZE_store_release): Do not
define if AO_GCC_HAVE_XSIZE_SYNC_CAS and AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/gcc/generic-small.h: Regenerate.
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE]
(AO_GCC_HAVE_double_SYNC_CAS): Move the definition upper to be before
AO_double_load.
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE]
(AO_double_load, AO_double_load_acquire, AO_double_store,
AO_double_store_release): Do not define if AO_GCC_HAVE_double_SYNC_CAS
and AO_PREFER_GENERALIZED.
Ivan Maidanski [Thu, 26 Jan 2017 20:07:57 +0000 (23:07 +0300)]
Enable limited testing in Makefile.msft without Cygwin
New target "check-noautogen" is introduced in Makefile.msft to build and
run only test_malloc and test_stack (which do not need test code
auto-generation by sed).
* src/Makefile.msft: Refine comment about tests execution; add comment
about "check-noautogen" target.
* src/Makefile.msft (check): Add dependency on check-noautogen;
move test_malloc and test_stack to check-noautogen.
* src/Makefile.msft (check-noautogen): New target (executes test_malloc
and test_stack only).
Ivan Maidanski [Thu, 26 Jan 2017 07:38:21 +0000 (10:38 +0300)]
Implement AO_CLEAR using C11 atomic intrinsic (GCC)
* src/atomic_ops/sysdeps/gcc/generic.h [!AO_PREFER_GENERALIZED]
(AO_CLEAR): Implement using GCC built-in __atomic_clear (thus
overriding the default one based on AO_char_store_release).
Hans Boehm [Thu, 26 Jan 2017 07:16:54 +0000 (10:16 +0300)]
Implement compiler_barrier using C11 __atomic_signal_fence (GCC)
Use __atomic_signal_fence(__ATOMIC_SEQ_CST) as AO_compiler_barrier.
That was the intended use of __atomic_signal_fence. The only
standards-relevant context in which you can tell apart a compiler and
real fence is in the case if signal handlers.
* src/atomic_ops/sysdeps/gcc/generic.h (AO_compiler_barrier): Redefine
using GCC atomic intrinsic (__atomic_signal_fence).
Ivan Maidanski [Tue, 24 Jan 2017 19:46:57 +0000 (22:46 +0300)]
Fix test_atomic failure caused unaligned AO_double_t access on x86
The failure is caused by violation of an assertion that checks
AO_double_t variable is 8-byte aligned on x86.
* doc/README.txt (AO_double_t): Add note about required alignment.
* src/atomic_ops/sysdeps/standard_ao_double_t.h (AO_double_t): Add
comment about alignment.
* src/atomic_ops_stack.h (AO_stack_t): Likewise.
* tests/test_atomic_include.template (test_atomicXX): Define old_w, w
local variables as static (as otherwise, e.g., they could have 4-byte
alignment on x86); add comment.
The failure is actually caused by the fact that default alignment of
stack on x86 is 4 bytes.
So, another solution should be proposed to fix the issue for other
compilers (and, potentially, other targets). E.g. do not place
AO_double_t volatile variables on stack.
Ivan Maidanski [Fri, 20 Jan 2017 08:58:13 +0000 (11:58 +0300)]
Fix test_atomic failure caused unaligned AO_double_t access on x86 (VC++)
Passing an unaligned AO_double_t pointer to AO double-wide primitives
results in an undefined behavior of the latter when running on x86 (or
violation of the corresponding assertion on the alignment).
MS VC++/x86 aligns AO_double_t values on a 4-byte boundary by default.
For the proper alignment, __declspec(align(8)) should be applied to
variables defined in the client code (which uses double-wide AO
primitives). Unfortunately, the attribute cannot be added to
AO_double_t definition itself because the compiler does not allow the
attribute for function arguments.
This patch introduces AO_DOUBLE_ALIGN attribute for use by clients of
the double-wide AO primitives (and, thus, AO_stack clients).
Matters only Visual Studio compiler for X86.
The inner clients (atomic_ops_malloc, test_atomic, test_stack) are
updated to use this attribute.
* doc/README_win32.txt [x86] (AO_DOUBLE_ALIGN): Document.
* src/atomic_ops/sysdeps/generic_pthread.h (AO_DOUBLE_ALIGN): Define
(as empty).
* src/atomic_ops/sysdeps/standard_ao_double_t.h [!_WIN64 && _WIN32
&& !__GNUC__ && _MSC_VER] (AO_DOUBLE_ALIGN): Define as declspec
align(8); document it.
* src/atomic_ops/sysdeps/standard_ao_double_t.h [!AO_DOUBLE_ALIGN]
(AO_DOUBLE_ALIGN): Define as empty (otherwise).
* src/atomic_ops_stack.h [AO_USE_ALMOST_LOCK_FREE && !AO_DOUBLE_ALIGN]
(AO_DOUBLE_ALIGN): Likewise.
* src/atomic_ops_malloc.c (AO_free_list): Use AO_DOUBLE_ALIGN attribute.
* tests/test_stack.c (the_list): Likewise.
* src/atomic_ops_stack.h [!AO_USE_ALMOST_LOCK_FREE] (AO_stack_t):
Document AO_DOUBLE_ALIGN usage (by clients).
* tests/test_atomic_include.template (test_atomicXX): Use
AO_DOUBLE_ALIGN attribute for old_w and w double-wide local variables
(to avoid alignment assertion violation or AO primitives undefined
behavior on x86 if the test code is compiled by VC++).
Ivan Maidanski [Fri, 20 Jan 2017 00:03:54 +0000 (03:03 +0300)]
Add assertion that double-wide CAS target is aligned (msftc/x86[_64])
* src/atomic_ops/sysdeps/msftc/x86.h [AO_ASSUME_VISTA]
(AO_double_compare_and_swap_full): Add assert() that addr pointer is
aligned according to the size of AO_double_t.
* src/atomic_ops/sysdeps/msftc/x86_64.h [AO_CMPXCHG16B_AVAILABLE
&& _MSC_VER>=1500] (AO_compare_double_and_swap_double_full): Likewise.
Ivan Maidanski [Thu, 19 Jan 2017 07:03:59 +0000 (10:03 +0300)]
Fix turn off optimization in case of configure --enable-gcov
(fix commit 0d0a16d)
* configure.ac [enable_gcov] (CFLAGS): Change sed regular expression
to avoid [] (as they are not properly handled during autogen), and to
also filter out -Os and -Ofast (-O0 is ignored).
Ivan Maidanski [Wed, 7 Dec 2016 09:35:47 +0000 (12:35 +0300)]
Eliminate 'printf format specifies type void*' GCC pedantic warnings
This commit also eliminates 'cast from pointer to integer' compiler
warnings and '32-bit value shift followed by expansion to 64-bit'
static analysis tool warning.
* src/atomic_ops_malloc.c [AO_TRACE_MALLOC] (AO_malloc, AO_free):
Use %p (instead of %x) format specifier to print pthread_self() value
(and cast pthread_self() to void*).
* src/atomic_ops_malloc.c [AO_TRACE_MALLOC] (AO_malloc): Cast result+1
to void* (to match %p printf format specifier).
* src/atomic_ops_malloc.c [AO_TRACE_MALLOC] (AO_free): Use "UL" suffix
for 1 and remove the cast to unsigned long (instead of performing left
shift of an integer value and extending the result to unsigned long).
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE
&& !AO_HAVE_double_store] (AO_double_store): Do not define if
AO_SKIPATOMIC_double_store.
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE
&& !AO_HAVE_double_store_release] (AO_double_store_release): Do not
define if AO_SKIPATOMIC_double_load.
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& __clang__ && !__x86_64__ && !__APPLE_CC__ && !__CYGWIN__
&& !AO_PREFER_BUILTIN_ATOMICS] (AO_SKIPATOMIC_double_load,
AO_SKIPATOMIC_double_load_acquire, AO_SKIPATOMIC_double_store,
AO_SKIPATOMIC_double_store_release): Define internal macro (undefined
at the end of file).
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& (__clang__ && !__x86_64__ && !__APPLE_CC__ && !__CYGWIN__
&& !AO_PREFER_BUILTIN_ATOMICS) || (__APPLE_CC__ && __x86_64__))]
(AO_SKIPATOMIC_double_compare_and_swap_ANY): Move definition here
(remove at other places in this file); undefine at the end of the file.
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET]: Check
AO_SKIPATOMIC_double_compare_and_swap_ANY instead of checking multiple
macros to detect whether a workaround for the CAS (and others)
double-wide operations is needed.
Ivan Maidanski [Tue, 22 Nov 2016 01:18:08 +0000 (04:18 +0300)]
Report gcc/clang pedantic warnings (configure)
* configure.ac [GCC] (WPEDANTIC): New variable (set to
"-Wpedantic -Wno-long-long" if supported by the compiler).
* configure.ac [GCC] (CFLAGS): Add $WPEDANTIC.
Tobias Leich [Thu, 10 Nov 2016 08:02:56 +0000 (09:02 +0100)]
Implement fetch-CAS for s390[x] (gcc)
* src/atomic_ops/sysdeps/gcc/s390.h (AO_compare_and_swap_full): Do not
define if AO_GENERALIZE_ASM_BOOL_CAS.
* src/atomic_ops/sysdeps/gcc/s390.h (AO_fetch_compare_and_swap_full):
Implement; remove TODO item.
Ivan Maidanski [Tue, 1 Nov 2016 08:25:39 +0000 (11:25 +0300)]
Fix reporting about missing and/or/xor_dd_acquire_read (test_atomic)
AO_XSIZE_and/or/xor_dd_acquire_read are meaningless and not implemented,
thus their absence is not reported in the tests.
* tests/test_atomic_include.template [!AO_HAVE_orXX] (test_atomicXX):
Do not call MISSING(AO_or) if all AO_HAVE_or* excluding
AO_HAVE_or_dd_acquire_read are not defined.
* tests/test_atomic_include.template [!AO_HAVE_xorXX] (test_atomicXX):
Do not call MISSING(AO_xor) if all AO_HAVE_xor* excluding
AO_HAVE_xor_dd_acquire_read are not defined.
* tests/test_atomic_include.template [!AO_HAVE_andXX] (test_atomicXX):
Do not call MISSING(AO_and) if all AO_HAVE_and* excluding
AO_HAVE_and_dd_acquire_read are not defined.
This matters only if AO_double_compare_and_swap[_acquire_read] actually
defined in generalize.h too.
* src/atomic_ops/generalize.h
[!AO_HAVE_double_compare_and_swap_dd_acquire_read]
(AO_double_compare_and_swap_dd_acquire_read): Define (same as definition
as auto-generated in generalize-small.h).
Ivan Maidanski [Wed, 26 Oct 2016 08:57:13 +0000 (11:57 +0300)]
Workaround 'value of MAP_ANON unknown' cppcheck info message
(fix commit 4c303bc)
* src/atomic_ops_malloc.c [USE_MMAP_ANON && CPPCHECK] (OPT_MAP_ANON):
Define to immediate non-zero value (taken from Linux libc) instead of
MAP_ANON (because the latter is used in ifdef).