diff --git a/aclocal.m4 b/aclocal.m4 index c7b94fed7501..154aab82c100 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -49,6 +49,14 @@ AC_DEFUN([OCAML_CC_VENDOR], [ msvc _MSC_VER #elif defined(__INTEL_COMPILER) icc __INTEL_COMPILER +#elif defined(__MINGW32__) +#include <_mingw_mac.h> +mingw32 __MINGW64_VERSION_MAJOR __MINGW64_VERSION_MINOR +# if defined(__clang_major__) && defined(__clang_minor__) + clang __clang_major__ __clang_minor__ +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) + gcc __GNUC__ __GNUC_MINOR__ +# endif #elif defined(__clang_major__) && defined(__clang_minor__) clang __clang_major__ __clang_minor__ #elif defined(__GNUC__) && defined(__GNUC_MINOR__) @@ -62,8 +70,8 @@ unknown #endif] )], [AC_CACHE_VAL([ocaml_cv_cc_vendor], - [ocaml_cv_cc_vendor=`grep ['^[a-z]'] conftest.i | tr -s ' ' '-' \ - | tr -d '\r'`])], + [ocaml_cv_cc_vendor=`sed -e '/^#/d' conftest.i | tr -s '[:space:]' '-' \ + | sed -e 's/^-//' -e 's/-$//'`])], [AC_MSG_FAILURE([unexpected preprocessor failure])]) AC_MSG_RESULT([$ocaml_cv_cc_vendor]) ]) diff --git a/configure b/configure index 0c7f22b37eee..21ac408feeed 100755 --- a/configure +++ b/configure @@ -13542,6 +13542,14 @@ printf %s "checking C compiler vendor... " >&6; } msvc _MSC_VER #elif defined(__INTEL_COMPILER) icc __INTEL_COMPILER +#elif defined(__MINGW32__) +#include <_mingw_mac.h> +mingw32 __MINGW64_VERSION_MAJOR __MINGW64_VERSION_MINOR +# if defined(__clang_major__) && defined(__clang_minor__) + clang __clang_major__ __clang_minor__ +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) + gcc __GNUC__ __GNUC_MINOR__ +# endif #elif defined(__clang_major__) && defined(__clang_minor__) clang __clang_major__ __clang_minor__ #elif defined(__GNUC__) && defined(__GNUC_MINOR__) @@ -13561,8 +13569,8 @@ then : then : printf %s "(cached) " >&6 else $as_nop - ocaml_cv_cc_vendor=`grep '^[a-z]' conftest.i | tr -s ' ' '-' \ - | tr -d '\r'` + ocaml_cv_cc_vendor=`sed -e '/^#/d' conftest.i | tr -s '[:space:]' '-' \ + | sed -e 's/^-//' -e 's/-$//'` fi else $as_nop @@ -13861,44 +13869,31 @@ esac # Concerning optimization level, -O3 is somewhat risky, so take -O2. # Concerning language version, recent enough versions of GCC and Clang # default to gnu11 (C11 + GNU extensions) or gnu17, which is fine. - -# Note: the vendor macro can not recognize MinGW because it calls the -# C preprocessor directly so no compiler specific macro like __MING32__ -# is defined. We thus catch MinGW first by looking at host and examine -# the vendor only as a fall-back. We could put tis part of the logic -# in the macro itself, too -case $host in #( - *-*-mingw32*) : - case $ocaml_cv_cc_vendor in #( - gcc-[01234]-*) : - as_fn_error $? "This version of MinGW-w64 GCC is too old. Please use GCC version 5 or above." "$LINENO" 5 ;; #( - gcc-*) : - internal_cflags="-Wno-unused $cc_warnings \ --fexcess-precision=standard" - # TODO: see whether the code can be fixed to avoid -Wno-unused - common_cflags="-O2 -fno-strict-aliasing -fwrapv -mms-bitfields" - internal_cppflags='-D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE' - internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" - internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)" ;; #( - *) : - as_fn_error $? "Unsupported C compiler for a MinGW-w64 build" "$LINENO" 5 ;; -esac ;; #( - *) : - case $ocaml_cv_cc_vendor in #( +case $ocaml_cv_cc_vendor in #( clang-*) : common_cflags="-O2 -fno-strict-aliasing -fwrapv"; - internal_cflags="$cc_warnings -fno-common" ;; #( - gcc-[0123]-*|gcc-4-[0-8]) : + internal_cflags="$cc_warnings -fno-common" ;; #( + *gcc-[0123]-*|*gcc-4-[0-8]) : # No C11 support - as_fn_error 69 "This version of GCC is too old. Please use GCC version 4.9 or above." "$LINENO" 5 ;; #( + as_fn_error 69 "This version of GCC is too old. Please use GCC version 4.9 or above." "$LINENO" 5 ;; #( gcc-*) : common_cflags="-O2 -fno-strict-aliasing -fwrapv"; - internal_cflags="$cc_warnings -fno-common -fexcess-precision=standard \ + internal_cflags="$cc_warnings -fno-common -fexcess-precision=standard \ -Wvla" ;; #( + mingw32-*-*-gcc-*|mingw32-*-*-clang-*) : + internal_cflags="-Wno-unused $cc_warnings \ +-fexcess-precision=standard" + # TODO: see whether the code can be fixed to avoid -Wno-unused + common_cflags="-O2 -fno-strict-aliasing -fwrapv -mms-bitfields" + internal_cppflags='-D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE' + internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" + internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)" ;; #( + mingw32-*) : + as_fn_error $? "Unsupported C compiler for a MinGW-w64 build" "$LINENO" 5 ;; #( msvc-*) : common_cflags="-nologo -O2 -Gy- -MD $cc_warnings" - common_cppflags="-D_CRT_SECURE_NO_DEPRECATE" - internal_cppflags='-DUNICODE -D_UNICODE' + common_cppflags="-D_CRT_SECURE_NO_DEPRECATE" + internal_cppflags='-DUNICODE -D_UNICODE' { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler supports -d2VolatileMetadata-" >&5 printf %s "checking whether the C compiler supports -d2VolatileMetadata-... " >&6; } @@ -13921,23 +13916,22 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS="$saved_CFLAGS" - if test "x$cl_has_volatile_metadata" = "xtrue" + if test "x$cl_has_volatile_metadata" = "xtrue" then : internal_cflags='-d2VolatileMetadata-' fi - internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" - internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)" ;; #( + internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" + internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)" ;; #( xlc-*) : common_cflags="-O5 -qtune=balanced -qnoipa -qinline"; - internal_cflags="$cc_warnings" ;; #( + internal_cflags="$cc_warnings" ;; #( sunc-*) : # Optimization should be >= O4 to inline functions - # and prevent unresolved externals - common_cflags="-O4 -xc99=all -D_XPG6 $CFLAGS"; - internal_cflags="$cc_warnings" ;; #( + # and prevent unresolved externals + common_cflags="-O4 -xc99=all -D_XPG6 $CFLAGS"; + internal_cflags="$cc_warnings" ;; #( *) : common_cflags="-O" ;; -esac ;; esac # Enable SSE2 on x86 mingw to avoid using 80-bit registers. diff --git a/configure.ac b/configure.ac index 28ad57a2933c..f2dd9c510ab9 100644 --- a/configure.ac +++ b/configure.ac @@ -788,56 +788,45 @@ AS_CASE([$enable_warn_error,OCAML__DEVELOPMENT_VERSION], # Concerning optimization level, -O3 is somewhat risky, so take -O2. # Concerning language version, recent enough versions of GCC and Clang # default to gnu11 (C11 + GNU extensions) or gnu17, which is fine. - -# Note: the vendor macro can not recognize MinGW because it calls the -# C preprocessor directly so no compiler specific macro like __MING32__ -# is defined. We thus catch MinGW first by looking at host and examine -# the vendor only as a fall-back. We could put tis part of the logic -# in the macro itself, too -AS_CASE([$host], - [*-*-mingw32*], - [AS_CASE([$ocaml_cv_cc_vendor], - [gcc-[[01234]]-*], - [AC_MSG_ERROR(m4_normalize([This version of MinGW-w64 GCC is too old. - Please use GCC version 5 or above.]))], - [gcc-*], - [internal_cflags="-Wno-unused $cc_warnings \ --fexcess-precision=standard" - # TODO: see whether the code can be fixed to avoid -Wno-unused - common_cflags="-O2 -fno-strict-aliasing -fwrapv -mms-bitfields" - internal_cppflags='-D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE' - internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" - internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)"], - [AC_MSG_ERROR([Unsupported C compiler for a MinGW-w64 build])])], - [AS_CASE([$ocaml_cv_cc_vendor], - [clang-*], - [common_cflags="-O2 -fno-strict-aliasing -fwrapv"; - internal_cflags="$cc_warnings -fno-common"], - [gcc-[[0123]]-*|gcc-4-[[0-8]]], - # No C11 support - [AC_MSG_ERROR(m4_normalize([This version of GCC is too old. - Please use GCC version 4.9 or above.]), 69)], - [gcc-*], - [common_cflags="-O2 -fno-strict-aliasing -fwrapv"; - internal_cflags="$cc_warnings -fno-common -fexcess-precision=standard \ +AS_CASE([$ocaml_cv_cc_vendor], + [clang-*], + [common_cflags="-O2 -fno-strict-aliasing -fwrapv"; + internal_cflags="$cc_warnings -fno-common"], + [*gcc-[[0123]]-*|*gcc-4-[[0-8]]], + # No C11 support + [AC_MSG_ERROR(m4_normalize([This version of GCC is too old. + Please use GCC version 4.9 or above.]), 69)], + [gcc-*], + [common_cflags="-O2 -fno-strict-aliasing -fwrapv"; + internal_cflags="$cc_warnings -fno-common -fexcess-precision=standard \ -Wvla"], - [msvc-*], - [common_cflags="-nologo -O2 -Gy- -MD $cc_warnings" - common_cppflags="-D_CRT_SECURE_NO_DEPRECATE" - internal_cppflags='-DUNICODE -D_UNICODE' - OCAML_CL_HAS_VOLATILE_METADATA - AS_IF([test "x$cl_has_volatile_metadata" = "xtrue"], - [internal_cflags='-d2VolatileMetadata-']) - internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" - internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)"], - [xlc-*], - [common_cflags="-O5 -qtune=balanced -qnoipa -qinline"; - internal_cflags="$cc_warnings"], - [sunc-*], # Optimization should be >= O4 to inline functions - # and prevent unresolved externals - [common_cflags="-O4 -xc99=all -D_XPG6 $CFLAGS"; - internal_cflags="$cc_warnings"], - [common_cflags="-O"])]) + [mingw32-*-*-gcc-*|mingw32-*-*-clang-*], + [internal_cflags="-Wno-unused $cc_warnings \ +-fexcess-precision=standard" + # TODO: see whether the code can be fixed to avoid -Wno-unused + common_cflags="-O2 -fno-strict-aliasing -fwrapv -mms-bitfields" + internal_cppflags='-D__USE_MINGW_ANSI_STDIO=0 -DUNICODE -D_UNICODE' + internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" + internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)"], + [mingw32-*], + [AC_MSG_ERROR([Unsupported C compiler for a MinGW-w64 build])], + [msvc-*], + [common_cflags="-nologo -O2 -Gy- -MD $cc_warnings" + common_cppflags="-D_CRT_SECURE_NO_DEPRECATE" + internal_cppflags='-DUNICODE -D_UNICODE' + OCAML_CL_HAS_VOLATILE_METADATA + AS_IF([test "x$cl_has_volatile_metadata" = "xtrue"], + [internal_cflags='-d2VolatileMetadata-']) + internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE=" + internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)"], + [xlc-*], + [common_cflags="-O5 -qtune=balanced -qnoipa -qinline"; + internal_cflags="$cc_warnings"], + [sunc-*], # Optimization should be >= O4 to inline functions + # and prevent unresolved externals + [common_cflags="-O4 -xc99=all -D_XPG6 $CFLAGS"; + internal_cflags="$cc_warnings"], + [common_cflags="-O"]) # Enable SSE2 on x86 mingw to avoid using 80-bit registers. AS_CASE([$host], diff --git a/runtime/caml/fail.h b/runtime/caml/fail.h index 4652bb896920..91c8cf6973c3 100644 --- a/runtime/caml/fail.h +++ b/runtime/caml/fail.h @@ -51,8 +51,13 @@ struct longjmp_buffer { struct longjmp_buffer { intptr_t buf[5]; }; +#if defined(__clang__) +#define sigsetjmp(buf,save) __builtin_setjmp((void **)(buf)) +#define siglongjmp(buf,val) __builtin_longjmp((void **)(buf),val) +#else #define sigsetjmp(buf,save) __builtin_setjmp(buf) #define siglongjmp(buf,val) __builtin_longjmp(buf,val) +#endif #else struct longjmp_buffer { jmp_buf buf; diff --git a/runtime/runtime_events.c b/runtime/runtime_events.c index ef95da40b05d..05bbbebc2505 100644 --- a/runtime/runtime_events.c +++ b/runtime/runtime_events.c @@ -252,10 +252,11 @@ void caml_runtime_events_destroy(void) { static void runtime_events_create_from_stw_single(void) { /* Don't initialise runtime_events twice */ if (!atomic_load_acquire(&runtime_events_enabled)) { - int ret, ring_headers_length, ring_data_length; + int ring_headers_length, ring_data_length; #ifdef _WIN32 DWORD pid = GetCurrentProcessId(); #else + int ret; int ring_fd; long int pid = getpid(); #endif diff --git a/runtime/win32.c b/runtime/win32.c index 7f1bcf976877..6b20f14e305d 100644 --- a/runtime/win32.c +++ b/runtime/win32.c @@ -361,7 +361,7 @@ static void expand_argument(wchar_t * arg) static void expand_pattern(wchar_t * pat) { - wchar_t * prefix, * p, * name; + wchar_t * prefix, * name; intptr_t handle; struct _wfinddata_t ffblk; size_t i; @@ -1094,7 +1094,6 @@ CAMLexport clock_t caml_win32_clock(void) { FILETIME _creation, _exit; CAML_ULONGLONG_FILETIME stime, utime; - ULARGE_INTEGER tmp; ULONGLONG clocks_per_sec; if (!(GetProcessTimes(GetCurrentProcess(), &_creation, &_exit,