[PATCH] D40775: [libcxx] Add underscores to win32 locale headers.

2018-03-11 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

ping.


https://reviews.llvm.org/D40775



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40775: [libcxx] Add underscores to win32 locale headers.

2018-03-11 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin updated this revision to Diff 137945.
halyavin added a comment.

update to new revision


https://reviews.llvm.org/D40775

Files:
  src/support/win32/locale_win32.cpp

Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -18,9 +18,9 @@
 using std::__libcpp_locale_guard;
 
 // 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 newlocale( int __mask, const char * __locale, locale_t /*__base*/ )
 {
-return {_create_locale( LC_ALL, locale ), locale};
+return {_create_locale( LC_ALL, __locale ), __locale};
 }
 
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
@@ -34,90 +34,90 @@
 }
 
 
-lconv *localeconv_l( locale_t loc )
+lconv *localeconv_l( locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
+__libcpp_locale_guard __current(__loc);
 return localeconv();
 }
-size_t mbrlen_l( const char *__restrict s, size_t n,
- mbstate_t *__restrict ps, locale_t loc )
+size_t mbrlen_l( const char *__restrict __s, size_t __n,
+ mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrlen( s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrlen( __s, __n, __ps );
 }
-size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
-size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsrtowcs( dst, src, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsrtowcs( __dst, __src, __len, __ps );
 }
-size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
-  locale_t loc )
+size_t wcrtomb_l( char *__restrict __s, wchar_t __wc, mbstate_t *__restrict __ps,
+  locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcrtomb( s, wc, ps );
+__libcpp_locale_guard __current(__loc);
+return wcrtomb( __s, __wc, __ps );
 }
