diff --git a/.upstream-tests/test/std/utilities/utilities.general/broken_constant_eval.pass.cpp b/.upstream-tests/test/std/utilities/utilities.general/broken_constant_eval.pass.cpp new file mode 100644 index 0000000000..2d9fbd71dd --- /dev/null +++ b/.upstream-tests/test/std/utilities/utilities.general/broken_constant_eval.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This test serves as a canary for when this issue is fixed in NVCC +// +// UNSUPPORTED: windows, icc, pgi +// XFAIL: clang-9 && c++11 +// XFAIL: clang-10 && c++11 +// XFAIL: gcc-9 && c++11 +// XFAIL: gcc-10 && c++11 + + +#if defined(__has_builtin) +#if __has_builtin(__builtin_is_constant_evaluated) +#define BUILTIN_CONSTANT_EVAL() __builtin_is_constant_evaluated() +#endif +#endif + +#ifndef BUILTIN_CONSTANT_EVAL +#define BUILTIN_CONSTANT_EVAL() true +#endif + +__device__ __host__ inline constexpr bool constant_eval() { + return BUILTIN_CONSTANT_EVAL(); +} + +int main(int, char**) { + static_assert(constant_eval(), ""); + return 0; +} diff --git a/libcxx/include/__config b/libcxx/include/__config index c3d3abaa0c..3047663d60 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -647,6 +647,14 @@ typedef __char32_t char32_t; #define _LIBCUDACXX_IS_CONSTANT_EVALUATED(...) __builtin_is_constant_evaluated(__VA_ARGS__) #endif +// TODO: Builtin is not constexpr, this can be tested with an integral_constant +// but _only_ in C++11 mode. (fix for NVCC+clang-9 and up) +#if defined(__CUDACC__) +#if __cplusplus < 201402L +#undef _LIBCUDACXX_IS_CONSTANT_EVALUATED +#endif +#endif + #if __has_builtin(__builtin_addressof) #define _LIBCUDACXX_ADDRESSOF(...) __builtin_addressof(__VA_ARGS__) #endif