On OpenBSD (and probably others), expr operates on a 32 bit signed integer,
which is the same size as a Fortran or C integer. This resulted in configure coming up with Fortran's MAX_INT as -2^31, which obviously isn't a positive number. Since we found the MAX_INT using the same broken loop in a couple places and doing it right is complicated, added a new macro that is much more careful about sign roll-over. During the Fortran rework between v1.6 and v1.7, the variable which indicates whether or not Fortran is being compiled changed, so on platforms without Fortran compilers, we were trying to determine the max value for Fortran INTEGERS where we previously didn't. I believe this is why bug #3374 appeared as a regression. Finally, since the OMPI code doesn't cope with OMPI_FORTRAN_HANDLE_MAX being negative (which was the root cause of the segfault in $3374), add a check at the end of the OMPI_FORTRAN_GET_HANDLE_MAX macro to ensure that OMPI_FORTRAN_HANDLE_MAX is always non-negative. This commit was SVN r27714.
Этот коммит содержится в:
родитель
295b04266b
Коммит
8231cb62a2
@ -31,22 +31,10 @@ AC_DEFUN([OMPI_FORTRAN_GET_HANDLE_MAX],[
|
||||
fortran_handle_max_var,
|
||||
[ # Find max fortran INTEGER value. Set to sentinel value if we don't
|
||||
# have a Fortran compiler (e.g., if --disable-fortran was given).
|
||||
if test $OMPI_WANT_FORTRAN_BINDINGS -eq 0; then
|
||||
if test $ompi_fortran_happy -eq 0; then
|
||||
ompi_fint_max=0
|
||||
else
|
||||
# Calculate the number of f's that we need to append to the hex
|
||||
# value. Do one less than we really need becaue we assume the
|
||||
# top nybble is 0x7 to avoid sign issues.
|
||||
ompi_numf=`expr $OMPI_SIZEOF_FORTRAN_INTEGER \* 8 - 1`
|
||||
ompi_fint_max=1
|
||||
# Use string comparisons when comparing these values to
|
||||
# 0, because $ompi_numf may be larger than "test -eq
|
||||
# ..." can handle (e.g., if we compile Fortran with
|
||||
# "ifort -i8").
|
||||
while test "$ompi_numf" != "0"; do
|
||||
ompi_fint_max=`expr $ompi_fint_max \* 2`
|
||||
ompi_numf=`expr $ompi_numf - 1`
|
||||
done
|
||||
OPAL_COMPUTE_MAX_VALUE([$OMPI_SIZEOF_FORTRAN_INTEGER], [ompi_fint_max])
|
||||
fi
|
||||
|
||||
# Get INT_MAX. Compute a SWAG if we are cross compiling or something
|
||||
@ -62,14 +50,7 @@ fclose(fp);]])],
|
||||
[ompi_cint_max=`cat conftest.out`],
|
||||
[ompi_cint_max=0],
|
||||
[ #cross compiling is fun. compute INT_MAX same as INTEGER max
|
||||
ompi_numf=`expr $ac_cv_sizeof_int \* 8 - 1`
|
||||
ompi_cint_max=1
|
||||
# Use string comparisons with "test"; see comment above
|
||||
# for rationale.
|
||||
while test "$ompi_numf" != "0" ; do
|
||||
ompi_cint_max=`expr $ompi_cint_max \* 2`
|
||||
ompi_numf=`expr $ompi_numf - 1`
|
||||
done])
|
||||
OPAL_COMPUTE_MAX_VALUE([$ac_cv_sizeof_int], [ompi_cint_max])])
|
||||
|
||||
# Use string comparisons with "test"; see comment above for
|
||||
# rationale.
|
||||
@ -94,6 +75,10 @@ fclose(fp);]])],
|
||||
unset value])
|
||||
|
||||
AS_VAR_COPY([ompi_fortran_handle_max], [fortran_handle_max_var])
|
||||
# sanity check; OMPI gets very unhappy if this value is negative...
|
||||
if test 0 -ne `expr $ompi_fortran_handle_max \< 0` ; then
|
||||
AC_MSG_ERROR([Detected negative max handle size.])
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([OMPI_FORTRAN_HANDLE_MAX],
|
||||
[$ompi_fortran_handle_max],
|
||||
[Max handle value for fortran MPI handles, effectively min(INT_MAX, max fortran INTEGER value)])
|
||||
|
@ -449,3 +449,62 @@ AC_DEFUN([OPAL_WITH_OPTION_MIN_MAX_VALUE], [
|
||||
[OPAL_MAX_]m4_toupper($1)=$max_value
|
||||
AC_SUBST([OPAL_MAX_]m4_toupper($1))
|
||||
])dnl
|
||||
|
||||
dnl #######################################################################
|
||||
dnl #######################################################################
|
||||
dnl #######################################################################
|
||||
|
||||
# Usage: OPAL_COMPUTE_MAX_VALUE(number_bytes, variable_to_set, action if overflow)
|
||||
# Compute maximum value of datatype of
|
||||
# number_bytes, setting the result in the second argument. Assumes a
|
||||
# signed datatype.
|
||||
AC_DEFUN([OPAL_COMPUTE_MAX_VALUE], [
|
||||
# This is more complicated than it really should be. But some
|
||||
# expr implementations (OpenBSD) have an expr with a max value of
|
||||
# 2^31 - 1, and we sometimes want to compute the max value of a
|
||||
# type as big or bigger than that...
|
||||
ompi_num_bits=`expr $1 \* 8 - 1`
|
||||
newval=1
|
||||
value=1
|
||||
overflow=0
|
||||
|
||||
while test $ompi_num_bits -ne 0 ; do
|
||||
newval=`expr $value \* 2`
|
||||
if test 0 -eq `expr $newval \< 0` ; then
|
||||
# if the new value is not negative, next iteration...
|
||||
value=$newval
|
||||
ompi_num_bits=`expr $ompi_num_bits - 1`
|
||||
# if this was the last iteration, subtract 1 (as signed
|
||||
# max positive is 2^num_bits - 1). Do this here instead
|
||||
# of outside of the while loop because we might have
|
||||
# already subtracted 1 by then if we're trying to find the
|
||||
# max value of the same datatype expr uses as it's
|
||||
# internal representation (ie, if we hit the else
|
||||
# below...)
|
||||
if test 0 -eq $ompi_num_bits ; then
|
||||
value=`expr $value - 1`
|
||||
fi
|
||||
else
|
||||
# if the new value is negative, we've over flowed. First,
|
||||
# try adding value - 1 instead of value (see if we can get
|
||||
# to positive max of expr)
|
||||
newval=`expr $value - 1 + $value`
|
||||
if test 0 -eq `expr $newval \< 0` ; then
|
||||
value=$newval
|
||||
# Still positive, this is as high as we can go. If
|
||||
# ompi_num_bits is 1, we didn't actually overflow.
|
||||
# Otherwise, we overflowed.
|
||||
if test 1 -ne $ompi_num_bits ; then
|
||||
overflow=1
|
||||
fi
|
||||
else
|
||||
# stil negative. Time to give up.
|
||||
overflow=1
|
||||
fi
|
||||
ompi_num_bits=0
|
||||
fi
|
||||
done
|
||||
|
||||
AS_VAR_SET([$2], [$value])
|
||||
AS_IF([test $overflow -ne 0], [$3])
|
||||
])dnl
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user