-size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
-  size_t n, mbstate_t *__restrict ps, locale_t loc )
+size_t mbrtowc_l( wchar_t *__restrict __pwc, const char *__restrict __s,
+  size_t __n, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrtowc( pwc, s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrtowc( __pwc, __s, __n, __ps );
 }
-size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
- size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsnrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+ size_t __nms, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsnrtowcs( dst, src, nms, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsnrtowcs( __dst, __src, __nms, __len, __ps );
 }
-size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
- size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t wcsnrtombs_l( char *__restrict __dst, const wchar_t **__restrict __src,
+ size_t __nwc, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcsnrtombs( dst, src, nwc, len, ps );
+__libcpp_locale_guard __current(__loc);
+return wcsnrtombs( __dst, __src, __nwc, __len, __ps );
 }
-wint_t btowc_l( int c, locale_t loc )
+wint_t btowc_l( int __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return btowc( c );
+__libcpp_locale_guard __current(__loc);
+return btowc( __c );
 }
-int wctob_l( wint_t c, locale_t loc )
+int wctob_l( wint_t __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wctob( c );
+__libcpp_locale_guard __current(__loc);
+return wctob( __c );
 }
 
-int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
+int snprintf_l(char *__ret, size_t __n, locale_t __loc, const char *__format, ...)
 {
-__libcpp_locale_guard __current(loc);
-va_list ap;
-va_start( ap, format );
-int result = vsnprintf( ret, n, format, ap );
-va_end(ap);
-return result;
+__libcpp_locale_guard __current(__loc);
+va_list __ap;
+va_start(__ap, __format );
+int __result = vsnprintf( __ret, __n, __format, __ap );
+va_end(__ap);
+return __result;
 }
 
-int asprintf_l( char **ret, locale_t loc, const char *format, ... )
+int asprintf_l( char **__ret, locale_t

[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2019-03-19 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

Yes, I considered it. But Microsoft documentation is not clear whether it will 
work or not for restoring inconsistent locales. The documentation shows how to 
save inconsistent locales with LC_ALL but doesn't provide an example for 
restoring them.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D40181/new/

https://reviews.llvm.org/D40181



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-22 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin updated this revision to Diff 123921.
halyavin added a comment.
Herald added a subscriber: krytarowski.

Fixed problem with C++98, added std for nullptr_t and switched on _l functions 
for MinGW.


https://reviews.llvm.org/D40181

Files:
  include/__config
  include/__locale
  include/support/win32/locale_win32.h
  src/support/win32/locale_win32.cpp

Index: include/__config
===
--- include/__config
+++ include/__config
@@ -877,7 +877,7 @@
 #define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63)
 #endif
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT) ||   \
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
 defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif
Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -18,23 +18,9 @@
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
 {
-return _create_locale( mask, locale );
+return {_create_locale( LC_ALL, locale ), locale};
 }
 
-locale_t uselocale( locale_t newloc )
-{
-locale_t old_locale = _get_current_locale();
-if ( newloc == NULL )
-return old_locale;
-// uselocale sets the thread's locale by definition, so unconditionally use thread-local locale
-_configthreadlocale( _ENABLE_PER_THREAD_LOCALE );
-// uselocale sets all categories
-// disable setting locale on Windows temporarily because the structure is opaque (PR31516)
-//setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale );
-// uselocale returns the old locale_t
-return old_locale;
-}
-
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
 #if defined(_LIBCPP_MSVCRT)
Index: include/support/win32/locale_win32.h
===
--- include/support/win32/locale_win32.h
+++ include/support/win32/locale_win32.h
@@ -14,6 +14,7 @@
 #include <__config>
 #include 
 #include  // _locale_t
+#include <__nullptr>
 
 #define LC_COLLATE_MASK _M_COLLATE
 #define LC_CTYPE_MASK _M_CTYPE
@@ -28,13 +29,77 @@
  | LC_NUMERIC_MASK \
  | LC_TIME_MASK )
 
-#define locale_t _locale_t
+class locale_t {
+public:
+locale_t()
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(std::nullptr_t)
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(_locale_t __locale, const char* __locale_str)
+: __locale(__locale), __locale_str(__locale_str) {}
 
+friend bool operator==(const locale_t& __left, const locale_t& __right) {
+return __left.__locale == __right.__locale;
+}
+
+friend bool operator==(const locale_t& __left, int __right) {
+return __left.__locale == nullptr && __right == 0;
+}
+
+friend bool operator==(const locale_t& __left, std::nullptr_t) {
+return __left.__locale == nullptr;
+}
+
+friend bool operator==(int __left, const locale_t& __right) {
+return __left == 0 && nullptr == __right.__locale;
+}
+
+friend bool operator==(std::nullptr_t, const locale_t& __right) {
+return nullptr == __right.__locale;
+}
+
+friend bool operator!=(const locale_t& __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, int __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, std::nullptr_t __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(int __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(std::nullptr_t __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+operator bool() const {
+return __locale != nullptr;
+}
+
+const char* __get_locale() const { return __locale_str; }
+
+operator _locale_t() const {
+return __locale;
+}
+private:
+_locale_t __locale;
+const char* __locale_str;
+};
+
 // 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 );
+// uselocale can't be implemented on Windows because Windows allows partial modification
+// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
+// not create any copies.
+// We can still implement raii even without uselocale though.
 
 
 lconv *localeconv_l( locale_t loc );
Index: include/__locale
==

[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-22 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

In https://reviews.llvm.org/D40181#930779, @mstorsjo wrote:

>   (but I think it does define some sort of dummy functions that at least will 
> allow it to build)


Looked into MinGW-w64 sources and this is indeed the case. _configthreadlocale 
will return -1 and will not do anything.


https://reviews.llvm.org/D40181



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-22 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin updated this revision to Diff 123923.

https://reviews.llvm.org/D40181

Files:
  include/__config
  include/__locale
  include/support/win32/locale_win32.h
  src/support/win32/locale_win32.cpp

Index: include/__config
===
--- include/__config
+++ include/__config
@@ -877,7 +877,7 @@
 #define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63)
 #endif
 
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT) ||   \
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
 defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif
Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -18,23 +18,9 @@
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
 {
-return _create_locale( mask, locale );
+return {_create_locale( LC_ALL, locale ), locale};
 }
 
-locale_t uselocale( locale_t newloc )
-{
-locale_t old_locale = _get_current_locale();
-if ( newloc == NULL )
-return old_locale;
-// uselocale sets the thread's locale by definition, so unconditionally use thread-local locale
-_configthreadlocale( _ENABLE_PER_THREAD_LOCALE );
-// uselocale sets all categories
-// disable setting locale on Windows temporarily because the structure is opaque (PR31516)
-//setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale );
-// uselocale returns the old locale_t
-return old_locale;
-}
-
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
 #if defined(_LIBCPP_MSVCRT)
Index: include/support/win32/locale_win32.h
===
--- include/support/win32/locale_win32.h
+++ include/support/win32/locale_win32.h
@@ -14,6 +14,7 @@
 #include <__config>
 #include 
 #include  // _locale_t
+#include <__nullptr>
 
 #define LC_COLLATE_MASK _M_COLLATE
 #define LC_CTYPE_MASK _M_CTYPE
@@ -28,13 +29,77 @@
  | LC_NUMERIC_MASK \
  | LC_TIME_MASK )
 
-#define locale_t _locale_t
+class locale_t {
+public:
+locale_t()
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(std::nullptr_t)
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(_locale_t __locale, const char* __locale_str)
+: __locale(__locale), __locale_str(__locale_str) {}
 
+friend bool operator==(const locale_t& __left, const locale_t& __right) {
+return __left.__locale == __right.__locale;
+}
+
+friend bool operator==(const locale_t& __left, int __right) {
+return __left.__locale == nullptr && __right == 0;
+}
+
+friend bool operator==(const locale_t& __left, std::nullptr_t) {
+return __left.__locale == nullptr;
+}
+
+friend bool operator==(int __left, const locale_t& __right) {
+return __left == 0 && nullptr == __right.__locale;
+}
+
+friend bool operator==(std::nullptr_t, const locale_t& __right) {
+return nullptr == __right.__locale;
+}
+
+friend bool operator!=(const locale_t& __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, int __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, std::nullptr_t __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(int __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(std::nullptr_t __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+operator bool() const {
+return __locale != nullptr;
+}
+
+const char* __get_locale() const { return __locale_str; }
+
+operator _locale_t() const {
+return __locale;
+}
+private:
+_locale_t __locale;
+const char* __locale_str;
+};
+
 // 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 );
+// uselocale can't be implemented on Windows because Windows allows partial modification
+// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
+// not create any copies.
+// We can still implement raii even without uselocale though.
 
 
 lconv *localeconv_l( locale_t loc );
Index: include/__locale
===
--- include/__locale
+++ include/__locale
@@ -49,7 +49,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_LOCALE__L_EXTENSIO

[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-23 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

@EricWF, could you please commit this change?


https://reviews.llvm.org/D40181



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40774: [libcxx] Fix intrinsics for MSVC

2017-12-03 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

The parameter was previously renamed but MSVC path was not updated.


https://reviews.llvm.org/D40774

Files:
  include/algorithm


Index: include/algorithm
===
--- include/algorithm
+++ include/algorithm
@@ -797,7 +797,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanForward(&where, mask))
+  if (_BitScanForward(&where, __x))
 return where;
   return 32;
 #endif
@@ -823,15 +823,15 @@
 // Returns zero if no set bit is found.
 #if defined(_LIBCPP_HAS_BITSCAN64)
 (defined(_M_AMD64) || defined(__x86_64__))
-  if (_BitScanForward64(&where, mask))
+  if (_BitScanForward64(&where, __x))
 return static_cast(where);
 #else
   // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
   // Scan the Low Word.
-  if (_BitScanForward(&where, static_cast(mask)))
+  if (_BitScanForward(&where, static_cast(__x)))
 return where;
   // Scan the High Word.
-  if (_BitScanForward(&where, static_cast(mask >> 32)))
+  if (_BitScanForward(&where, static_cast(__x >> 32)))
 return where + 32; // Create a bit offset from the LSB.
 #endif
   return 64;
@@ -849,7 +849,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanReverse(&where, mask))
+  if (_BitScanReverse(&where, __x))
 return 31 - where;
   return 32; // Undefined Behavior.
 #endif
@@ -874,14 +874,14 @@
 // 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))
+  if (_BitScanReverse64(&where, __x))
 return static_cast(63 - where);
 #else
   // Scan the high 32 bits.
-  if (_BitScanReverse(&where, static_cast(mask >> 32)))
+  if (_BitScanReverse(&where, static_cast(__x >> 32)))
 return 63 - (where + 32); // Create a bit offset from the MSB.
   // Scan the low 32 bits.
-  if (_BitScanReverse(&where, static_cast(mask)))
+  if (_BitScanReverse(&where, static_cast(__x)))
 return 63 - where;
 #endif
   return 64; // Undefined Behavior.


Index: include/algorithm
===
--- include/algorithm
+++ include/algorithm
@@ -797,7 +797,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanForward(&where, mask))
+  if (_BitScanForward(&where, __x))
 return where;
   return 32;
 #endif
@@ -823,15 +823,15 @@
 // Returns zero if no set bit is found.
 #if defined(_LIBCPP_HAS_BITSCAN64)
 (defined(_M_AMD64) || defined(__x86_64__))
-  if (_BitScanForward64(&where, mask))
+  if (_BitScanForward64(&where, __x))
 return static_cast(where);
 #else
   // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
   // Scan the Low Word.
-  if (_BitScanForward(&where, static_cast(mask)))
+  if (_BitScanForward(&where, static_cast(__x)))
 return where;
   // Scan the High Word.
-  if (_BitScanForward(&where, static_cast(mask >> 32)))
+  if (_BitScanForward(&where, static_cast(__x >> 32)))
 return where + 32; // Create a bit offset from the LSB.
 #endif
   return 64;
@@ -849,7 +849,7 @@
   unsigned long where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanReverse(&where, mask))
+  if (_BitScanReverse(&where, __x))
 return 31 - where;
   return 32; // Undefined Behavior.
 #endif
@@ -874,14 +874,14 @@
 // 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))
+  if (_BitScanReverse64(&where, __x))
 return static_cast(63 - where);
 #else
   // Scan the high 32 bits.
-  if (_BitScanReverse(&where, static_cast(mask >> 32)))
+  if (_BitScanReverse(&where, static_cast(__x >> 32)))
 return 63 - (where + 32); // Create a bit offset from the MSB.
   // Scan the low 32 bits.
-  if (_BitScanReverse(&where, static_cast(mask)))
+  if (_BitScanReverse(&where, static_cast(__x)))
 return 63 - where;
 #endif
   return 64; // Undefined Behavior.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40775: [libcxx] Add underscores to win32 locale headers.

2017-12-03 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

Avoid possible collisions with macros.


Repository:
  rCXX libc++

https://reviews.llvm.org/D40775

Files:
  include/support/win32/locale_win32.h
  src/support/win32/locale_win32.cpp

Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -16,9 +16,9 @@
 using std::__libcpp_locale_guard;
 
 // 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 newlocale( int __mask, const char * __locale, locale_t /*__base*/ )
 {
-return {_create_locale( LC_ALL, locale ), locale};
+return {_create_locale( LC_ALL, __locale ), __locale};
 }
 
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
@@ -32,90 +32,90 @@
 }
 
 
-lconv *localeconv_l( locale_t loc )
+lconv *localeconv_l( locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
+__libcpp_locale_guard __current(__loc);
 return localeconv();
 }
-size_t mbrlen_l( const char *__restrict s, size_t n,
- mbstate_t *__restrict ps, locale_t loc )
+size_t mbrlen_l( const char *__restrict __s, size_t __n,
+ mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrlen( s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrlen( __s, __n, __ps );
 }
-size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
-size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsrtowcs( dst, src, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsrtowcs( __dst, __src, __len, __ps );
 }
-size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
-  locale_t loc )
+size_t wcrtomb_l( char *__restrict __s, wchar_t __wc, mbstate_t *__restrict __ps,
+  locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcrtomb( s, wc, ps );
+__libcpp_locale_guard __current(__loc);
+return wcrtomb( __s, __wc, __ps );
 }
-size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
-  size_t n, mbstate_t *__restrict ps, locale_t loc )
+size_t mbrtowc_l( wchar_t *__restrict __pwc, const char *__restrict __s,
+  size_t __n, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrtowc( pwc, s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrtowc( __pwc, __s, __n, __ps );
 }
-size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
- size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsnrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+ size_t __nms, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsnrtowcs( dst, src, nms, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsnrtowcs( __dst, __src, __nms, __len, __ps );
 }
-size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
- size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t wcsnrtombs_l( char *__restrict __dst, const wchar_t **__restrict __src,
+ size_t __nwc, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcsnrtombs( dst, src, nwc, len, ps );
+__libcpp_locale_guard __current(__loc);
+return wcsnrtombs( __dst, __src, __nwc, __len, __ps );
 }
-wint_t btowc_l( int c, locale_t loc )
+wint_t btowc_l( int __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return btowc( c );
+__libcpp_locale_guard __current(__loc);
+return btowc( __c );
 }
-int wctob_l( wint_t c, locale_t loc )
+int wctob_l( wint_t __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wctob( c );
+__libcpp_locale_guard __current(__loc);
+return wctob( __c );
 }
 
-int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
+int snprintf_l(char *__ret, size_t __n, locale_t __loc, const char *__format, ...)
 {
-__libcpp_locale_guard __current(loc);
+__libcpp_locale_guard __current(__loc);
 va_list ap;
-va_start( ap, format );
-int result = vsnprintf( ret, n, format, ap );
+va_start( ap, __format );
+int result = vsnprintf( __ret, __n, __format, ap );
 va_end(ap);
 return result;
 }
 
-int asprintf_l( char **ret, locale_t loc, const char *format, ... )
+int asprintf_l( char **__ret, locale_t __loc, const char *__fo

[PATCH] D40775: [libcxx] Add underscores to win32 locale headers.

2017-12-04 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin updated this revision to Diff 125354.

https://reviews.llvm.org/D40775

Files:
  include/support/win32/locale_win32.h
  src/support/win32/locale_win32.cpp

Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -16,9 +16,9 @@
 using std::__libcpp_locale_guard;
 
 // 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 newlocale( int __mask, const char * __locale, locale_t /*__base*/ )
 {
-return {_create_locale( LC_ALL, locale ), locale};
+return {_create_locale( LC_ALL, __locale ), __locale};
 }
 
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
@@ -32,90 +32,90 @@
 }
 
 
-lconv *localeconv_l( locale_t loc )
+lconv *localeconv_l( locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
+__libcpp_locale_guard __current(__loc);
 return localeconv();
 }
-size_t mbrlen_l( const char *__restrict s, size_t n,
- mbstate_t *__restrict ps, locale_t loc )
+size_t mbrlen_l( const char *__restrict __s, size_t __n,
+ mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrlen( s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrlen( __s, __n, __ps );
 }
-size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
-size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsrtowcs( dst, src, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsrtowcs( __dst, __src, __len, __ps );
 }
-size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
-  locale_t loc )
+size_t wcrtomb_l( char *__restrict __s, wchar_t __wc, mbstate_t *__restrict __ps,
+  locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcrtomb( s, wc, ps );
+__libcpp_locale_guard __current(__loc);
+return wcrtomb( __s, __wc, __ps );
 }
-size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
-  size_t n, mbstate_t *__restrict ps, locale_t loc )
+size_t mbrtowc_l( wchar_t *__restrict __pwc, const char *__restrict __s,
+  size_t __n, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbrtowc( pwc, s, n, ps );
+__libcpp_locale_guard __current(__loc);
+return mbrtowc( __pwc, __s, __n, __ps );
 }
-size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
- size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t mbsnrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
+ size_t __nms, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return mbsnrtowcs( dst, src, nms, len, ps );
+__libcpp_locale_guard __current(__loc);
+return mbsnrtowcs( __dst, __src, __nms, __len, __ps );
 }
