diff options
author | Thomas Munro <tmunro@postgresql.org> | 2024-12-04 14:46:59 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2024-12-04 15:05:38 +1300 |
commit | 962da900ac8f0927f1af2fd811ca67fa163c873a (patch) | |
tree | 5839c22d2ad7bc68ddfd1e4debc734ef5df3a9d1 /configure | |
parent | 3b08d5224d7df71cc111d8522cf6190fc02f6fb9 (diff) | |
download | postgresql-962da900ac8f0927f1af2fd811ca67fa163c873a.tar.gz postgresql-962da900ac8f0927f1af2fd811ca67fa163c873a.zip |
Use <stdint.h> and <inttypes.h> for c.h integers.
Redefine our exact width types with standard C99 types and macros,
including int64_t, INT64_MAX, INT64_C(), PRId64 etc. We were already
using <stdint.h> types in a few places.
One complication is that Windows' <inttypes.h> uses format strings like
"%I64d", "%I32", "%I" for PRI*64, PRI*32, PTR*PTR, instead of mapping to
other standardized format strings like "%lld" etc as seen on other known
systems. Teach our snprintf.c to understand them.
This removes a lot of configure clutter, and should also allow 64-bit
numbers and other standard types to be used in localized messages
without casting.
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://postgr.es/m/ME3P282MB3166F9D1F71F787929C0C7E7B6312%40ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 354 |
1 files changed, 92 insertions, 262 deletions
diff --git a/configure b/configure index cf2d83b93ad..518c33b73a9 100755 --- a/configure +++ b/configure @@ -14437,6 +14437,43 @@ if test x"$pgac_cv__builtin_constant_p" = xyes ; then $as_echo "#define HAVE__BUILTIN_CONSTANT_P 1" >>confdefs.h fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_mul_overflow" >&5 +$as_echo_n "checking for __builtin_mul_overflow... " >&6; } +if ${pgac_cv__builtin_op_overflow+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include <stdint.h> +int64_t a = 1; +int64_t b = 1; +int64_t result; +int oflo; + +int +main () +{ +oflo = __builtin_mul_overflow(a, b, &result); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + pgac_cv__builtin_op_overflow=yes +else + pgac_cv__builtin_op_overflow=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__builtin_op_overflow" >&5 +$as_echo "$pgac_cv__builtin_op_overflow" >&6; } +if test x"$pgac_cv__builtin_op_overflow" = xyes ; then + +$as_echo "#define HAVE__BUILTIN_OP_OVERFLOW 1" >>confdefs.h + +fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_unreachable" >&5 $as_echo_n "checking for __builtin_unreachable... " >&6; } if ${pgac_cv__builtin_unreachable+:} false; then : @@ -16196,236 +16233,6 @@ fi # Run tests below here # -------------------- - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether long int is 64 bits" >&5 -$as_echo_n "checking whether long int is 64 bits... " >&6; } -if ${pgac_cv_type_long_int_64+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : - # If cross-compiling, check the size reported by the compiler and -# trust that the arithmetic works. -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -static int test_array [1 - 2 * !(sizeof(long int) == 8)]; -test_array [0] = 0; -return test_array [0]; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - pgac_cv_type_long_int_64=yes -else - pgac_cv_type_long_int_64=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -typedef long int ac_int64; - -/* - * These are globals to discourage the compiler from folding all the - * arithmetic tests down to compile-time constants. - */ -ac_int64 a = 20000001; -ac_int64 b = 40000005; - -int does_int64_work() -{ - ac_int64 c,d; - - if (sizeof(ac_int64) != 8) - return 0; /* definitely not the right size */ - - /* Do perfunctory checks to see if 64-bit arithmetic seems to work */ - c = a * b; - d = (c + b) / b; - if (d != a+1) - return 0; - return 1; -} - -int -main() { - return (! does_int64_work()); -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - pgac_cv_type_long_int_64=yes -else - pgac_cv_type_long_int_64=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_type_long_int_64" >&5 -$as_echo "$pgac_cv_type_long_int_64" >&6; } - -HAVE_LONG_INT_64=$pgac_cv_type_long_int_64 -if test x"$pgac_cv_type_long_int_64" = xyes ; then - -$as_echo "#define HAVE_LONG_INT_64 1" >>confdefs.h - -fi - - -if test x"$HAVE_LONG_INT_64" = x"yes" ; then - pg_int64_type="long int" -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether long long int is 64 bits" >&5 -$as_echo_n "checking whether long long int is 64 bits... " >&6; } -if ${pgac_cv_type_long_long_int_64+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : - # If cross-compiling, check the size reported by the compiler and -# trust that the arithmetic works. -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -static int test_array [1 - 2 * !(sizeof(long long int) == 8)]; -test_array [0] = 0; -return test_array [0]; - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - pgac_cv_type_long_long_int_64=yes -else - pgac_cv_type_long_long_int_64=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -typedef long long int ac_int64; - -/* - * These are globals to discourage the compiler from folding all the - * arithmetic tests down to compile-time constants. - */ -ac_int64 a = 20000001; -ac_int64 b = 40000005; - -int does_int64_work() -{ - ac_int64 c,d; - - if (sizeof(ac_int64) != 8) - return 0; /* definitely not the right size */ - - /* Do perfunctory checks to see if 64-bit arithmetic seems to work */ - c = a * b; - d = (c + b) / b; - if (d != a+1) - return 0; - return 1; -} - -int -main() { - return (! does_int64_work()); -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - pgac_cv_type_long_long_int_64=yes -else - pgac_cv_type_long_long_int_64=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_type_long_long_int_64" >&5 -$as_echo "$pgac_cv_type_long_long_int_64" >&6; } - -HAVE_LONG_LONG_INT_64=$pgac_cv_type_long_long_int_64 -if test x"$pgac_cv_type_long_long_int_64" = xyes ; then - -$as_echo "#define HAVE_LONG_LONG_INT_64 1" >>confdefs.h - -fi - - if test x"$HAVE_LONG_LONG_INT_64" = x"yes" ; then - pg_int64_type="long long int" - else - as_fn_error $? "Cannot find a working 64-bit integer type." "$LINENO" 5 - fi -fi - - -cat >>confdefs.h <<_ACEOF -#define PG_INT64_TYPE $pg_int64_type -_ACEOF - - -# Select the printf length modifier that goes with that, too. -if test x"$pg_int64_type" = x"long long int" ; then - INT64_MODIFIER='"ll"' -else - INT64_MODIFIER='"l"' -fi - - -cat >>confdefs.h <<_ACEOF -#define INT64_MODIFIER $INT64_MODIFIER -_ACEOF - - -# has to be down here, rather than with the other builtins, because -# the test uses PG_INT64_TYPE. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_mul_overflow" >&5 -$as_echo_n "checking for __builtin_mul_overflow... " >&6; } -if ${pgac_cv__builtin_op_overflow+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -PG_INT64_TYPE a = 1; -PG_INT64_TYPE b = 1; -PG_INT64_TYPE result; -int oflo; - -int -main () -{ -oflo = __builtin_mul_overflow(a, b, &result); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - pgac_cv__builtin_op_overflow=yes -else - pgac_cv__builtin_op_overflow=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__builtin_op_overflow" >&5 -$as_echo "$pgac_cv__builtin_op_overflow" >&6; } -if test x"$pgac_cv__builtin_op_overflow" = xyes ; then - -$as_echo "#define HAVE__BUILTIN_OP_OVERFLOW 1" >>confdefs.h - -fi - # Check size of void *, size_t (enables tweaks for > 32bit address space) # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects @@ -16526,6 +16333,39 @@ cat >>confdefs.h <<_ACEOF _ACEOF +# The cast to long int works around a bug in the HP C Compiler +# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects +# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +# This bug is HP SR number 8606223364. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of long long" >&5 +$as_echo_n "checking size of long long... " >&6; } +if ${ac_cv_sizeof_long_long+:} false; then : + $as_echo_n "(cached) " >&6 +else + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (long long))" "ac_cv_sizeof_long_long" "$ac_includes_default"; then : + +else + if test "$ac_cv_type_long_long" = yes; then + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot compute sizeof (long long) +See \`config.log' for more details" "$LINENO" 5; } + else + ac_cv_sizeof_long_long=0 + fi +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_long_long" >&5 +$as_echo "$ac_cv_sizeof_long_long" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long +_ACEOF + + # Determine memory alignment requirements for the basic C data types. @@ -16634,43 +16474,41 @@ cat >>confdefs.h <<_ACEOF _ACEOF -if test x"$HAVE_LONG_LONG_INT_64" = x"yes" ; then - # The cast to long int works around a bug in the HP C Compiler, +# The cast to long int works around a bug in the HP C Compiler, # see AC_CHECK_SIZEOF for more information. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of long long int" >&5 -$as_echo_n "checking alignment of long long int... " >&6; } -if ${ac_cv_alignof_long_long_int+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of int64_t" >&5 +$as_echo_n "checking alignment of int64_t... " >&6; } +if ${ac_cv_alignof_int64_t+:} false; then : $as_echo_n "(cached) " >&6 else - if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_long_long_int" "$ac_includes_default + if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_int64_t" "$ac_includes_default #ifndef offsetof # define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0) #endif -typedef struct { char x; long long int y; } ac__type_alignof_;"; then : +typedef struct { char x; int64_t y; } ac__type_alignof_;"; then : else - if test "$ac_cv_type_long_long_int" = yes; then + if test "$ac_cv_type_int64_t" = yes; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error 77 "cannot compute alignment of long long int +as_fn_error 77 "cannot compute alignment of int64_t See \`config.log' for more details" "$LINENO" 5; } else - ac_cv_alignof_long_long_int=0 + ac_cv_alignof_int64_t=0 fi fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_long_long_int" >&5 -$as_echo "$ac_cv_alignof_long_long_int" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_int64_t" >&5 +$as_echo "$ac_cv_alignof_int64_t" >&6; } cat >>confdefs.h <<_ACEOF -#define ALIGNOF_LONG_LONG_INT $ac_cv_alignof_long_long_int +#define ALIGNOF_INT64_T $ac_cv_alignof_int64_t _ACEOF -fi # The cast to long int works around a bug in the HP C Compiler, # see AC_CHECK_SIZEOF for more information. { $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of double" >&5 @@ -16728,8 +16566,8 @@ MAX_ALIGNOF=$ac_cv_alignof_double if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5 fi -if test x"$HAVE_LONG_LONG_INT_64" = xyes && test $ac_cv_alignof_long_long_int -gt $MAX_ALIGNOF ; then - as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5 +if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then + as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5 fi cat >>confdefs.h <<_ACEOF @@ -16737,7 +16575,6 @@ cat >>confdefs.h <<_ACEOF _ACEOF - # Some compilers offer a 128-bit integer scalar type. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __int128" >&5 $as_echo_n "checking for __int128... " >&6; } @@ -16992,12 +16829,12 @@ if ${pgac_cv_gcc_sync_int64_cas+:} false; then : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - +#include <stdint.h> int main () { -PG_INT64_TYPE lock = 0; - __sync_val_compare_and_swap(&lock, 0, (PG_INT64_TYPE) 37); +int64_t lock = 0; + __sync_val_compare_and_swap(&lock, 0, (int64_t) 37); ; return 0; } @@ -17057,12 +16894,12 @@ if ${pgac_cv_gcc_atomic_int64_cas+:} false; then : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - +#include <stdint.h> int main () { -PG_INT64_TYPE val = 0; - PG_INT64_TYPE expect = 0; +int64_t val = 0; + int64_t expect = 0; __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); ; return 0; @@ -17278,13 +17115,14 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <immintrin.h> + #include <stdint.h> #if defined(__has_attribute) && __has_attribute (target) __attribute__((target("avx512vpopcntdq,avx512bw"))) #endif static int popcount_test(void) { const char buf[sizeof(__m512i)]; - PG_INT64_TYPE popcnt = 0; + int64_t popcnt = 0; __m512i accum = _mm512_setzero_si512(); const __m512i val = _mm512_maskz_loadu_epi8((__mmask64) 0xf0f0f0f0f0f0f0f0, (const __m512i *) buf); const __m512i cnt = _mm512_popcnt_epi64(val); @@ -18954,9 +18792,6 @@ fi ac_config_headers="$ac_config_headers src/include/pg_config.h" -ac_config_headers="$ac_config_headers src/include/pg_config_ext.h" - - ac_config_headers="$ac_config_headers src/interfaces/ecpg/include/ecpg_config.h" @@ -19671,7 +19506,6 @@ do "src/Makefile.port") CONFIG_LINKS="$CONFIG_LINKS src/Makefile.port:src/makefiles/Makefile.${template}" ;; "check_win32_symlinks") CONFIG_COMMANDS="$CONFIG_COMMANDS check_win32_symlinks" ;; "src/include/pg_config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/include/pg_config.h" ;; - "src/include/pg_config_ext.h") CONFIG_HEADERS="$CONFIG_HEADERS src/include/pg_config_ext.h" ;; "src/interfaces/ecpg/include/ecpg_config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/interfaces/ecpg/include/ecpg_config.h" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; @@ -20280,10 +20114,6 @@ $as_echo "$as_me: WARNING: *** link for $FILE -- please fix by hand" >&2;} # Update timestamp for pg_config.h (see Makefile.global) echo >src/include/stamp-h ;; - "src/include/pg_config_ext.h":H) -# Update timestamp for pg_config_ext.h (see Makefile.global) -echo >src/include/stamp-ext-h - ;; "src/interfaces/ecpg/include/ecpg_config.h":H) echo >src/interfaces/ecpg/include/stamp-h ;; esac |