autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AC_CHECK_SIZEOF should report an error if the size can't be computed


From: Paul Eggert
Subject: AC_CHECK_SIZEOF should report an error if the size can't be computed
Date: Fri, 28 Sep 2001 18:03:40 -0700 (PDT)

In investigating why autoconf 2.52d 'make check' loops on HP-UX 11.11,
Kevin Steves reports that AC_CHECK_SIZEOF(unsigned char) fails, as the
compiler complains as follows:

   cc: "conftest.c", line 45: error 1502: Array size must be a constant 
expression.

when given the following declaration:

   int _array_ [1 - 2 * !((sizeof (unsigned char)) >= 0)];

and this causes the testsuite to loop.  I've asked Kevin to see if
there's some other way that we can word the expression that works with
this apparently-buggy compiler, but in the meantime it seems to me
that AC_CHECK_SIZEOF should never loop, no matter how bad the compiler
is.  Here's a proposed patch to do that (alas untested -- my autoconf
snapshot currently doesn't run).

This proposed patch also checks for overflow by `expr', which Kevin
also observed.

2001-09-28  Paul Eggert  <address@hidden>

        Try to detect cross-compilation failures that currently cause
        'configure' to loop when compiling for HP-UX 11.11, causing
        'make check' to loop on that platform.

        * lib/autoconf/types.m4 (AC_CHECK_SIZEOF):
        Report an error if the size cannot be determined even though
        the type exists.
        * lib/autoconf/general.m4 (_AC_COMPUTE_INT_COMPILE):
        Check for `expr' arithmetic overflow, and for compilation failure,
        and invoke a new argument $4 if either is discovered.
        This makes _AC_COMPUTE_INT_COMPILE more like _AC_COMPUTE_INT_RUN.
        (_AC_COMPUTE_INT): Pass IF-FAILS arg to _AC_COMPUTE_INT_COMPILE.

diff -ru autoconf-fiy0/lib/autoconf/types.m4 autoconf-fiy1/lib/autoconf/types.m4
--- autoconf-fiy0/lib/autoconf/types.m4 Mon Sep 17 10:05:38 2001
+++ autoconf-fiy1/lib/autoconf/types.m4 Fri Sep 28 17:28:21 2001
@@ -354,7 +354,8 @@
 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
   _AC_COMPUTE_INT([sizeof ($1)],
                   [AS_TR_SH([ac_cv_sizeof_$1])],
-                  [AC_INCLUDES_DEFAULT([$3])])
+                  [AC_INCLUDES_DEFAULT([$3])],
+                  [AC_MSG_ERROR([Cannot compute sizeof ($1)])])
 else
   AS_TR_SH([ac_cv_sizeof_$1])=0
 fi])dnl
diff -ru autoconf-fiy0/lib/autoconf/general.m4 
autoconf-fiy1/lib/autoconf/general.m4
--- autoconf-fiy0/lib/autoconf/general.m4       Thu Sep 27 12:17:00 2001
+++ autoconf-fiy1/lib/autoconf/general.m4       Fri Sep 28 17:55:26 2001
@@ -2503,10 +2503,10 @@
 ## ----------------------------------- ##
 
 
-# _AC_COMPUTE_INT_COMPILE(EXPRESSION, VARIABLE, [INCLUDES])
+# _AC_COMPUTE_INT_COMPILE(EXPRESSION, VARIABLE, [INCLUDES], [IF-FAILS])
 # ---------------------------------------------------------
 # Compute the integer EXPRESSION and store the result in the VARIABLE.
-# Works OK if cross compiling.
+# Works OK if cross compiling, but assumes twos-complement arithmetic.
 m4_define([_AC_COMPUTE_INT_COMPILE],
 [# Depending upon the size, compute the lo and hi bounds.
 AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= 0])],
@@ -2514,21 +2514,36 @@
   while :; do
     AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_mid])],
                    [ac_hi=$ac_mid; break],
-                   [ac_lo=`expr $ac_mid + 1`; ac_mid=`expr 2 '*' $ac_mid + 1`])
+                   [ac_lo=`expr $ac_mid + 1`
+                    if test $ac_lo -le $ac_mid; then
+                      ac_lo= ac_hi=
+                      break
+                    fi
+                    ac_mid=`expr 2 '*' $ac_mid + 1`])
   done],
+[AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) < 0])],
  [ac_hi=-1 ac_mid=-1
   while :; do
     AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= $ac_mid])],
                       [ac_lo=$ac_mid; break],
-                      [ac_hi=`expr '(' $ac_mid ')' - 1`; ac_mid=`expr 2 '*' 
$ac_mid`])
-  done])
+                      [ac_hi=`expr '(' $ac_mid ')' - 1`
+                       if test $ac_mid -le $ac_hi; then
+                         ac_lo= ac_hi=
+                         break
+                       fi
+                       ac_mid=`expr 2 '*' $ac_mid`])
+  done],
+ [ac_lo= ac_hi=])])
 # Binary search between lo and hi bounds.
 while test "x$ac_lo" != "x$ac_hi"; do
   ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
   AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_mid])],
                      [ac_hi=$ac_mid], [ac_lo=`expr '(' $ac_mid ')' + 1`])
 done
-$2=$ac_lo[]dnl
+case $ac_lo in
+?*) $2=$ac_lo;;
+'') $4 ;;
+esac[]dnl
 ])# _AC_COMPUTE_INT_COMPILE
 
 
@@ -2544,7 +2559,7 @@
 # ---------------------------------------------------------
 m4_define([_AC_COMPUTE_INT],
 [if test "$cross_compiling" = yes; then
-  _AC_COMPUTE_INT_COMPILE([$1], [$2], [$3])
+  _AC_COMPUTE_INT_COMPILE([$1], [$2], [$3], [$4])
 else
   _AC_COMPUTE_INT_RUN([$1], [$2], [$3], [$4])
 fi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]