-size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
- size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
+size_t wcsnrtombs_l( char *__restrict __dst, const wchar_t **__restrict __src,
+ size_t __nwc, size_t __len, mbstate_t *__restrict __ps, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wcsnrtombs( dst, src, nwc, len, ps );
+__libcpp_locale_guard __current(__loc);
+return wcsnrtombs( __dst, __src, __nwc, __len, __ps );
 }
-wint_t btowc_l( int c, locale_t loc )
+wint_t btowc_l( int __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return btowc( c );
+__libcpp_locale_guard __current(__loc);
+return btowc( __c );
 }
-int wctob_l( wint_t c, locale_t loc )
+int wctob_l( wint_t __c, locale_t __loc )
 {
-__libcpp_locale_guard __current(loc);
-return wctob( c );
+__libcpp_locale_guard __current(__loc);
+return wctob( __c );
 }
 
-int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
+int snprintf_l(char *__ret, size_t __n, locale_t __loc, const char *__format, ...)
 {
-__libcpp_locale_guard __current(loc);
-va_list ap;
-va_start( ap, format );
-int result = vsnprintf( ret, n, format, ap );
-va_end(ap);
-return result;
+__libcpp_locale_guard __current(__loc);
+va_list __ap;
+va_start(__ap, __format );
+int __result = vsnprintf( __ret, __n, __format, __ap );
+va_end(__ap);
+return __result;
 }
 
