Author: jlebar Date: Tue Nov 15 13:15:57 2016 New Revision: 287012 URL: http://llvm.org/viewvc/llvm-project?rev=287012&view=rev Log: [CUDA] Mark __libcpp_{isnan,isinf,isfinite} as constexpr.
Summary: This makes these functions available on host and device, which is necessary to compile <complex> for the device. Reviewers: hfinkel, EricWF Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25403 Added: libcxx/trunk/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp Modified: libcxx/trunk/include/cmath Modified: libcxx/trunk/include/cmath URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cmath?rev=287012&r1=287011&r2=287012&view=diff ============================================================================== --- libcxx/trunk/include/cmath (original) +++ libcxx/trunk/include/cmath Tue Nov 15 13:15:57 2016 @@ -554,7 +554,7 @@ hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __ template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isnan) @@ -566,7 +566,7 @@ __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT { return isnan(__lcpp_x); @@ -574,7 +574,7 @@ __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isinf) @@ -586,7 +586,7 @@ __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT { return isinf(__lcpp_x); @@ -594,7 +594,7 @@ __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isfinite) @@ -606,7 +606,7 @@ __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEP template <class _A1> _LIBCPP_ALWAYS_INLINE -typename enable_if<!is_floating_point<_A1>::value, bool>::type +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT { return isfinite(__lcpp_x); Added: libcxx/trunk/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp?rev=287012&view=auto ============================================================================== --- libcxx/trunk/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp (added) +++ libcxx/trunk/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp Tue Nov 15 13:15:57 2016 @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// Check that the overloads of std::__libcpp_{isnan,isinf,isfinite} that take +// floating-point values are evaluatable from constexpr contexts. +// +// These functions need to be constexpr in order to be called from CUDA, see +// https://reviews.llvm.org/D25403. They don't actually need to be +// constexpr-evaluatable, but that's what we check here, since we can't check +// true constexpr-ness. +// +// UNSUPPORTED: c++98, c++03 + +#include <cmath> + +constexpr bool a = std::__libcpp_isnan(0.); +constexpr bool b = std::__libcpp_isinf(0.0); +constexpr bool c = std::__libcpp_isfinite(0.0); + +int main() +{ + return 0; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits