From 470ddb8edf2d3a24a7b6165bb5cb3f6272de2f5f Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Sat, 8 Oct 2016 22:16:03 +0000 Subject: [PATCH] [CUDA] Declare our __device__ math functions in the same inline namespace as our standard library. Summary: Currently we declare our inline __device__ math functions in namespace std. But libstdc++ and libc++ declare these functions in an inline namespace inside namespace std. We need to match this because, in a later patch, we want to get e.g. to use our device overloads, and it only will if those overloads are in the right inline namespace. Reviewers: tra Subscribers: cfe-commits, jhen Differential Revision: https://reviews.llvm.org/D24977 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283678 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Headers/__clang_cuda_cmath.h | 22 ++++++++++++++++++- .../__clang_cuda_math_forward_declares.h | 20 +++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/Headers/__clang_cuda_cmath.h b/lib/Headers/__clang_cuda_cmath.h index 01aaa2f88a..569374584e 100644 --- a/lib/Headers/__clang_cuda_cmath.h +++ b/lib/Headers/__clang_cuda_cmath.h @@ -316,7 +316,19 @@ scalbn(__T __x, int __exp) { return std::scalbn((double)__x, __exp); } +// We need to define these overloads in exactly the namespace our standard +// library uses (including the right inline namespace), otherwise they won't be +// picked up by other functions in the standard library (e.g. functions in +// ). Thus the ugliness below. +#ifdef _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_NAMESPACE_STD +#else namespace std { +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_BEGIN_NAMESPACE_VERSION +#endif +#endif + // Pull the new overloads we defined above into namespace std. using ::acos; using ::acosh; @@ -451,7 +463,15 @@ using ::tanf; using ::tanhf; using ::tgammaf; using ::truncf; -} + +#ifdef _LIBCPP_END_NAMESPACE_STD +_LIBCPP_END_NAMESPACE_STD +#else +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_END_NAMESPACE_VERSION +#endif +} // namespace std +#endif #undef __DEVICE__ diff --git a/lib/Headers/__clang_cuda_math_forward_declares.h b/lib/Headers/__clang_cuda_math_forward_declares.h index 0a605e1956..49c805151d 100644 --- a/lib/Headers/__clang_cuda_math_forward_declares.h +++ b/lib/Headers/__clang_cuda_math_forward_declares.h @@ -185,7 +185,19 @@ __DEVICE__ float tgamma(float); __DEVICE__ double trunc(double); __DEVICE__ float trunc(float); +// We need to define these overloads in exactly the namespace our standard +// library uses (including the right inline namespace), otherwise they won't be +// picked up by other functions in the standard library (e.g. functions in +// ). Thus the ugliness below. +#ifdef _LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_BEGIN_NAMESPACE_STD +#else namespace std { +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_BEGIN_NAMESPACE_VERSION +#endif +#endif + using ::abs; using ::acos; using ::acosh; @@ -259,7 +271,15 @@ using ::tan; using ::tanh; using ::tgamma; using ::trunc; + +#ifdef _LIBCPP_END_NAMESPACE_STD +_LIBCPP_END_NAMESPACE_STD +#else +#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_END_NAMESPACE_VERSION +#endif } // namespace std +#endif #pragma pop_macro("__DEVICE__") -- 2.40.0