-int asprintf_l( char **ret, locale_t loc, const char *format, ... )
+int asprintf_l( char **__ret, locale_t __loc, cons

[PATCH] D40071: [libcxx] Implement exception_ptr on Windows without msvcprt.dll

2017-12-04 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin updated this revision to Diff 125356.
halyavin added a comment.

Updated diff to include whole context.


https://reviews.llvm.org/D40071

Files:
  include/exception
  src/support/runtime/exception_pointer_msvc.ipp

Index: src/support/runtime/exception_pointer_msvc.ipp
===
--- src/support/runtime/exception_pointer_msvc.ipp
+++ src/support/runtime/exception_pointer_msvc.ipp
@@ -8,84 +8,237 @@
 //
 //===--===//
 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include  // For RtlPcToFileHeader function
 
-#if !defined(_CRTIMP2_PURE)
-#define _CRTIMP2_PURE __declspec(dllimport)
+struct EHCatchableType {
+  uint32_t properties;
+  int32_t type_info;
+  uint32_t non_virtual_adjustment;
+  uint32_t offset_to_virtual_base_ptr;
+  uint32_t virtual_base_table_index;
+  uint32_t size;
+  int32_t copy_function;
+};
+
+struct EHCatchableTypeArray {
+  uint32_t catchable_types;
+  // It is variable size but we only need the first element of this array
+  int32_t array_of_catchable_types[1];
+};
+
+struct EHThrowInfo {
+  uint32_t attributes;
+  int32_t unwind;
+  int32_t forward_compat;
+  int32_t catchable_type_array;
+};
+
+struct EHParameters {
+  uint32_t magic_number;
+  void* exception_object;
+  EHThrowInfo* throw_info;
+#ifdef _M_AMD64
+  uintptr_t throw_image_base;
 #endif
+};
 
-#if !defined(__CLRCALL_PURE_OR_CDECL)
-#define __CLRCALL_PURE_OR_CDECL __cdecl
+struct EHExceptionRecord {
+  uint32_t exception_code;
+  uint32_t exception_flags;
+  void* exception_record;
+  void* exception_address;
+  uint32_t number_of_parameters;
+  EHParameters parameters;
+};
+
+// defined in vcruntime.dll
+extern "C" EHExceptionRecord** __current_exception();
+
+// This is internal compiler definition for MSVC but not for clang.
+// We use our own EHThrowInfo because _ThrowInfo doesn't match actual
+// compiler-generated structures in 64-bit mode.
+#ifdef __clang__
+struct _ThrowInfo;
+// defined in vcruntime.dll
+_LIBCPP_NORETURN extern "C" void __stdcall _CxxThrowException(
+void* __exc, _ThrowInfo* __throw_info);
 #endif
 
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(void*,
-  const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrAssign(void*, const void*);
-_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCompare(const void*, const void*);
-_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrToBool(const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(void*, void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCurrentException(void*);
-[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrRethrow(const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCopyException(void*, const void*, const void*);
+namespace {
+struct ExceptionPtr {
+  void* exception_object;
+  const EHThrowInfo* throw_info;
+  std::atomic counter;
+#ifdef _M_AMD64
+  PVOID image_base;
+#endif
+  template 
+  T convert(int32_t offset) {
+#ifdef _M_AMD64
+uintptr_t value = reinterpret_cast(image_base) +
+  static_cast(offset);
+#else
+uintptr_t value = static_cast(offset);
+#endif
+T res;
+static_assert(
+sizeof(value) == sizeof(res),
+"Can only convert to pointers or pointers to member functions");
+memcpy(&res, &value, sizeof(value));
+return res;
+  }
 
-namespace std {
+  void copy(void* dst, const void* src, const EHCatchableType* exc_type) {
+struct Temp {};
+constexpr uint32_t virtual_base = 4;
+if (exc_type->copy_function == 0) {
+  memcpy(dst, src, exc_type->size);
+} else if (exc_type->properties & virtual_base) {
+  auto copy_constructor =
+  convert(exc_type->copy_function);
+  ((Temp*)dst->*copy_constructor)(src, 1);
+} else {
+  auto copy_constructor =
+  convert(exc_type->copy_function);
+  ((Temp*)dst->*copy_constructor)(src);
+}
+  }
 
-exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); }
-exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); }
+  EHCatchableType* exception_type() {
+return convert(
+convert(throw_info->catchable_type_array)
+->array_of_catchable_types[0]);
+  }
 
-exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT {
-  __ExceptionPtrCopy(this, &__other);
-}
-exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _NOEXCEPT {
-  __ExceptionPtrAssign(this, &__other);
-  return *this;
-}
+  ExceptionPtr(const void* exception_object_, const EHThrowInfo* throw_info_)
+  : exception_object(nullptr), throw_info(throw_in

[PATCH] D40071: [libcxx] Implement exception_ptr on Windows without msvcprt.dll

2017-12-04 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin marked an inline comment as done.
halyavin added inline comments.



Comment at: src/support/runtime/exception_pointer_msvc.ipp:119-123
+#ifdef _M_AMD64
+RtlPcToFileHeader(
+reinterpret_cast(const_cast(throw_info)),
+&image_base);
+#endif

majnemer wrote:
> Can't you use the image_base field in throw_info?
The structure throw_info doesn't have image_base field, it is EHParameters that 
does. Unfortunately EHParameters is not available in make_exception_ptr.


https://reviews.llvm.org/D40071



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40774: [libcxx] Fix intrinsics for MSVC

2017-12-04 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

In https://reviews.llvm.org/D40774#943993, @smeenai wrote:

> Are you actually using libc++ with cl? :)


People mostly use it to compile on Windows but I heard someone launches the 
result too. Since no one complains and it passed most of the testing, I guess 
the result doesn't explode. It is also part of catboost but I haven't tried how 
well it works there myself yet.


https://reviews.llvm.org/D40774



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40774: [libcxx] Fix intrinsics for MSVC

2017-12-05 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

In https://reviews.llvm.org/D40774#944751, @smeenai wrote:

> In https://reviews.llvm.org/D40774#944749, @halyavin wrote:
>
> > In https://reviews.llvm.org/D40774#943993, @smeenai wrote:
> >
> > > Are you actually using libc++ with cl? :)
> >
> >
> > People mostly use it to compile on Windows but I heard someone launches the 
> > result too. Since no one complains and it passed most of the testing, I 
> > guess the result doesn't explode. It is also part of catboost but I haven't 
> > tried how well it works there myself yet.
>
>
> Hmm how is `#include_next` handled?


About the same way as this proposed change: https://reviews.llvm.org/D32411 .

PS Could you please commit this (https://reviews.llvm.org/D40774) change? I 
don't have commit rights.


https://reviews.llvm.org/D40774



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40775: [libcxx] Add underscores to win32 locale headers.

2017-12-13 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

@EricWF , could you please look at this change? It doesn't have any functional 
changes.


https://reviews.llvm.org/D40775



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39961: [libcxx] Fix rethrow_if_nested test on Windows.

2017-11-13 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

Stack overflow is caused by B copy constructor invoking default constructor of 
std::nested_exception which tries to capture current exception. Capturing 
current exception copies it and since our current exception is B, we call B's 
copy constructor and cause infinite recursion.

After fix, "throw b" no longer captures current exception (it copies it from 
B(5) object where it is empty) and so throw_if_nested terminates the test.


https://reviews.llvm.org/D39961

Files:
  
test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp


Index: 
test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
===
--- 
test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
+++ 
test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
@@ -9,9 +9,6 @@
 
 // UNSUPPORTED: libcpp-no-exceptions
 
-// This test fails due to a stack overflow
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // 
 
 // class nested_exception;
@@ -40,7 +37,7 @@
 {
 public:
 explicit B(int data) : A(data) {}
-B(const B& b) : A(b) {}
+B(const B& b) : std::nested_exception(b), A(b) {}
 };
 
 class C
@@ -104,7 +101,7 @@
 {
 try
 {
-throw b;
+throw B(4);
 }
 catch (const A& a)
 {


Index: test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
===
--- test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
+++ test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
@@ -9,9 +9,6 @@
 
 // UNSUPPORTED: libcpp-no-exceptions
 
-// This test fails due to a stack overflow
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // 
 
 // class nested_exception;
@@ -40,7 +37,7 @@
 {
 public:
 explicit B(int data) : A(data) {}
-B(const B& b) : A(b) {}
+B(const B& b) : std::nested_exception(b), A(b) {}
 };
 
 class C
@@ -104,7 +101,7 @@
 {
 try
 {
-throw b;
+throw B(4);
 }
 catch (const A& a)
 {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39962: [libcxx] Fix current_exception test on Windows.

2017-11-13 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

Take extra copies in current_exception() into account.


https://reviews.llvm.org/D39962

Files:
  
test/std/language.support/support.exception/propagation/current_exception.pass.cpp

Index: test/std/language.support/support.exception/propagation/current_exception.pass.cpp
===
--- test/std/language.support/support.exception/propagation/current_exception.pass.cpp
+++ test/std/language.support/support.exception/propagation/current_exception.pass.cpp
@@ -7,10 +7,6 @@
 //
 //===--===//
 
-// This test needs to be rewritten for the Windows exception_ptr semantics
-// which copy the exception each time the exception_ptr is copied.
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // UNSUPPORTED: libcpp-no-exceptions
 // 
 
@@ -51,6 +47,22 @@
 }
 assert(A::constructed == 0);
 {
+try 
+{
+throw A();
+assert(false);
+}
+catch(...)
+{
+std::exception_ptr p = std::current_exception();
+int constructed_before = A::constructed;
+std::exception_ptr p2 = p;
+assert(A::constructed == constructed_before);
+assert(p == p2);
+}
+}
+assert(A::constructed == 0);
+{
 std::exception_ptr p2;
 try
 {
@@ -61,11 +73,10 @@
 catch (...)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(A::constructed <= 2);
 assert(p != nullptr);
 p2 = std::current_exception();
-assert(A::constructed == 1);
-assert(p == p2);
+assert(A::constructed <= 3);
 }
 assert(A::constructed == 1);
 }
@@ -81,11 +92,10 @@
 catch (A&)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(A::constructed <= 2);
 assert(p != nullptr);
 p2 = std::current_exception();
-assert(A::constructed == 1);
-assert(p == p2);
+assert(A::constructed <= 3);
 }
 assert(A::constructed == 1);
 }
@@ -101,11 +111,10 @@
 catch (A)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 2);
+assert(A::constructed <= 3);
 assert(p != nullptr);
 p2 = std::current_exception();
-assert(A::constructed == 2);
-assert(p == p2);
+assert(A::constructed <= 4);
 }
 assert(A::constructed == 1);
 }
@@ -148,7 +157,7 @@
 try
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(A::constructed <= 2);
 assert(p != nullptr);
 throw;
 assert(false);
@@ -181,7 +190,7 @@
 catch (...)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(A::constructed <= 2);
 assert(p != nullptr);
 }
 assert(A::constructed == 1);
@@ -210,7 +219,7 @@
 assert(A::constructed == 1);
 }
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(A::constructed <= 2);
 assert(p != nullptr);
 }
 assert(A::constructed == 0);
