[LLVMdev] Re: Patch for missing rand48 on win32
Reid Spencer
reid at x10sys.com
Wed Oct 27 16:04:51 PDT 2004
Morten,
39 reconfigures later :) .. this patch has been committed, but it doesn't look
much like the original. I would have sent this patch back but the problem was
in existing m4 macros. Please note that the AC_SINGLE_CXX_CHECK macro has
changed to make it actually work. It is not *correct* to AC_DEFINE where the
first argument is not a literal. That means you have to provide a separate
AC_DEFINE for each variable, not encapsulate them the way AC_SINGLE_CXX_CHECK
used to do. I have also fixed the HAVE_ISNAN* and HAVE_ISINF* defines.
Reid
Morten Ofstad wrote:
> Morten Ofstad wrote:
>
>>> Hi,
>>>
>>> There's no HAVE_RAND48 symbol provided by autoconf. You'll have to
>>> add the appropriate check to autoconf/configure.ac before we can
>>> take this patch.
>
>
> I installed autoconf with cygwin now and I think I've managed to do this
> right now -- there are some strange problems with running the
> AutoRegen.sh script, so I had to do it manually... Here are the patches
> and the new test (which goes in autoconf/m4).
>
> m.
>
>
> ------------------------------------------------------------------------
>
> Index: autoconf/configure.ac
> ===================================================================
> RCS file: /var/cvs/llvm/llvm/autoconf/configure.ac,v
> retrieving revision 1.125
> diff -u -r1.125 configure.ac
> --- autoconf/configure.ac 25 Oct 2004 08:18:47 -0000 1.125
> +++ autoconf/configure.ac 27 Oct 2004 13:26:01 -0000
> @@ -318,6 +318,7 @@
>
> AC_FUNC_ISNAN
> AC_FUNC_ISINF
> +AC_FUNC_RAND48
>
> dnl Checks for library functions.
> AC_FUNC_ALLOCA
> Index: configure
> ===================================================================
> RCS file: /var/cvs/llvm/llvm/configure,v
> retrieving revision 1.131
> diff -u -r1.131 configure
> --- configure 25 Oct 2004 08:18:47 -0000 1.131
> +++ configure 27 Oct 2004 13:26:21 -0000
> @@ -23024,6 +23024,75 @@
> fi
>
>
> +echo "$as_me:$LINENO: checking for srand48/lrand48/drand48 in <stdlib.h>" >&5
> +echo $ECHO_N "checking for srand48/lrand48/drand48 in <stdlib.h>... $ECHO_C" >&6
> +if test "${ac_cv_func_rand48+set}" = set; then
> + echo $ECHO_N "(cached) $ECHO_C" >&6
> +else
> + ac_ext=cc
> +ac_cpp='$CXXCPP $CPPFLAGS'
> +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
> +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
> +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
> +
> + cat >conftest.$ac_ext <<_ACEOF
> +/* confdefs.h. */
> +_ACEOF
> +cat confdefs.h >>conftest.$ac_ext
> +cat >>conftest.$ac_ext <<_ACEOF
> +/* end confdefs.h. */
> +#include <stdlib.h>
> + void foo(void) {srand48(0);lrand48();drand48();}
> +_ACEOF
> +rm -f conftest.$ac_objext
> +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
> + (eval $ac_compile) 2>conftest.er1
> + ac_status=$?
> + grep -v '^ *+' conftest.er1 >conftest.err
> + rm -f conftest.er1
> + cat conftest.err >&5
> + echo "$as_me:$LINENO: \$? = $ac_status" >&5
> + (exit $ac_status); } &&
> + { ac_try='test -z "$ac_cxx_werror_flag"
> + || test ! -s conftest.err'
> + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
> + (eval $ac_try) 2>&5
> + ac_status=$?
> + echo "$as_me:$LINENO: \$? = $ac_status" >&5
> + (exit $ac_status); }; } &&
> + { ac_try='test -s conftest.$ac_objext'
> + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
> + (eval $ac_try) 2>&5
> + ac_status=$?
> + echo "$as_me:$LINENO: \$? = $ac_status" >&5
> + (exit $ac_status); }; }; then
> + ac_cv_func_rand48=yes
> +else
> + echo "$as_me: failed program was:" >&5
> +sed 's/^/| /' conftest.$ac_ext >&5
> +
> +ac_cv_func_rand48=no
> +fi
> +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
> + ac_ext=c
> +ac_cpp='$CPP $CPPFLAGS'
> +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
> +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
> +ac_compiler_gnu=$ac_cv_c_compiler_gnu
> +
> +fi
> +echo "$as_me:$LINENO: result: $ac_cv_func_rand48" >&5
> +echo "${ECHO_T}$ac_cv_func_rand48" >&6
> + if test "$ac_cv_func_rand48" = "yes"
> + then
> +
> +cat >>confdefs.h <<\_ACEOF
> +#define HAVE_RAND48 1
> +_ACEOF
> +
> + fi
> +
> +
> # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
> # for constant arguments. Useless!
> echo "$as_me:$LINENO: checking for working alloca.h" >&5
> Index: lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
> ===================================================================
> RCS file: /var/cvs/llvm/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp,v
> retrieving revision 1.78
> diff -u -r1.78 ExternalFunctions.cpp
> --- lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 1 Sep 2004 22:55:35 -0000 1.78
> +++ lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp 27 Oct 2004 13:26:22 -0000
> @@ -213,6 +213,8 @@
> return GV;
> }
>
> +#ifdef HAVE_RAND48
> +
> // double drand48()
> GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
> assert(Args.size() == 0);
> @@ -236,6 +238,16 @@
> return GenericValue();
> }
>
> +#endif
> +
> +// int rand()
> +GenericValue lle_X_rand(FunctionType *M, const vector<GenericValue> &Args) {
> + assert(Args.size() == 0);
> + GenericValue GV;
> + GV.IntVal = rand();
> + return GV;
> +}
> +
> // void srand(uint)
> GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
> assert(Args.size() == 1);
> @@ -676,9 +688,12 @@
> FuncNames["lle_X_log"] = lle_X_log;
> FuncNames["lle_X_floor"] = lle_X_floor;
> FuncNames["lle_X_srand"] = lle_X_srand;
> + FuncNames["lle_X_rand"] = lle_X_rand;
> +#ifdef HAVE_RAND48
> FuncNames["lle_X_drand48"] = lle_X_drand48;
> FuncNames["lle_X_srand48"] = lle_X_srand48;
> FuncNames["lle_X_lrand48"] = lle_X_lrand48;
> +#endif
> FuncNames["lle_X_sqrt"] = lle_X_sqrt;
> FuncNames["lle_X_puts"] = lle_X_puts;
> FuncNames["lle_X_printf"] = lle_X_printf;
>
>
> ------------------------------------------------------------------------
>
> #
> # This function determins if the the srand48,drand48,lrand48 functions are
> # available on this platform.
> #
> AC_DEFUN([AC_FUNC_RAND48],[
> AC_SINGLE_CXX_CHECK([HAVE_RAND48], [ac_cv_func_rand48],
> [srand48/lrand48/drand48], [<stdlib.h>],
> [#include <stdlib.h>
> void foo(void) {srand48(0);lrand48();drand48();}])
> ])
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list