From 3f6aa735e96fcfd91e8fe187b26b74bf2c82bc9d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 6 Jan 2011 17:06:51 -0600 Subject: [PATCH] Fix for OS X 10.5 compile error wrt llabs() GCC < 4.1.0 possibly has a problem w/ choosing an llabs() unambigiously from stdlib.h and cstdlib See also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13943 --- cmake/OSSpecific.cmake | 27 ++++++++++++++++++++++++++- config.h.in | 3 +++ src/Val.cc | 4 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cmake/OSSpecific.cmake b/cmake/OSSpecific.cmake index 03788813c3..b63ce54f6d 100644 --- a/cmake/OSSpecific.cmake +++ b/cmake/OSSpecific.cmake @@ -1,3 +1,6 @@ +include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) + if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") # alternate malloc is faster for FreeBSD, but needs more testing # need to add way to set this from the command line @@ -7,6 +10,28 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") set(USE_NMALLOC true) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + # The following may have a greater scope than just Darwin + # (i.e. any platform w/ GCC < 4.1.0), but I've only seen + # it on OS X 10.5, which has GCC 4.0.1, so the workaround + # will be stuck here for now. + # + # See also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13943 + + check_cxx_source_compiles(" + #include + #include + using namespace std; + int main() { + llabs(1); + return 0; + } + " darwin_llabs_works) + + if (NOT darwin_llabs_works) + # abs() should be used in this case, the long long version should + # exist in the __gnu_cxx namespace + set(DARWIN_NO_LLABS true) + endif () elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(HAVE_LINUX true) @@ -25,7 +50,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "irix") elseif (${CMAKE_SYSTEM_NAME} MATCHES "ultrix") list(APPEND CMAKE_C_FLAGS -std1 -g3) list(APPEND CMAKE_CXX_FLAGS -std1 -g3) - include(CheckCSourceCompiles) + check_c_source_compiles(" #include int main() { diff --git a/config.h.in b/config.h.in index f1405813fc..46915563a8 100644 --- a/config.h.in +++ b/config.h.in @@ -146,3 +146,6 @@ /* Define u_int8_t */ #define u_int8_t @U_INT8_T@ + +/* Whether llabs will be ambiguous in stdlib.h and cstdlib headers */ +#cmakedefine DARWIN_NO_LLABS diff --git a/src/Val.cc b/src/Val.cc index 9a1ee700ff..f43bafe4d7 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -524,7 +524,11 @@ Val* Val::SizeVal() const { switch ( type->InternalType() ) { case TYPE_INTERNAL_INT: +#ifdef DARWIN_NO_LLABS + return new Val(abs(val.int_val), TYPE_COUNT); +#else return new Val(llabs(val.int_val), TYPE_COUNT); +#endif case TYPE_INTERNAL_UNSIGNED: return new Val(val.uint_val, TYPE_COUNT);