@@ -263,9 +272,9 @@
 catch (...)
 {
 p = std::current_exception();
-assert(A::constructed == 1);
+assert(A::constructed <= 2);
 }
-assert(A::constructed == 1);
+assert(A::constructed <= 2);
 }
 assert(A::constructed == 1);
 assert(p != nullptr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39962: [libcxx] Fix current_exception test on Windows.

2017-11-15 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin updated this revision to Diff 122998.
halyavin added a comment.

Add lower bound too.


https://reviews.llvm.org/D39962

Files:
  
test/std/language.support/support.exception/propagation/current_exception.pass.cpp

Index: test/std/language.support/support.exception/propagation/current_exception.pass.cpp
===
--- test/std/language.support/support.exception/propagation/current_exception.pass.cpp
+++ test/std/language.support/support.exception/propagation/current_exception.pass.cpp
@@ -7,10 +7,6 @@
 //
 //===--===//
 
-// This test needs to be rewritten for the Windows exception_ptr semantics
-// which copy the exception each time the exception_ptr is copied.
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // UNSUPPORTED: libcpp-no-exceptions
 // 
 
@@ -51,6 +47,22 @@
 }
 assert(A::constructed == 0);
 {
+try 
+{
+throw A();
+assert(false);
+}
+catch(...)
+{
+std::exception_ptr p = std::current_exception();
+int constructed_before = A::constructed;
+std::exception_ptr p2 = p;
+assert(A::constructed == constructed_before);
+assert(p == p2);
+}
+}
+assert(A::constructed == 0);
+{
 std::exception_ptr p2;
 try
 {
@@ -61,11 +73,10 @@
 catch (...)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(1 <= A::constructed && A::constructed <= 2);
 assert(p != nullptr);
 p2 = std::current_exception();
-assert(A::constructed == 1);
-assert(p == p2);
+assert(1 <= A::constructed && A::constructed <= 3);
 }
 assert(A::constructed == 1);
 }
@@ -81,11 +92,10 @@
 catch (A&)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(1 <= A::constructed && A::constructed <= 2);
 assert(p != nullptr);
 p2 = std::current_exception();
-assert(A::constructed == 1);
-assert(p == p2);
+assert(1 <= A::constructed && A::constructed <= 3);
 }
 assert(A::constructed == 1);
 }
@@ -101,11 +111,10 @@
 catch (A)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 2);
+assert(2 <= A::constructed && A::constructed <= 3);
 assert(p != nullptr);
 p2 = std::current_exception();
-assert(A::constructed == 2);
-assert(p == p2);
+assert(2 <= A::constructed && A::constructed <= 4);
 }
 assert(A::constructed == 1);
 }
@@ -148,7 +157,7 @@
 try
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(1 <= A::constructed && A::constructed <= 2);
 assert(p != nullptr);
 throw;
 assert(false);
@@ -181,7 +190,7 @@
 catch (...)
 {
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(1 <= A::constructed && A::constructed <= 2);
 assert(p != nullptr);
 }
 assert(A::constructed == 1);
