Author: ericwf Date: Wed May 31 17:14:05 2017 New Revision: 304360 URL: http://llvm.org/viewvc/llvm-project?rev=304360&view=rev Log: Fix Libc++ build with MinGW64
Summary: This patch corrects the build errors I encountered when building on MinGW64. Reviewers: mati865, rnk, compnerd, smeenai, bcraig Reviewed By: mati865, smeenai Subscribers: martell, chapuni, cfe-commits Differential Revision: https://reviews.llvm.org/D33082 Modified: libcxx/trunk/include/__config libcxx/trunk/include/__locale libcxx/trunk/include/locale libcxx/trunk/include/stdio.h libcxx/trunk/include/support/win32/locale_win32.h libcxx/trunk/include/wchar.h libcxx/trunk/src/chrono.cpp libcxx/trunk/src/new.cpp libcxx/trunk/src/support/win32/locale_win32.cpp libcxx/trunk/src/support/win32/support.cpp libcxx/trunk/src/system_error.cpp libcxx/trunk/src/thread.cpp Modified: libcxx/trunk/include/__config URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/include/__config (original) +++ libcxx/trunk/include/__config Wed May 31 17:14:05 2017 @@ -220,10 +220,12 @@ #endif // __NetBSD__ #if defined(_WIN32) -# define _LIBCPP_WIN32API 1 +# define _LIBCPP_WIN32API # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 # define _LIBCPP_SHORT_WCHAR 1 +// Both MinGW and native MSVC provide a "MSVC"-like enviroment +# define _LIBCPP_MSVCRT_LIKE // If mingw not explicitly detected, assume using MS C runtime only. # ifndef __MINGW32__ # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library Modified: libcxx/trunk/include/__locale URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__locale?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/include/__locale (original) +++ libcxx/trunk/include/__locale Wed May 31 17:14:05 2017 @@ -19,7 +19,7 @@ #include <cstdint> #include <cctype> #include <locale.h> -#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) +#if defined(_LIBCPP_MSVCRT_LIKE) # include <support/win32/locale_win32.h> #elif defined(_AIX) # include <support/ibm/xlocale.h> @@ -367,7 +367,7 @@ public: static const mask punct = _ISpunct; static const mask xdigit = _ISxdigit; static const mask blank = _ISblank; -#elif defined(_LIBCPP_MSVCRT) +#elif defined(_LIBCPP_MSVCRT_LIKE) typedef unsigned short mask; static const mask space = _SPACE; static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; Modified: libcxx/trunk/include/locale URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/include/locale (original) +++ libcxx/trunk/include/locale Wed May 31 17:14:05 2017 @@ -192,14 +192,7 @@ template <class charT> class messages_by #endif #include <cstdlib> #include <ctime> -#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) -#include <support/win32/locale_win32.h> -#elif defined(_NEWLIB_VERSION) -// FIXME: replace all the uses of _NEWLIB_VERSION with __NEWLIB__ preceded by an -// include of <sys/cdefs.h> once https://sourceware.org/ml/newlib-cvs/2014-q3/msg00038.html -// has had a chance to bake for a bit -#include <support/newlib/xlocale.h> -#endif +#include <cstdio> #ifdef _LIBCPP_HAS_CATOPEN #include <nl_types.h> #endif Modified: libcxx/trunk/include/stdio.h URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stdio.h?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/include/stdio.h (original) +++ libcxx/trunk/include/stdio.h Wed May 31 17:14:05 2017 @@ -110,10 +110,9 @@ void perror(const char* s); #ifdef __cplusplus // snprintf -#if defined(_LIBCPP_MSVCRT) +#if defined(_LIBCPP_MSVCRT_LIKE) extern "C" { int vasprintf(char **sptr, const char *__restrict fmt, va_list ap); -int asprintf(char **sptr, const char *__restrict fmt, ...); } #endif Modified: libcxx/trunk/include/support/win32/locale_win32.h URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/locale_win32.h?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/include/support/win32/locale_win32.h (original) +++ libcxx/trunk/include/support/win32/locale_win32.h Wed May 31 17:14:05 2017 @@ -52,20 +52,21 @@ size_t wcsnrtombs_l( char *__restrict ds size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc); wint_t btowc_l( int c, locale_t loc ); int wctob_l( wint_t c, locale_t loc ); -inline _LIBCPP_ALWAYS_INLINE -decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ) -{ - return ___mb_cur_max_l_func(__l); -} + +decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ); // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ #define mbtowc_l _mbtowc_l #define strtoll_l _strtoi64_l #define strtoull_l _strtoui64_l -#define strtof_l _strtof_l #define strtod_l _strtod_l +#if defined(_LIBCPP_MSVCRT) +#define strtof_l _strtof_l #define strtold_l _strtold_l - +#else +float strtof_l(const char*, char**, locale_t); +long double strtold_l(const char*, char**, locale_t); +#endif inline _LIBCPP_INLINE_VISIBILITY int islower_l(int c, _locale_t loc) Modified: libcxx/trunk/include/wchar.h URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wchar.h?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/include/wchar.h (original) +++ libcxx/trunk/include/wchar.h Wed May 31 17:14:05 2017 @@ -166,7 +166,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP } #endif -#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT) +#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT_LIKE) extern "C" { size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, size_t nmc, size_t len, mbstate_t *__restrict ps); Modified: libcxx/trunk/src/chrono.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/chrono.cpp?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/src/chrono.cpp (original) +++ libcxx/trunk/src/chrono.cpp Wed May 31 17:14:05 2017 @@ -37,7 +37,7 @@ #if defined(_LIBCPP_WIN32API) #define WIN32_LEAN_AND_MEAN #define VC_EXTRA_LEAN -#include <Windows.h> +#include <windows.h> #if _WIN32_WINNT >= _WIN32_WINNT_WIN8 #include <winapifamily.h> #endif Modified: libcxx/trunk/src/new.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/new.cpp?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/src/new.cpp (original) +++ libcxx/trunk/src/new.cpp Wed May 31 17:14:05 2017 @@ -183,7 +183,7 @@ operator new(std::size_t size, std::alig if (static_cast<size_t>(alignment) < sizeof(void*)) alignment = std::align_val_t(sizeof(void*)); void* p; -#if defined(_LIBCPP_MSVCRT) +#if defined(_LIBCPP_MSVCRT_LIKE) while ((p = _aligned_malloc(size, static_cast<size_t>(alignment))) == nullptr) #else while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0) @@ -256,7 +256,7 @@ void operator delete(void* ptr, std::align_val_t) _NOEXCEPT { if (ptr) -#if defined(_LIBCPP_MSVCRT) +#if defined(_LIBCPP_MSVCRT_LIKE) ::_aligned_free(ptr); #else ::free(ptr); Modified: libcxx/trunk/src/support/win32/locale_win32.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/win32/locale_win32.cpp?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/src/support/win32/locale_win32.cpp (original) +++ libcxx/trunk/src/support/win32/locale_win32.cpp Wed May 31 17:14:05 2017 @@ -34,6 +34,18 @@ locale_t uselocale( locale_t newloc ) // uselocale returns the old locale_t return old_locale; } + +decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ) +{ +#if defined(_LIBCPP_MSVCRT) + return ___mb_cur_max_l_func(__l); +#else + __libcpp_locale_guard __current(__l); + return MB_CUR_MAX; +#endif +} + + lconv *localeconv_l( locale_t loc ) { __libcpp_locale_guard __current(loc); @@ -109,3 +121,15 @@ int vasprintf_l( char **ret, locale_t lo __libcpp_locale_guard __current(loc); return vasprintf( ret, format, ap ); } + +#if !defined(_LIBCPP_MSVCRT) +float strtof_l(const char* nptr, char** endptr, locale_t loc) { + __libcpp_locale_guard __current(loc); + return strtof(nptr, endptr); +} + +long double strtold_l(const char* nptr, char** endptr, locale_t loc) { + __libcpp_locale_guard __current(loc); + return strtold(nptr, endptr); +} +#endif Modified: libcxx/trunk/src/support/win32/support.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/win32/support.cpp?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/src/support/win32/support.cpp (original) +++ libcxx/trunk/src/support/win32/support.cpp Wed May 31 17:14:05 2017 @@ -15,17 +15,6 @@ #include <cstring> // strcpy, wcsncpy #include <cwchar> // mbstate_t -// Some of these functions aren't standard or if they conform, the name does not. - -int asprintf(char **sptr, const char *__restrict format, ...) -{ - va_list ap; - va_start(ap, format); - int result; - result = vasprintf(sptr, format, ap); - va_end(ap); - return result; -} // Like sprintf, but when return value >= 0 it returns // a pointer to a malloc'd string in *sptr. Modified: libcxx/trunk/src/system_error.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/system_error.cpp?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/src/system_error.cpp (original) +++ libcxx/trunk/src/system_error.cpp Wed May 31 17:14:05 2017 @@ -65,7 +65,7 @@ constexpr size_t strerror_buff_size = 10 string do_strerror_r(int ev); -#if defined(_LIBCPP_MSVCRT) +#if defined(_LIBCPP_MSVCRT_LIKE) string do_strerror_r(int ev) { char buffer[strerror_buff_size]; if (::strerror_s(buffer, strerror_buff_size, ev) == 0) Modified: libcxx/trunk/src/thread.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=304360&r1=304359&r2=304360&view=diff ============================================================================== --- libcxx/trunk/src/thread.cpp (original) +++ libcxx/trunk/src/thread.cpp Wed May 31 17:14:05 2017 @@ -34,7 +34,7 @@ #if defined(_LIBCPP_WIN32API) #include <windows.h> -#endif // defined(_LIBCPP_WIN32API) +#endif _LIBCPP_BEGIN_NAMESPACE_STD _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits