From 5e54fa769d1b04ccf0d904164e897d081051647f Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Mon, 9 Feb 2015 15:02:20 -0500 Subject: [PATCH] Add configure checks for portability assumptions Check a few portability assumptions: * Integers are two's complement. Testing that the bitwise complement of the representation of -1 is zero is sufficient, because C99 6.2.6.2 only allows sign and magnitude, one's complement, and two's complement as representations. * Integer values with sign bit one and value bits zero are valid and not trap representations. C99 6.2.6.2 allows such a value to be a trap representation. Testing that the declared integer value bounds are asymmetric in magnitude is sufficient. * Conversion of an unsigned integer value that is not representable in the corresponding signed type preserves the bit pattern. C99 6.3.1.3 says this is implementation-defined, or raises an implementation-defined signal. Exhaustively checking for the desired behavior is prohibitive, so this spot check will have to do. * Bytes are 8 bits --- src/configure.in | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/configure.in b/src/configure.in index 58e6e54ca7..1a79ee2a42 100644 --- a/src/configure.in +++ b/src/configure.in @@ -22,6 +22,40 @@ AC_SUBST(KRB5_VERSION) AC_REQUIRE_CPP +AC_CACHE_CHECK([whether integers are two's complement], + [krb5_cv_ints_twos_compl], + [AC_COMPILE_IFELSE( + [AC_LANG_BOOL_COMPILE_TRY( +[#include +], + [/* Basic two's complement check */ + ~(-1) == 0 && ~(-1L) == 0L && + /* Check that values with sign bit 1 and value bits 0 are valid */ + -(INT_MIN + 1) == INT_MAX && -(LONG_MIN + 1) == LONG_MAX && + /* Check that unsigned-to-signed conversions preserve bit patterns */ + (int)((unsigned int)INT_MAX + 1) == INT_MIN && + (long)((unsigned long)LONG_MAX + 1) == LONG_MIN])], + [krb5_cv_ints_twos_compl=yes], + [krb5_cv_ints_twos_compl=no])]) + +if test "$krb5_cv_ints_twos_compl" = "no"; then + AC_MSG_ERROR([integers are not two's complement]) +fi + +AC_CACHE_CHECK([whether CHAR_BIT is 8], + [krb5_cv_char_bit_8], + [AC_PREPROC_IFELSE([AC_LANG_SOURCE( +[[#include +#if CHAR_BIT != 8 + #error CHAR_BIT != 8 +#endif +]])], + [krb5_cv_char_bit_8=yes], [krb5_cv_char_bit_8=no])]) + +if test "$krb5_cv_char_bit_8" = "no"; then + AC_MSG_ERROR([CHAR_BIT is not 8]) +fi + AC_CACHE_CHECK(if va_copy is available, krb5_cv_va_copy, [AC_LINK_IFELSE([AC_LANG_SOURCE([ #include -- 2.47.2