[libcxx] r302727 - [libc++] Refactor Windows support headers.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Wed May 10 13:57:46 PDT 2017
Author: ericwf
Date: Wed May 10 15:57:45 2017
New Revision: 302727
URL: http://llvm.org/viewvc/llvm-project?rev=302727&view=rev
Log:
[libc++] Refactor Windows support headers.
Summary:
This patch refactors and tries to remove as much of the Windows support headers as possible. This is needed because they currently introduce super weird include cycles and dependencies between STL and libc headers.
The changes in this patch are:
* remove `support/win32/support.h` completely. The required parts have either been moved into `support/win32/msvc_support.h` (for `MSVC` only helpers not needed by Clang), or directly into their respective `foo.h` headers.
* Combine `locale_win32.h` and `locale_mgmt_win32.h` into a single headers, this header should only be included within `__locale` or `locale` to avoid include cycles.
* Remove the unneeded parts of `limits_win32.h` and re-name it to `limits_msvc_win32.h` since it's only needed by Clang.
I've tested this patch using Clang on Windows, but I suspect it might technically regress our non-existent support for MSVC. Is somebody able to double check?
This refactor is needed to support upcoming fixes to `<locale>` on Windows.
Reviewers: bcraig, rmaprath, compnerd, EricWF
Reviewed By: EricWF
Subscribers: majnemer, cfe-commits
Differential Revision: https://reviews.llvm.org/D32988
Added:
libcxx/trunk/include/support/win32/limits_msvc_win32.h
libcxx/trunk/include/support/win32/msvc_builtin_support.h
Removed:
libcxx/trunk/include/support/win32/limits_win32.h
libcxx/trunk/include/support/win32/locale_mgmt_win32.h
libcxx/trunk/include/support/win32/support.h
Modified:
libcxx/trunk/include/__mutex_base
libcxx/trunk/include/__threading_support
libcxx/trunk/include/algorithm
libcxx/trunk/include/ctype.h
libcxx/trunk/include/limits
libcxx/trunk/include/stdio.h
libcxx/trunk/include/stdlib.h
libcxx/trunk/include/support/win32/locale_win32.h
libcxx/trunk/include/wchar.h
libcxx/trunk/src/string.cpp
libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp
Modified: libcxx/trunk/include/__mutex_base
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__mutex_base?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/__mutex_base (original)
+++ libcxx/trunk/include/__mutex_base Wed May 10 15:57:45 2017
@@ -15,6 +15,7 @@
#include <chrono>
#include <system_error>
#include <__threading_support>
+#include <__undef_min_max>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
Modified: libcxx/trunk/include/__threading_support
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Wed May 10 15:57:45 2017
@@ -30,6 +30,7 @@
#include <Windows.h>
#include <process.h>
#include <fibersapi.h>
+#include <__undef_min_max>
#endif
#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Wed May 10 15:57:45 2017
@@ -644,8 +644,8 @@ template <class BidirectionalIterator, c
#if defined(__IBMCPP__)
#include "support/ibm/support.h"
#endif
-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
-#include "support/win32/support.h"
+#if defined(_LIBCPP_COMPILER_MSVC)
+#include "support/win32/msvc_builtin_support.h"
#endif
#include <__undef_min_max>
Modified: libcxx/trunk/include/ctype.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ctype.h?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/ctype.h (original)
+++ libcxx/trunk/include/ctype.h Wed May 10 15:57:45 2017
@@ -40,15 +40,6 @@ int toupper(int c);
#ifdef __cplusplus
-#if defined(_LIBCPP_MSVCRT)
-// We support including .h headers inside 'extern "C"' contexts, so switch
-// back to C++ linkage before including these C++ headers.
-extern "C++" {
- #include "support/win32/support.h"
- #include "support/win32/locale_win32.h"
-}
-#endif // _LIBCPP_MSVCRT
-
#undef isalnum
#undef isalpha
#undef isblank
Modified: libcxx/trunk/include/limits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/limits?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/limits (original)
+++ libcxx/trunk/include/limits Wed May 10 15:57:45 2017
@@ -111,8 +111,8 @@ template<> class numeric_limits<cv long
#include <__undef_min_max>
-#if defined(_LIBCPP_MSVCRT)
-#include "support/win32/limits_win32.h"
+#if defined(_LIBCPP_COMPILER_MSVC)
+#include "support/win32/limits_msvc_win32.h"
#endif // _LIBCPP_MSVCRT
#if defined(__IBMCPP__)
Modified: libcxx/trunk/include/stdio.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stdio.h?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/stdio.h (original)
+++ libcxx/trunk/include/stdio.h Wed May 10 15:57:45 2017
@@ -111,8 +111,9 @@ void perror(const char* s);
// snprintf
#if defined(_LIBCPP_MSVCRT)
-extern "C++" {
-#include "support/win32/support.h"
+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/stdlib.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stdlib.h?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/stdlib.h (original)
+++ libcxx/trunk/include/stdlib.h Wed May 10 15:57:45 2017
@@ -97,10 +97,6 @@ void *aligned_alloc(size_t alignment, si
extern "C++" {
-#ifdef _LIBCPP_MSVCRT
-#include "support/win32/locale_win32.h"
-#endif // _LIBCPP_MSVCRT
-
#undef abs
#undef div
#undef labs
Added: libcxx/trunk/include/support/win32/limits_msvc_win32.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/limits_msvc_win32.h?rev=302727&view=auto
==============================================================================
--- libcxx/trunk/include/support/win32/limits_msvc_win32.h (added)
+++ libcxx/trunk/include/support/win32/limits_msvc_win32.h Wed May 10 15:57:45 2017
@@ -0,0 +1,72 @@
+// -*- C++ -*-
+//===------------------ support/win32/limits_msvc_win32.h -----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H
+#define _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H
+
+#if !defined(_LIBCPP_MSVCRT)
+#error "This header complements the Microsoft C Runtime library, and should not be included otherwise."
+#endif
+#if defined(__clang__)
+#error "This header should only be included when using Microsofts C1XX frontend"
+#endif
+
+#include <limits.h> // CHAR_BIT
+#include <float.h> // limit constants
+#include <math.h> // HUGE_VAL
+#include <ymath.h> // internal MSVC header providing the needed functionality
+
+#define __CHAR_BIT__ CHAR_BIT
+
+#define __FLT_MANT_DIG__ FLT_MANT_DIG
+#define __FLT_DIG__ FLT_DIG
+#define __FLT_RADIX__ FLT_RADIX
+#define __FLT_MIN_EXP__ FLT_MIN_EXP
+#define __FLT_MIN_10_EXP__ FLT_MIN_10_EXP
+#define __FLT_MAX_EXP__ FLT_MAX_EXP
+#define __FLT_MAX_10_EXP__ FLT_MAX_10_EXP
+#define __FLT_MIN__ FLT_MIN
+#define __FLT_MAX__ FLT_MAX
+#define __FLT_EPSILON__ FLT_EPSILON
+// predefined by MinGW GCC
+#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F
+
+#define __DBL_MANT_DIG__ DBL_MANT_DIG
+#define __DBL_DIG__ DBL_DIG
+#define __DBL_RADIX__ DBL_RADIX
+#define __DBL_MIN_EXP__ DBL_MIN_EXP
+#define __DBL_MIN_10_EXP__ DBL_MIN_10_EXP
+#define __DBL_MAX_EXP__ DBL_MAX_EXP
+#define __DBL_MAX_10_EXP__ DBL_MAX_10_EXP
+#define __DBL_MIN__ DBL_MIN
+#define __DBL_MAX__ DBL_MAX
+#define __DBL_EPSILON__ DBL_EPSILON
+// predefined by MinGW GCC
+#define __DBL_DENORM_MIN__ double(4.94065645841246544177e-324L)
+
+#define __LDBL_MANT_DIG__ LDBL_MANT_DIG
+#define __LDBL_DIG__ LDBL_DIG
+#define __LDBL_RADIX__ LDBL_RADIX
+#define __LDBL_MIN_EXP__ LDBL_MIN_EXP
+#define __LDBL_MIN_10_EXP__ LDBL_MIN_10_EXP
+#define __LDBL_MAX_EXP__ LDBL_MAX_EXP
+#define __LDBL_MAX_10_EXP__ LDBL_MAX_10_EXP
+#define __LDBL_MIN__ LDBL_MIN
+#define __LDBL_MAX__ LDBL_MAX
+#define __LDBL_EPSILON__ LDBL_EPSILON
+// predefined by MinGW GCC
+#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
+
+// __builtin replacements/workarounds
+#define __builtin_huge_vall() _LInf._Long_double
+#define __builtin_nanl(__dummmy) _LNan._Long_double
+#define __builtin_nansl(__dummy) _LSnan._Long_double
+
+#endif // _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H
Removed: libcxx/trunk/include/support/win32/limits_win32.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/limits_win32.h?rev=302726&view=auto
==============================================================================
--- libcxx/trunk/include/support/win32/limits_win32.h (original)
+++ libcxx/trunk/include/support/win32/limits_win32.h (removed)
@@ -1,79 +0,0 @@
-// -*- C++ -*-
-//===--------------------- support/win32/limits_win32.h -------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
-#define _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
-
-#if !defined(_LIBCPP_MSVCRT)
-#error "This header complements the Microsoft C Runtime library, and should not be included otherwise."
-#else
-
-#include <limits.h> // CHAR_BIT
-#include <float.h> // limit constants
-
-#if ! defined(__clang__)
-#define __CHAR_BIT__ CHAR_BIT
-
-#define __FLT_MANT_DIG__ FLT_MANT_DIG
-#define __FLT_DIG__ FLT_DIG
-#define __FLT_RADIX__ FLT_RADIX
-#define __FLT_MIN_EXP__ FLT_MIN_EXP
-#define __FLT_MIN_10_EXP__ FLT_MIN_10_EXP
-#define __FLT_MAX_EXP__ FLT_MAX_EXP
-#define __FLT_MAX_10_EXP__ FLT_MAX_10_EXP
-#define __FLT_MIN__ FLT_MIN
-#define __FLT_MAX__ FLT_MAX
-#define __FLT_EPSILON__ FLT_EPSILON
-// predefined by MinGW GCC
-#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F
-
-#define __DBL_MANT_DIG__ DBL_MANT_DIG
-#define __DBL_DIG__ DBL_DIG
-#define __DBL_RADIX__ DBL_RADIX
-#define __DBL_MIN_EXP__ DBL_MIN_EXP
-#define __DBL_MIN_10_EXP__ DBL_MIN_10_EXP
-#define __DBL_MAX_EXP__ DBL_MAX_EXP
-#define __DBL_MAX_10_EXP__ DBL_MAX_10_EXP
-#define __DBL_MIN__ DBL_MIN
-#define __DBL_MAX__ DBL_MAX
-#define __DBL_EPSILON__ DBL_EPSILON
-// predefined by MinGW GCC
-#define __DBL_DENORM_MIN__ double(4.94065645841246544177e-324L)
-
-#define __LDBL_MANT_DIG__ LDBL_MANT_DIG
-#define __LDBL_DIG__ LDBL_DIG
-#define __LDBL_RADIX__ LDBL_RADIX
-#define __LDBL_MIN_EXP__ LDBL_MIN_EXP
-#define __LDBL_MIN_10_EXP__ LDBL_MIN_10_EXP
-#define __LDBL_MAX_EXP__ LDBL_MAX_EXP
-#define __LDBL_MAX_10_EXP__ LDBL_MAX_10_EXP
-#define __LDBL_MIN__ LDBL_MIN
-#define __LDBL_MAX__ LDBL_MAX
-#define __LDBL_EPSILON__ LDBL_EPSILON
-// predefined by MinGW GCC
-#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
-
-// __builtin replacements/workarounds
-#include <math.h> // HUGE_VAL
-#include <ymath.h> // internal MSVC header providing the needed functionality
-#define __builtin_huge_val() HUGE_VAL
-#define __builtin_huge_valf() _FInf._Float
-#define __builtin_huge_vall() _LInf._Long_double
-#define __builtin_nan(__dummy) _Nan._Double
-#define __builtin_nanf(__dummy) _FNan._Float
-#define __builtin_nanl(__dummmy) _LNan._Long_double
-#define __builtin_nans(__dummy) _Snan._Double
-#define __builtin_nansf(__dummy) _FSnan._Float
-#define __builtin_nansl(__dummy) _LSnan._Long_double
-#endif // ! defined(__clang__)
-
-#endif // _LIBCPP_MSVCRT
-
-#endif // _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
Removed: libcxx/trunk/include/support/win32/locale_mgmt_win32.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/locale_mgmt_win32.h?rev=302726&view=auto
==============================================================================
--- libcxx/trunk/include/support/win32/locale_mgmt_win32.h (original)
+++ libcxx/trunk/include/support/win32/locale_mgmt_win32.h (removed)
@@ -1,33 +0,0 @@
-// -*- C++ -*-
-//===----------------- support/win32/locale_mgmt_win32.h ------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
-#define _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
-
-#include <xlocinfo.h> // _locale_t
-#define locale_t _locale_t
-#define LC_COLLATE_MASK _M_COLLATE
-#define LC_CTYPE_MASK _M_CTYPE
-#define LC_MONETARY_MASK _M_MONETARY
-#define LC_NUMERIC_MASK _M_NUMERIC
-#define LC_TIME_MASK _M_TIME
-#define LC_MESSAGES_MASK _M_MESSAGES
-#define LC_ALL_MASK ( LC_COLLATE_MASK \
- | LC_CTYPE_MASK \
- | LC_MESSAGES_MASK \
- | LC_MONETARY_MASK \
- | LC_NUMERIC_MASK \
- | LC_TIME_MASK )
-#define freelocale _free_locale
-// FIXME: base currently unused. Needs manual work to construct the new locale
-locale_t newlocale( int mask, const char * locale, locale_t base );
-locale_t uselocale( locale_t newloc );
-
-#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
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=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/support/win32/locale_win32.h (original)
+++ libcxx/trunk/include/support/win32/locale_win32.h Wed May 10 15:57:45 2017
@@ -12,9 +12,30 @@
#define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
#include <__config>
-#include "support/win32/support.h"
-#include "support/win32/locale_mgmt_win32.h"
#include <stdio.h>
+#include <xlocinfo.h> // _locale_t
+
+#define LC_COLLATE_MASK _M_COLLATE
+#define LC_CTYPE_MASK _M_CTYPE
+#define LC_MONETARY_MASK _M_MONETARY
+#define LC_NUMERIC_MASK _M_NUMERIC
+#define LC_TIME_MASK _M_TIME
+#define LC_MESSAGES_MASK _M_MESSAGES
+#define LC_ALL_MASK ( LC_COLLATE_MASK \
+ | LC_CTYPE_MASK \
+ | LC_MESSAGES_MASK \
+ | LC_MONETARY_MASK \
+ | LC_NUMERIC_MASK \
+ | LC_TIME_MASK )
+
+#define locale_t _locale_t
+
+// Locale management functions
+#define freelocale _free_locale
+// FIXME: base currently unused. Needs manual work to construct the new locale
+locale_t newlocale( int mask, const char * locale, locale_t base );
+locale_t uselocale( locale_t newloc );
+
lconv *localeconv_l( locale_t loc );
size_t mbrlen_l( const char *__restrict s, size_t n,
@@ -88,7 +109,6 @@ _LIBCPP_FUNC_VIS int snprintf_l(char *re
_LIBCPP_FUNC_VIS int asprintf_l( char **ret, locale_t loc, const char *format, ... );
_LIBCPP_FUNC_VIS int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap );
-
// not-so-pressing FIXME: use locale to determine blank characters
inline int isblank_l( int c, locale_t /*loc*/ )
{
@@ -99,10 +119,4 @@ inline int iswblank_l( wint_t c, locale_
return ( c == L' ' || c == L'\t' );
}
-#if defined(_LIBCPP_MSVCRT)
-inline int isblank( int c, locale_t /*loc*/ )
-{ return ( c == ' ' || c == '\t' ); }
-inline int iswblank( wint_t c, locale_t /*loc*/ )
-{ return ( c == L' ' || c == L'\t' ); }
-#endif // _LIBCPP_MSVCRT
#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
Added: libcxx/trunk/include/support/win32/msvc_builtin_support.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/msvc_builtin_support.h?rev=302727&view=auto
==============================================================================
--- libcxx/trunk/include/support/win32/msvc_builtin_support.h (added)
+++ libcxx/trunk/include/support/win32/msvc_builtin_support.h Wed May 10 15:57:45 2017
@@ -0,0 +1,156 @@
+// -*- C++ -*-
+//===----------------------- support/win32/support.h ----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_WIN32_MSVC_BUILTIN_SUPPORT_H
+#define _LIBCPP_SUPPORT_WIN32_MSVC_BUILTIN_SUPPORT_H
+
+#ifndef _LIBCPP_COMPILER_MSVC
+#error "This header can only be included when using Microsoft's C1XX frontend"
+#endif
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+// "builtins" not implemented here for Clang or GCC as they provide
+// implementations. Assuming required for elsewhere else, certainly MSVC.
+#include <intrin.h>
+
+// Bit builtin's make these assumptions when calling _BitScanForward/Reverse
+// etc. These assumptions are expected to be true for Win32/Win64 which this
+// file supports.
+static_assert(sizeof(unsigned long long) == 8, "");
+static_assert(sizeof(unsigned long) == 4, "");
+static_assert(sizeof(unsigned int) == 4, "");
+
+_LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x)
+{
+ // Binary: 0101...
+ static const unsigned int m1 = 0x55555555;
+ // Binary: 00110011..
+ static const unsigned int m2 = 0x33333333;
+ // Binary: 4 zeros, 4 ones ...
+ static const unsigned int m4 = 0x0f0f0f0f;
+ // The sum of 256 to the power of 0,1,2,3...
+ static const unsigned int h01 = 0x01010101;
+ // Put count of each 2 bits into those 2 bits.
+ x -= (x >> 1) & m1;
+ // Put count of each 4 bits into those 4 bits.
+ x = (x & m2) + ((x >> 2) & m2);
+ // Put count of each 8 bits into those 8 bits.
+ x = (x + (x >> 4)) & m4;
+ // Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24).
+ return (x * h01) >> 24;
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x)
+{
+ return __builtin_popcount(static_cast<int>(x));
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x)
+{
+ // Binary: 0101...
+ static const unsigned long long m1 = 0x5555555555555555;
+ // Binary: 00110011..
+ static const unsigned long long m2 = 0x3333333333333333;
+ // Binary: 4 zeros, 4 ones ...
+ static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f;
+ // The sum of 256 to the power of 0,1,2,3...
+ static const unsigned long long h01 = 0x0101010101010101;
+ // Put count of each 2 bits into those 2 bits.
+ x -= (x >> 1) & m1;
+ // Put count of each 4 bits into those 4 bits.
+ x = (x & m2) + ((x >> 2) & m2);
+ // Put count of each 8 bits into those 8 bits.
+ x = (x + (x >> 4)) & m4;
+ // Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
+ return static_cast<int>((x * h01) >> 56);
+}
+
+// Returns the number of trailing 0-bits in x, starting at the least significant
+// bit position. If x is 0, the result is undefined.
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
+{
+ unsigned long where;
+// Search from LSB to MSB for first set bit.
+// Returns zero if no set bit is found.
+#if defined(_LIBCPP_HAS_BITSCAN64)
+ (defined(_M_AMD64) || defined(__x86_64__))
+ if (_BitScanForward64(&where, mask))
+ return static_cast<int>(where);
+#else
+ // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
+ // Scan the Low Word.
+ if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
+ return static_cast<int>(where);
+ // Scan the High Word.
+ if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
+ return static_cast<int>(where + 32); // Create a bit offset from the LSB.
+#endif
+ return 64;
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzl(unsigned long mask)
+{
+ unsigned long where;
+ // Search from LSB to MSB for first set bit.
+ // Returns zero if no set bit is found.
+ if (_BitScanForward(&where, mask))
+ return static_cast<int>(where);
+ return 32;
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_ctz(unsigned int mask)
+{
+ // Win32 and Win64 expectations.
+ static_assert(sizeof(mask) == 4, "");
+ static_assert(sizeof(unsigned long) == 4, "");
+ return __builtin_ctzl(static_cast<unsigned long>(mask));
+}
+
+// Returns the number of leading 0-bits in x, starting at the most significant
+// bit position. If x is 0, the result is undefined.
+_LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
+{
+ unsigned long where;
+// BitScanReverse scans from MSB to LSB for first set bit.
+// Returns 0 if no set bit is found.
+#if defined(_LIBCPP_HAS_BITSCAN64)
+ if (_BitScanReverse64(&where, mask))
+ return static_cast<int>(63 - where);
+#else
+ // Scan the high 32 bits.
+ if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
+ return static_cast<int>(63 -
+ (where + 32)); // Create a bit offset from the MSB.
+ // Scan the low 32 bits.
+ if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
+ return static_cast<int>(63 - where);
+#endif
+ return 64; // Undefined Behavior.
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_clzl(unsigned long mask)
+{
+ unsigned long where;
+ // Search from LSB to MSB for first set bit.
+ // Returns zero if no set bit is found.
+ if (_BitScanReverse(&where, mask))
+ return static_cast<int>(31 - where);
+ return 32; // Undefined Behavior.
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_clz(unsigned int x)
+{
+ return __builtin_clzl(x);
+}
+
+#endif // _LIBCPP_SUPPORT_WIN32_MSVC_BUILTIN_SUPPORT_H
Removed: libcxx/trunk/include/support/win32/support.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/support.h?rev=302726&view=auto
==============================================================================
--- libcxx/trunk/include/support/win32/support.h (original)
+++ libcxx/trunk/include/support/win32/support.h (removed)
@@ -1,177 +0,0 @@
-// -*- C++ -*-
-//===----------------------- support/win32/support.h ----------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
-#define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
-
-// Functions and constants used in libc++ that
-// are missing from the Windows C library.
-
-#include <wchar.h> // mbstate_t
-#include <cstdarg> // va_ macros
-// "builtins" not implemented here for Clang or GCC as they provide
-// implementations. Assuming required for elsewhere else, certainly MSVC.
-#if defined(_LIBCPP_COMPILER_MSVC)
-#include <intrin.h>
-#endif
-#define swprintf _snwprintf
-#define vswprintf _vsnwprintf
-
-#ifndef NOMINMAX
-#define NOMINMAX
-#endif
-
-// The mingw headers already define these as static.
-#ifndef __MINGW32__
-extern "C" {
-
-int vasprintf(char **sptr, const char *__restrict fmt, va_list ap);
-int asprintf(char **sptr, const char *__restrict fmt, ...);
-size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
- size_t nmc, size_t len, mbstate_t *__restrict ps);
-size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
- size_t nwc, size_t len, mbstate_t *__restrict ps);
-}
-#endif // __MINGW32__
-
-#if defined(_LIBCPP_COMPILER_MSVC)
-
-// Bit builtin's make these assumptions when calling _BitScanForward/Reverse
-// etc. These assumptions are expected to be true for Win32/Win64 which this
-// file supports.
-static_assert(sizeof(unsigned long long) == 8, "");
-static_assert(sizeof(unsigned long) == 4, "");
-static_assert(sizeof(unsigned int) == 4, "");
-
-_LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x)
-{
- // Binary: 0101...
- static const unsigned int m1 = 0x55555555;
- // Binary: 00110011..
- static const unsigned int m2 = 0x33333333;
- // Binary: 4 zeros, 4 ones ...
- static const unsigned int m4 = 0x0f0f0f0f;
- // The sum of 256 to the power of 0,1,2,3...
- static const unsigned int h01 = 0x01010101;
- // Put count of each 2 bits into those 2 bits.
- x -= (x >> 1) & m1;
- // Put count of each 4 bits into those 4 bits.
- x = (x & m2) + ((x >> 2) & m2);
- // Put count of each 8 bits into those 8 bits.
- x = (x + (x >> 4)) & m4;
- // Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24).
- return (x * h01) >> 24;
-}
-
-_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x)
-{
- return __builtin_popcount(static_cast<int>(x));
-}
-
-_LIBCPP_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x)
-{
- // Binary: 0101...
- static const unsigned long long m1 = 0x5555555555555555;
- // Binary: 00110011..
- static const unsigned long long m2 = 0x3333333333333333;
- // Binary: 4 zeros, 4 ones ...
- static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f;
- // The sum of 256 to the power of 0,1,2,3...
- static const unsigned long long h01 = 0x0101010101010101;
- // Put count of each 2 bits into those 2 bits.
- x -= (x >> 1) & m1;
- // Put count of each 4 bits into those 4 bits.
- x = (x & m2) + ((x >> 2) & m2);
- // Put count of each 8 bits into those 8 bits.
- x = (x + (x >> 4)) & m4;
- // Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
- return static_cast<int>((x * h01) >> 56);
-}
-
-// Returns the number of trailing 0-bits in x, starting at the least significant
-// bit position. If x is 0, the result is undefined.
-_LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
-{
- unsigned long where;
-// Search from LSB to MSB for first set bit.
-// Returns zero if no set bit is found.
-#if defined(_LIBCPP_HAS_BITSCAN64)
- (defined(_M_AMD64) || defined(__x86_64__))
- if (_BitScanForward64(&where, mask))
- return static_cast<int>(where);
-#else
- // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
- // Scan the Low Word.
- if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
- return static_cast<int>(where);
- // Scan the High Word.
- if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
- return static_cast<int>(where + 32); // Create a bit offset from the LSB.
-#endif
- return 64;
-}
-
-_LIBCPP_ALWAYS_INLINE int __builtin_ctzl(unsigned long mask)
-{
- unsigned long where;
- // Search from LSB to MSB for first set bit.
- // Returns zero if no set bit is found.
- if (_BitScanForward(&where, mask))
- return static_cast<int>(where);
- return 32;
-}
-
-_LIBCPP_ALWAYS_INLINE int __builtin_ctz(unsigned int mask)
-{
- // Win32 and Win64 expectations.
- static_assert(sizeof(mask) == 4, "");
- static_assert(sizeof(unsigned long) == 4, "");
- return __builtin_ctzl(static_cast<unsigned long>(mask));
-}
-
-// Returns the number of leading 0-bits in x, starting at the most significant
-// bit position. If x is 0, the result is undefined.
-_LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
-{
- unsigned long where;
-// BitScanReverse scans from MSB to LSB for first set bit.
-// Returns 0 if no set bit is found.
-#if defined(_LIBCPP_HAS_BITSCAN64)
- if (_BitScanReverse64(&where, mask))
- return static_cast<int>(63 - where);
-#else
- // Scan the high 32 bits.
- if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
- return static_cast<int>(63 -
- (where + 32)); // Create a bit offset from the MSB.
- // Scan the low 32 bits.
- if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
- return static_cast<int>(63 - where);
-#endif
- return 64; // Undefined Behavior.
-}
-
-_LIBCPP_ALWAYS_INLINE int __builtin_clzl(unsigned long mask)
-{
- unsigned long where;
- // Search from LSB to MSB for first set bit.
- // Returns zero if no set bit is found.
- if (_BitScanReverse(&where, mask))
- return static_cast<int>(31 - where);
- return 32; // Undefined Behavior.
-}
-
-_LIBCPP_ALWAYS_INLINE int __builtin_clz(unsigned int x)
-{
- return __builtin_clzl(x);
-}
-#endif // _LIBCPP_MSVC
-
-#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H
Modified: libcxx/trunk/include/wchar.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wchar.h?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/include/wchar.h (original)
+++ libcxx/trunk/include/wchar.h Wed May 10 15:57:45 2017
@@ -166,9 +166,12 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP
}
#endif
-#if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT) || defined(__MINGW32__))
-extern "C++" {
-#include <support/win32/support.h> // pull in *swprintf defines
+#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT)
+extern "C" {
+size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
+ size_t nmc, size_t len, mbstate_t *__restrict ps);
+size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
+ size_t nwc, size_t len, mbstate_t *__restrict ps);
} // extern "C++"
#endif // __cplusplus && _LIBCPP_MSVCRT
Modified: libcxx/trunk/src/string.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/string.cpp?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/src/string.cpp (original)
+++ libcxx/trunk/src/string.cpp Wed May 10 15:57:45 2017
@@ -13,9 +13,6 @@
#include "cerrno"
#include "limits"
#include "stdexcept"
-#ifdef _LIBCPP_MSVCRT
-#include "support/win32/support.h"
-#endif // _LIBCPP_MSVCRT
#include <stdio.h>
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -430,7 +427,7 @@ get_swprintf()
#ifndef _LIBCPP_MSVCRT
return swprintf;
#else
- return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(swprintf);
+ return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
#endif
}
Modified: libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp?rev=302727&r1=302726&r2=302727&view=diff
==============================================================================
--- libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_pointer_msvc.ipp Wed May 10 15:57:45 2017
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <yvals.h> // for _CRTIMP2_PURE
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(_Out_ void*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(_Inout_ void*);
More information about the cfe-commits
mailing list