8f0dd9478e
Future releases of GCC are planning to remove[0] default support for some old features that were removed from C99 but GCC still accepts. We can test for these changes by using the following -Werror= directives -Werror=implicit-int -Werror=implicit-function-declaration -Werror=int-conversion -Werror=strict-prototypes -Werror=old-style-definition Doing so revealed an issue with the auto/ tests in that the test programs always define main as int main() rather than int main(void) which results in a bunch of errors like build/autotest.c:3:23: error: function declaration isn't a prototype [-Werror=strict-prototypes] 3 | int main() { | ^~~~ build/autotest.c: In function 'main': build/autotest.c:3:23: error: old-style function definition [-Werror=old-style-definition] The fix was easy, it only required fixing the main prototype with find -type f -exec sed -i 's/int main() {/int main(void) {/g' {} \; Regardless of these upcoming GCC changes, this is probably a good thing to do anyway for correctness. [0]: https://fedoraproject.org/wiki/Changes/PortingToModernC Link: <https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/CJXKTLXJUPZ4F2C2VQOTNMEA5JAUPMBD/> Link: <https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/6SGHPHPAXKCVJ6PUZ57WVDQ5TDBVIRMF/> Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
122 lines
3.8 KiB
Text
122 lines
3.8 KiB
Text
|
|
# Copyright (C) Igor Sysoev
|
|
# Copyright (C) NGINX, Inc.
|
|
|
|
|
|
# GCC 4.1+ builtin atomic operations.
|
|
|
|
nxt_feature="GCC builtin atomic operations"
|
|
nxt_feature_name=NXT_HAVE_GCC_ATOMIC
|
|
nxt_feature_run=yes
|
|
nxt_feature_incs=
|
|
nxt_feature_libs=
|
|
nxt_feature_test="int main(void) {
|
|
long n = 0;
|
|
|
|
if (!__sync_bool_compare_and_swap(&n, 0, 3))
|
|
return 1;
|
|
if (__sync_fetch_and_add(&n, 1) != 3)
|
|
return 1;
|
|
if (__sync_lock_test_and_set(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
if (__sync_or_and_fetch(&n, 2) != 7)
|
|
return 1;
|
|
if (__sync_and_and_fetch(&n, 5) != 5)
|
|
return 1;
|
|
__sync_lock_release(&n);
|
|
if (n != 0)
|
|
return 1;
|
|
return 0;
|
|
}"
|
|
. auto/feature
|
|
|
|
|
|
# Solaris 10 builtin atomic operations.
|
|
|
|
if [ $nxt_found = no ]; then
|
|
|
|
nxt_feature="Solaris builtin atomic operations"
|
|
nxt_feature_name=NXT_HAVE_SOLARIS_ATOMIC
|
|
nxt_feature_run=yes
|
|
nxt_feature_incs=
|
|
nxt_feature_libs=
|
|
nxt_feature_test="#include <atomic.h>
|
|
|
|
int main(void) {
|
|
ulong_t n = 0;
|
|
|
|
if (atomic_cas_ulong(&n, 0, 3) != 0)
|
|
return 1;
|
|
if (atomic_add_long_nv(&n, 1) != 4)
|
|
return 1;
|
|
if (atomic_swap_ulong(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
if (atomic_or_ulong_nv(&n, 2) != 7)
|
|
return 1;
|
|
if (atomic_and_ulong_nv(&n, 5) != 5)
|
|
return 1;
|
|
return 0;
|
|
}"
|
|
. auto/feature
|
|
fi
|
|
|
|
|
|
# AIX xlC builtin atomic operations.
|
|
|
|
if [ $nxt_found = no ]; then
|
|
|
|
if [ $NXT_64BIT = 1 ]; then
|
|
nxt_feature_test="int main(void) {
|
|
long n = 0;
|
|
long o = 0;
|
|
|
|
if (!__compare_and_swaplp(&n, &o, 3))
|
|
return 1;
|
|
if (__fetch_and_addlp(&n, 1) != 3)
|
|
return 1;
|
|
if (__fetch_and_swaplp(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
__isync();
|
|
__lwsync();
|
|
return 0;
|
|
}"
|
|
else
|
|
nxt_feature_test="int main(void) {
|
|
int n = 0;
|
|
int o = 0;
|
|
|
|
if (!__compare_and_swap(&n, &o, 3))
|
|
return 1;
|
|
if (__fetch_and_add(&n, 1) != 3)
|
|
return 1;
|
|
if (__fetch_and_swap(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
__isync();
|
|
__lwsync();
|
|
return 0;
|
|
}"
|
|
fi
|
|
|
|
nxt_feature="xlC builtin atomic operations"
|
|
nxt_feature_name=NXT_HAVE_XLC_ATOMIC
|
|
nxt_feature_run=yes
|
|
nxt_feature_incs=
|
|
nxt_feature_libs=
|
|
. auto/feature
|
|
fi
|
|
|
|
|
|
if [ $nxt_found = no ]; then
|
|
$echo
|
|
$echo $0: error: no atomic operations found.
|
|
$echo
|
|
exit 1;
|
|
fi
|