[cfe-dev] [PATCH] Libc++ Windows fixes
Ruben Van Boxem
vanboxem.ruben at gmail.com
Thu Oct 27 06:11:59 PDT 2011
And now with patch attached.
2011/10/27 Ruben Van Boxem <vanboxem.ruben at gmail.com>
> Hi,
>
> Attached is a patch which I could make using an MSVC-based Clang (MSVC
> headers, Clang's language support). I had to ifdef out all C99 math, I
> implemented the floating point functions. And I fixed some bad things in the
> win32 MSVC support headers.
>
>
> Comments and commits welcome!
>
> Ruben
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111027/9b7b2e62/attachment.html>
-------------- next part --------------
Index: include/cstdlib
===================================================================
--- include/cstdlib (revision 142734)
+++ include/cstdlib (working copy)
@@ -82,7 +82,7 @@
#include <__config>
#include <stdlib.h>
#ifdef _MSC_VER
-#include "support/win32/support.h"
+#include "support/win32/locale_win32.h"
#endif // _MSC_VER
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Index: include/cmath
===================================================================
--- include/cmath (revision 142734)
+++ include/cmath (working copy)
@@ -301,6 +301,10 @@
#include <math.h>
#include <type_traits>
+#ifdef _MSC_VER
+#include "support/win32/math_win32.h"
+#endif
+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
@@ -654,8 +658,10 @@
using ::acos;
using ::acosf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float acos(float __x) {return acosf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __x) {return acosl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -667,8 +673,10 @@
using ::asin;
using ::asinf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float asin(float __x) {return asinf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __x) {return asinl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -680,8 +688,10 @@
using ::atan;
using ::atanf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float atan(float __x) {return atanf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __x) {return atanl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -693,8 +703,10 @@
using ::atan2;
using ::atan2f;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float atan2(float __y, float __x) {return atan2f(__y, __x);}
inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __y, long double __x) {return atan2l(__y, __x);}
+#endif
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
@@ -717,8 +729,10 @@
using ::ceil;
using ::ceilf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float ceil(float __x) {return ceilf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __x) {return ceill(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -730,8 +744,10 @@
using ::cos;
using ::cosf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float cos(float __x) {return cosf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __x) {return cosl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY
@@ -743,8 +759,10 @@
using ::cosh;
using ::coshf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float cosh(float __x) {return coshf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __x) {return coshl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -756,8 +774,10 @@
using ::exp;
using ::expf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float exp(float __x) {return expf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __x) {return expl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -769,8 +789,10 @@
using ::fabs;
using ::fabsf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float fabs(float __x) {return fabsf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __x) {return fabsl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -782,8 +804,10 @@
using ::floor;
using ::floorf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float floor(float __x) {return floorf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __x) {return floorl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -795,8 +819,10 @@
using ::fmod;
using ::fmodf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float fmod(float __x, float __y) {return fmodf(__x, __y);}
inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __x, long double __y) {return fmodl(__x, __y);}
+#endif
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
@@ -819,8 +845,10 @@
using ::frexp;
using ::frexpf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float frexp(float __x, int* __e) {return frexpf(__x, __e);}
inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __x, int* __e) {return frexpl(__x, __e);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -832,8 +860,10 @@
using ::ldexp;
using ::ldexpf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __x, int __e) {return ldexpf(__x, __e);}
inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __x, int __e) {return ldexpl(__x, __e);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -845,8 +875,10 @@
using ::log;
using ::logf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float log(float __x) {return logf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double log(long double __x) {return logl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -858,8 +890,10 @@
using ::log10;
using ::log10f;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float log10(float __x) {return log10f(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __x) {return log10l(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -871,16 +905,20 @@
using ::modf;
using ::modff;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float modf(float __x, float* __y) {return modff(__x, __y);}
inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __x, long double* __y) {return modfl(__x, __y);}
+#endif
// pow
using ::pow;
using ::powf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float pow(float __x, float __y) {return powf(__x, __y);}
inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __x, long double __y) {return powl(__x, __y);}
+#endif
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
@@ -903,8 +941,10 @@
using ::sin;
using ::sinf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float sin(float __x) {return sinf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __x) {return sinl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -916,8 +956,10 @@
using ::sinh;
using ::sinhf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float sinh(float __x) {return sinhf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __x) {return sinhl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -929,8 +971,10 @@
using ::sqrt;
using ::sqrtf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __x) {return sqrtf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __x) {return sqrtl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -942,8 +986,10 @@
using ::tan;
using ::tanf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float tan(float __x) {return tanf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __x) {return tanl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -955,8 +1001,10 @@
using ::tanh;
using ::tanhf;
+#ifndef _MSC_VER
inline _LIBCPP_INLINE_VISIBILITY float tanh(float __x) {return tanhf(__x);}
inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __x) {return tanhl(__x);}
+#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
@@ -965,6 +1013,7 @@
// acosh
+#ifndef _MSC_VER
using ::acosh;
using ::acoshf;
@@ -975,9 +1024,11 @@
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_integral<_A1>::value, double>::type
acosh(_A1 __x) {return acosh((double)__x);}
+#endif
// asinh
+#ifndef _MSC_VER
using ::asinh;
using ::asinhf;
@@ -988,9 +1039,11 @@
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_integral<_A1>::value, double>::type
asinh(_A1 __x) {return asinh((double)__x);}
+#endif
// atanh
+#ifndef _MSC_VER
using ::atanh;
using ::atanhf;
@@ -1001,9 +1054,11 @@
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_integral<_A1>::value, double>::type
atanh(_A1 __x) {return atanh((double)__x);}
+#endif
// cbrt
+#ifndef _MSC_VER
using ::cbrt;
using ::cbrtf;
@@ -1014,6 +1069,7 @@
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_integral<_A1>::value, double>::type
cbrt(_A1 __x) {return cbrt((double)__x);}
+#endif
// copysign
@@ -1039,6 +1095,8 @@
return copysign((__result_type)__x, (__result_type)__y);
}
+#ifndef _MSC_VER
+
// erf
using ::erf;
@@ -1513,6 +1571,8 @@
typename enable_if<is_integral<_A1>::value, double>::type
trunc(_A1 __x) {return trunc((double)__x);}
+#endif // !_MSC_VER
+
using ::acosl;
using ::asinl;
using ::atanl;
@@ -1534,12 +1594,15 @@
using ::sinhl;
using ::sqrtl;
using ::tanl;
+#ifndef _MSC_VER
using ::tanhl;
using ::acoshl;
using ::asinhl;
using ::atanhl;
using ::cbrtl;
+#endif !_MSC_VER
using ::copysignl;
+#ifndef _MSC_VER
using ::erfl;
using ::erfcl;
using ::exp2l;
@@ -1570,6 +1633,7 @@
using ::scalbnl;
using ::tgammal;
using ::truncl;
+#endif // !_MSC_VER
_LIBCPP_END_NAMESPACE_STD
Index: include/__config
===================================================================
--- include/__config (revision 142734)
+++ include/__config (working copy)
@@ -321,7 +321,6 @@
#elif defined(_MSC_VER)
-#define _LIBCPP_HAS_NO_RVALUE_REFERENCES
#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
#define _LIBCPP_HAS_NO_CONSTEXPR
Index: include/support/win32/math_win32.h
===================================================================
--- include/support/win32/math_win32.h (revision 0)
+++ include/support/win32/math_win32.h (revision 0)
@@ -0,0 +1,113 @@
+// -*- C++ -*-
+//===---------------------- support/win32/math_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_MATH_WIN32_H
+#define _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
+
+#if !defined(_MSC_VER)
+#error "This header is MSVC specific, Clang and GCC should not include it"
+#else
+
+#include <math.h>
+
+typedef float float_t;
+typedef double double_t;
+
+_LIBCPP_ALWAYS_INLINE bool isfinite( double num )
+{
+ return _finite(num) != 0;
+}
+_LIBCPP_ALWAYS_INLINE bool isinf( double num )
+{
+ return !isfinite(num) && !_isnan(num);
+}
+_LIBCPP_ALWAYS_INLINE bool isnan( double num )
+{
+ return _isnan(num) != 0;
+}
+_LIBCPP_ALWAYS_INLINE bool isnormal( double num )
+{
+ int class_ = _fpclass(num);
+ return class_ == _FPCLASS_NN || class_ == _FPCLASS_PN;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isgreater( double x, double y )
+{
+ if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x > y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isgreaterequal( double x, double y )
+{
+ if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x >= y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isless( double x, double y )
+{
+ if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x < y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool islessequal( double x, double y )
+{
+ if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x <= y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool islessgreater( double x, double y )
+{
+ if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x < y || x > y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isunordered( double x, double y )
+{
+ return isnan(x) || isnan(y);
+}
+_LIBCPP_ALWAYS_INLINE bool signbit( double num )
+{
+ switch(_fpclass(num))
+ {
+ case _FPCLASS_SNAN:
+ case _FPCLASS_QNAN:
+ case _FPCLASS_NINF:
+ case _FPCLASS_NN:
+ case _FPCLASS_ND:
+ case _FPCLASS_NZ:
+ return true;
+ case _FPCLASS_PZ:
+ case _FPCLASS_PD:
+ case _FPCLASS_PN:
+ case _FPCLASS_PINF:
+ return false;
+ }
+ return false;
+}
+_LIBCPP_ALWAYS_INLINE float copysignf( float x, float y )
+{
+ return (signbit (x) != signbit (y) ? - x : x);
+}
+_LIBCPP_ALWAYS_INLINE double copysign( double x, double y )
+{
+ return ::_copysign(x,y);
+}
+_LIBCPP_ALWAYS_INLINE double copysignl( long double x, long double y )
+{
+ return ::_copysignl(x,y);
+}
+_LIBCPP_ALWAYS_INLINE int fpclassify( double num )
+{
+ return _fpclass(num);
+}
+
+#endif // _MSC_VER
+
+#endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
\ No newline at end of file
Index: include/support/win32/support.h
===================================================================
--- include/support/win32/support.h (revision 142734)
+++ include/support/win32/support.h (working copy)
@@ -34,10 +34,7 @@
#if defined(_MSC_VER)
#define snprintf _snprintf
-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' ); }
+
#include <xlocinfo.h>
#define atoll _atoi64
#define strtoll _strtoi64
@@ -50,10 +47,10 @@
{ return _Stod(nptr, endptr, 0); }
_LIBCPP_ALWAYS_INLINE long double strtold( const char *nptr, char **endptr )
{ return _Stold(nptr, endptr, 0); }
-_LIBCPP_ALWAYS_INLINE float wcstof( const wchar_t *nptr, char** endptr )
#define _Exit _exit
+#ifndef __clang__ // MSVC-based Clang also defines _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountl __popcnt
@@ -89,7 +86,7 @@
_BitScanForward64(&r, x);
return static_cast<int>(r);
}
+#endif // !__clang__
+#endif // _MSC_VER
-#endif
-
#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H
\ No newline at end of file
Index: include/support/win32/locale_win32.h
===================================================================
--- include/support/win32/locale_win32.h (revision 142734)
+++ include/support/win32/locale_win32.h (working copy)
@@ -107,4 +107,10 @@
return ( c == L' ' || c == L'\t' );
}
+#ifdef _MSC_VER
+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 // _MSC_VER
#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
More information about the cfe-dev
mailing list