@@ -210,7 +219,7 @@
 assert(A::constructed == 1);
 }
 std::exception_ptr p = std::current_exception();
-assert(A::constructed == 1);
+assert(1 <= A::constructed && A::constructed <= 2);
 assert(p != nullptr);
 }
 assert(A::constructed == 0);
@@ -263,9 +272,9 @@
 catch (...)
 {
 p = std::current_exception();
-assert(A::constructed == 1);
+assert(1 <= A::constructed && A::constructed <= 2);
 }
-assert(A::constructed == 1);
+assert(1 <= A::constructed && A::constructed <= 2);
 }
 assert(A::constructed == 1);
 assert(p != nullptr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40071: [libcxx] Implement exception_ptr on Windows without msvcprt.dll

2017-11-15 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.
Herald added a reviewer: EricWF.

This change removes dependency on Microsoft STL implementation but adds 
dependency on VC runtime implementation. We will need to evolve and add 
#ifdef's to this code as new versions of Visual Studio runtime will come out.

Tested on x86 and x64, llvm clang 5.0, Visual Studio 2015 runtime.


https://reviews.llvm.org/D40071

Files:
  include/exception
  src/support/runtime/exception_pointer_msvc.ipp

Index: src/support/runtime/exception_pointer_msvc.ipp
===
--- src/support/runtime/exception_pointer_msvc.ipp
+++ src/support/runtime/exception_pointer_msvc.ipp
@@ -8,84 +8,237 @@
 //
 //===--===//
 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include  // For RtlPcToFileHeader function
 
-#if !defined(_CRTIMP2_PURE)
-#define _CRTIMP2_PURE __declspec(dllimport)
+struct EHCatchableType {
+  uint32_t properties;
+  int32_t type_info;
+  uint32_t non_virtual_adjustment;
+  uint32_t offset_to_virtual_base_ptr;
+  uint32_t virtual_base_table_index;
+  uint32_t size;
+  int32_t copy_function;
+};
+
+struct EHCatchableTypeArray {
+  uint32_t catchable_types;
+  // It is variable size but we only need the first element of this array
+  int32_t array_of_catchable_types[1];
+};
+
+struct EHThrowInfo {
+  uint32_t attributes;
+  int32_t unwind;
+  int32_t forward_compat;
+  int32_t catchable_type_array;
+};
+
+struct EHParameters {
+  uint32_t magic_number;
+  void* exception_object;
+  EHThrowInfo* throw_info;
+#ifdef _M_AMD64
+  uintptr_t throw_image_base;
 #endif
+};
 
-#if !defined(__CLRCALL_PURE_OR_CDECL)
-#define __CLRCALL_PURE_OR_CDECL __cdecl
+struct EHExceptionRecord {
+  uint32_t exception_code;
+  uint32_t exception_flags;
+  void* exception_record;
+  void* exception_address;
+  uint32_t number_of_parameters;
+  EHParameters parameters;
+};
+
+// defined in vcruntime.dll
+extern "C" EHExceptionRecord** __current_exception();
+
+// This is internal compiler definition for MSVC but not for clang.
+// We use our own EHThrowInfo because _ThrowInfo doesn't match actual
+// compiler-generated structures in 64-bit mode.
+#ifdef __clang__
+struct _ThrowInfo;
+// defined in vcruntime.dll
+_LIBCPP_NORETURN extern "C" void __stdcall _CxxThrowException(
+void* __exc, _ThrowInfo* __throw_info);
 #endif
 
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(void*,
-  const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrAssign(void*, const void*);
-_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCompare(const void*, const void*);
-_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrToBool(const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(void*, void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCurrentException(void*);
-[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrRethrow(const void*);
-_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
-__ExceptionPtrCopyException(void*, const void*, const void*);
+namespace {
+struct ExceptionPtr {
+  void* exception_object;
+  const EHThrowInfo* throw_info;
+  std::atomic counter;
+#ifdef _M_AMD64
+  PVOID image_base;
+#endif
+  template 
+  T convert(int32_t offset) {
+#ifdef _M_AMD64
+uintptr_t value = reinterpret_cast(image_base) +
+  static_cast(offset);
+#else
+uintptr_t value = static_cast(offset);
+#endif
+T res;
+static_assert(
+sizeof(value) == sizeof(res),
+"Can only convert to pointers or pointers to member functions");
+memcpy(&res, &value, sizeof(value));
+return res;
+  }
 
-namespace std {
+  void copy(void* dst, const void* src, const EHCatchableType* exc_type) {
+struct Temp {};
+constexpr uint32_t virtual_base = 4;
+if (exc_type->copy_function == 0) {
+  memcpy(dst, src, exc_type->size);
+} else if (exc_type->properties & virtual_base) {
+  auto copy_constructor =
+  convert(exc_type->copy_function);
+  ((Temp*)dst->*copy_constructor)(src, 1);
+} else {
+  auto copy_constructor =
+  convert(exc_type->copy_function);
+  ((Temp*)dst->*copy_constructor)(src);
+}
+  }
 
-exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); }
-exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); }
+  EHCatchableType* exception_type() {
+return convert(
+convert(throw_info->catchable_type_array)
+->array_of_catchable_types[0]);
+  }
 
-exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT {
-  __ExceptionPtrCopy(this, &__other);
-}
-exception_ptr& exception_ptr::op

[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-17 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

Fix the problem PR31516  with 
setting locale on Windows by wrapping _locale_t with a pointer-like class.

Reduces 74 test failures in std/localization test suite to 47 test failures (on 
llvm clang, Visual Studio 2015). Number of test failures doesn't depend on the 
platform (x86 or x64).


https://reviews.llvm.org/D40181

Files:
  include/__locale
  include/support/win32/locale_win32.h
  src/support/win32/locale_win32.cpp

Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -18,23 +18,9 @@
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
 {
-return _create_locale( mask, locale );
+return {_create_locale( LC_ALL, locale ), locale};
 }
 
-locale_t uselocale( locale_t newloc )
-{
-locale_t old_locale = _get_current_locale();
-if ( newloc == NULL )
-return old_locale;
-// uselocale sets the thread's locale by definition, so unconditionally use thread-local locale
-_configthreadlocale( _ENABLE_PER_THREAD_LOCALE );
-// uselocale sets all categories
-// disable setting locale on Windows temporarily because the structure is opaque (PR31516)
-//setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale );
-// uselocale returns the old locale_t
-return old_locale;
-}
-
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
 #if defined(_LIBCPP_MSVCRT)
Index: include/support/win32/locale_win32.h
===
--- include/support/win32/locale_win32.h
+++ include/support/win32/locale_win32.h
@@ -14,6 +14,7 @@
 #include <__config>
 #include 
 #include  // _locale_t
+#include <__nullptr>
 
 #define LC_COLLATE_MASK _M_COLLATE
 #define LC_CTYPE_MASK _M_CTYPE
@@ -28,13 +29,77 @@
  | LC_NUMERIC_MASK \
  | LC_TIME_MASK )
 
-#define locale_t _locale_t
+class locale_t {
+public:
+locale_t()
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(std::nullptr_t)
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(_locale_t __locale, const char* __locale_str)
+: __locale(__locale), __locale_str(__locale_str) {}
 
+friend bool operator==(const locale_t& __left, const locale_t& __right) {
+return __left.__locale == __right.__locale;
+}
+
+friend bool operator==(const locale_t& __left, int __right) {
+return __left.__locale == nullptr && __right == 0;
+}
+
+friend bool operator==(const locale_t& __left, nullptr_t) {
+return __left.__locale == nullptr;
+}
+
+friend bool operator==(int __left, const locale_t& __right) {
+return __left == 0 && nullptr == __right.__locale;
+}
+
+friend bool operator==(nullptr_t, const locale_t& __right) {
+return nullptr == __right.__locale;
+}
+
+friend bool operator!=(const locale_t& __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, int __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, nullptr_t __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(int __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(nullptr_t __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+operator bool() const {
+return __locale != nullptr;
+}
+
+const char* __get_locale() const { return __locale_str; }
+
+operator _locale_t() const {
+return __locale;
+}
+private:
+_locale_t __locale;
+const char* __locale_str;
+};
+
 // 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 );
+// uselocale can't be implemented on Windows because Windows allows partial modification
+// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
+// not create any copies.
+// We can still implement raii even without uselocale though.
 
 
 lconv *localeconv_l( locale_t loc );
Index: include/__locale
===
--- include/__locale
+++ include/__locale
@@ -49,7 +49,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT)
+#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
 struct __libcpp_locale_guard {
   _LIBCPP_INLINE_VISIBILITY
   __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
@@

[PATCH] D28220: provide Win32 native threading

2017-01-03 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: include/__threading_support:421
+if (!SleepConditionVariableCS(__cv, __m,
+  
duration_cast(timeout).count()))
+  return GetLastError();

We can have integer overflow on cast to DWORD here and get unexpectedly small 
wait for large timeouts.



Comment at: include/__threading_support:458
+{
+  // TODO(compnerd) provide a wrapper for CC adjustment
+  *__t = reinterpret_cast(_beginthreadex(

For other reviewers: CC means Calling Convention.


Repository:
  rL LLVM

https://reviews.llvm.org/D28220



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28220: provide Win32 native threading

2017-01-04 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: include/__threading_support:458
+   __libcpp_mutex_reference&& __m,
+   timespec* __ts)
+{

In posix, pthread_cond_timedwait uses absolute time but we use relative time 
here.



Comment at: include/__threading_support:460
+{
+  using namespace _VSTD::chrono;
+  auto timeout = seconds(__ts->tv_sec) + nanoseconds(__ts->tv_nsec);

We need to include  to use types and functions from this namespace.



Comment at: include/__threading_support:464
+
+  _LIBCPP_ASSERT(timeout_ms.count() < _VSTD::numeric_limits::max(),
+ "timeout duration overflows");

You have done it accidentally right. I realized there is a second problem here 
- if timeout equals to INFINITE, the thread will wait forever. INFINITE equals 
to (DWORD)-1, so the strict sign in the assert is required. But for sanity sake 
_VSTD::numeric_limits::max() should be replaced with INFINITE.  



Comment at: include/__threading_support:486
+static inline _LIBCPP_ALWAYS_INLINE BOOL CALLBACK
+__libcpp_init_once_trampoline(PINIT_ONCE InitOnce, PVOID Parameter,
+  PVOID *Context)

We need underscores for parameters and init_routine.



Comment at: include/__threading_support:497
+
+int __libcpp_execute_once(__libcpp_exec_once_flag* flag,
+  void (*init_routine)(void))

Underscores for parameters are missing.



Comment at: include/__threading_support:527
+static inline _LIBCPP_ALWAYS_INLINE unsigned int WINAPI
+__libcpp_thread_trampoline(void *__data)
+{

Trampolines will never be inlined. Should we put them in support *.cpp instead? 
The downside is new public symbols which can't be changed without breaking 
backward compatibility. The upside is that we will have only one copy of each 
trampoline. What do you think?



Comment at: include/__threading_support:531
+  *(__libcpp_thread_trampoline_data*)__data;
+  _VSTD::free(__data);
+  return reinterpret_cast(data.__func(data.__arg));

Do we need #include  for free() and malloc() now? Can we use 
new/delete instead?

BTW, What is the purpose of _VSTD? I think it is used to prevent 
argument-dependent lookup and so is not needed for free and malloc.



Comment at: include/__threading_support:532
+  _VSTD::free(__data);
+  return reinterpret_cast(data.__func(data.__arg));
+}

Should we even try to pass thread exit code, given that sizeof(unsigned int) < 
sizeof(void*) on 64-bit system? std::thread doesn't support thread exit code 
anyway.


Repository:
  rL LLVM

https://reviews.llvm.org/D28220



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28220: provide Win32 native threading

2017-01-04 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: include/__threading_support:474
+  
system_clock::time_point(duration_cast(duration));
+  auto timeout_ms = duration_cast(abstime - system_clock::now());
+

Since negative timeouts can't be avoided, we must make sure that 
timeout_ms.count() is at least zero.



Comment at: include/__threading_support:476
+
+  _LIBCPP_ASSERT(timeout_ms.count() > INFINITE && "timeout duration overflow");
+  if (!SleepConditionVariableSRW(__cv, __m, timeout_ms.count(), 0))

It is >= INFINITE. _LIBCPP_ASSERT has 2 arguments and supports error message 
out of the box.


Repository:
  rL LLVM

https://reviews.llvm.org/D28220



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28220: provide Win32 native threading

2017-01-05 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: include/__threading_support:474
+  
system_clock::time_point(duration_cast(duration));
+  auto timeout_ms = duration_cast(abstime - system_clock::now());
+

compnerd wrote:
> halyavin wrote:
> > Since negative timeouts can't be avoided, we must make sure that 
> > timeout_ms.count() is at least zero.
> Good point.  I suppose that the assert takes care of that though.
Negative timeout_ms.count() is a normal case, we shouldn't fail on assertion. 
The reason is that program can always be slow enough for current timestamp 
(system_clock::now()) to pass any fixed point in time (__ts/abstime). 



Comment at: include/__threading_support:476
+
+  _LIBCPP_ASSERT(timeout_ms.count() > INFINITE && "timeout duration overflow");
+  if (!SleepConditionVariableSRW(__cv, __m, timeout_ms.count(), 0))

compnerd wrote:
> halyavin wrote:
> > It is >= INFINITE. _LIBCPP_ASSERT has 2 arguments and supports error 
> > message out of the box.
> Shouldnt this be, `timeout_ms.count() > 0` which implicitly ensures that it 
> is not `INFINITE` (-1)?
I just checked in the Windows SDK, INFINITE is defined as `0x` and 
negative timeouts are legal anyway.



Repository:
  rL LLVM

https://reviews.llvm.org/D28220



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28220: provide Win32 native threading

2017-01-06 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

LGTM.




Comment at: include/__threading_support:480
+  if (!SleepConditionVariableSRW(__cv, __m,
+ timeout_ms.count() > 0 ? timeout_ms.count()
+: 0,

There is still problem with large timeout but let us fix it later.


https://reviews.llvm.org/D28220



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28441: [libc++] [CMake] Link with /nodefaultlibs on Windows

2017-01-06 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: lib/CMakeLists.txt:108-109
+if (LIBCXX_TARGETING_WINDOWS)
+  add_compile_flags(/Zl)
+  add_link_flags(/nodefaultlib)
+  add_library_flags(ucrt) # Universal C runtime

smeenai wrote:
> These should be guarded under a check for a cl or cl-like frontend rather 
> than `LIBCXX_TARGETING_WINDOWS` (since in theory we could be using the 
> regular clang frontend to compile for Windows as well).
Regular clang supports both gcc-like and cl-like options (there are 2 
compilers: clang.exe and clang-cl.exe). I think it is not worth it to support 
both considering they differ only in command line options handling.



Comment at: lib/CMakeLists.txt:111
+  add_library_flags(ucrt) # Universal C runtime
+  add_library_flags(vcruntime) # C++ runtime
+  add_library_flags(msvcrt) # C runtime startup files

smeenai wrote:
> Idk if there's anything specific to C++ in vcruntime; it's more compiler 
> runtime functions as far as I know.
It contains exception handling stuff.


https://reviews.llvm.org/D28441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28441: [libc++] [CMake] Link with /nodefaultlibs on Windows

2017-01-07 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: lib/CMakeLists.txt:112
+  add_library_flags(vcruntime) # C++ runtime
+  add_library_flags(msvcrt) # C runtime startup files
+  add_library_flags(iso_stdio_wide_specifiers)

As far as I know, applications shouldn't use msvcrt.dll ([[ 
https://blogs.msdn.microsoft.com/oldnewthing/20140411-00/?p=1273 | Windows is 
not a Microsoft Visual C/C++ Run-Time delivery channel ]]) Can we survive on 
ucrt only?


https://reviews.llvm.org/D28441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28441: [libc++] [CMake] Link with /nodefaultlibs on Windows

2017-01-07 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: lib/CMakeLists.txt:112
+  add_library_flags(vcruntime) # C++ runtime
+  add_library_flags(msvcrt) # C runtime startup files
+  add_library_flags(iso_stdio_wide_specifiers)

halyavin wrote:
> As far as I know, applications shouldn't use msvcrt.dll ([[ 
> https://blogs.msdn.microsoft.com/oldnewthing/20140411-00/?p=1273 | Windows is 
> not a Microsoft Visual C/C++ Run-Time delivery channel ]]) Can we survive on 
> ucrt only?
Oh, it is static library that doesn't correspond to a dll.


https://reviews.llvm.org/D28441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28441: [libc++] [CMake] Link with /nodefaultlibs on Windows

2017-01-07 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: lib/CMakeLists.txt:113
+  add_library_flags(msvcrt) # C runtime startup files
+  add_library_flags(iso_stdio_wide_specifiers)
+endif()

EricWF wrote:
> smeenai wrote:
> > Maybe add a comment explaining the purpose of this one as well?
> Not sure what the comment should read. I originally implemented this patch 
> without this library, but during testing it generated a undefined reference 
> to `___PLEASE_LINK_WITH_iso_stdio_wide_specifiers.lib`.  So should the 
> comment read "MSVC told me to link this"?
From very few hits Google gave me, it looks like this library implements proper 
behavior for %s and %c in printfw/scanfw-like functions. 


https://reviews.llvm.org/D28441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28441: [libc++] [CMake] Link with /nodefaultlibs on Windows

2017-01-07 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added inline comments.



Comment at: lib/CMakeLists.txt:113
+  add_library_flags(msvcrt) # C runtime startup files
+  add_library_flags(iso_stdio_wide_specifiers)
+endif()

EricWF wrote:
> halyavin wrote:
> > EricWF wrote:
> > > smeenai wrote:
> > > > Maybe add a comment explaining the purpose of this one as well?
> > > Not sure what the comment should read. I originally implemented this 
> > > patch without this library, but during testing it generated a undefined 
> > > reference to `___PLEASE_LINK_WITH_iso_stdio_wide_specifiers.lib`.  So 
> > > should the comment read "MSVC told me to link this"?
> > From very few hits Google gave me, it looks like this library implements 
> > proper behavior for %s and %c in printfw/scanfw-like functions. 
> That would make sense since the undefined symbols were in `locale.cpp`.  I 
> guess I'll update the comment to say "# required for wide character 
> formatting (e.g. `printfw`/`scanfw`)"
It is required for **correct** wide character formatting functions. Hence the 
ISO in the name. They were previously implemented incorrectly and this library 
fixes this (probably just flips a switch between legacy and correct behavior).


https://reviews.llvm.org/D28441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-07-17 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

In https://reviews.llvm.org/D32411#799878, @mclow.lists wrote:

> @smeenai wrote:
>
> > This is kinda ugly, but I can't think of a better way to do it. I'm fine 
> > with this, but given that it's a pretty invasive change, I'm not 
> > comfortable accepting. You may wanna ping @EricWF and @mclow.lists directly.
>
> I'll be meeting with the MS compiler engineers next week; I'll see when/if 
> they plan on implemementing `include_next`.


How was a meeting in Toronto? Did they say anything about `#include_next`?


https://reviews.llvm.org/D32411



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30837: [libcxx] Support for shared_ptr

2017-03-10 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

But std::allocator is deprecated in C++17. I don't know a good solution, 
I just used int as an arbitrary type when I faced similar problem.


https://reviews.llvm.org/D30837



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-04-23 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

Here is how we solved this problem in our libc++ fork:

  #define _LIBCPP_UCRT_INCLUDE(x) <../ucrt/x>
  #define _LIBCPP_MSVC_INCLUDE(x) <../../VC/include/x>



  #ifdef _LIBCPP_COMPILER_MSVC
  #include _LIBCPP_UCRT_INCLUDE(wchar.h)
  #else
  #include_next 
  #endif

As far as I understand neither solution resolves the problem with original 
paths not excluded. Watch out for cycling dependencies created by MSVC includes 
using other includes which point right back to libc++ instead.

Also, there is a problem with errno macro. I solved it like this:

  #ifdef _LIBCPP_COMPILER_MSVC
  // errno is defined in several files so we can't use #ifndef errno here
  #ifdef errno
  // undefine errno to avoid substitution in errno.h include file name.
  #pragma push_macro("errno")
  #undef errno
  #include _LIBCPP_UCRT_INCLUDE(errno.h)
  #pragma pop_macro("errno")
  #else
  #include _LIBCPP_UCRT_INCLUDE(errno.h)
  #endif
  #else
  #include_next 
  #endif


https://reviews.llvm.org/D32411



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-04-24 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

BTW, the list of include files which are located in [PROGRAM_FILES]\Microsoft 
Visual Studio 14.0\VC\include directory is

- stdbool.h
- limits.h
- stdint.h
- setjmp.h

The rest is in [PROGRAM_FILES]\Windows Kits\10\Include\10.0.whatever.0\ucrt 
directory. Which directory @_LIBCPP_INCLUDE_NEXT@ is supposed to point to?


https://reviews.llvm.org/D32411



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits