aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2018-05-17 20:32:55 +0000
committerJustin Lebar <jlebar@google.com>2018-05-17 20:32:55 +0000
commit8359b150c580590f77020524b8df3bce4c4f17f7 (patch)
tree17de846b5ae33177f082f7b5fde47017bcad72a4
parentf9c975a1e7ffc5c3c0dca6e52b53831319af5d25 (diff)
[test-suite] Test CUDA in C++14 mode with C++11 stdlibs.
Summary: Previously (D46993) std::min/max didn't work in C++14 mode with a C++11 stdlib; we'd assumed that compiler std=c++14 implied stdlib in C++14 mode. Reviewers: tra Subscribers: sanjoy, mgorny, llvm-commits, rsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D46994 git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@332659 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--External/CUDA/CMakeLists.txt27
-rw-r--r--External/CUDA/algorithm.cu2
-rw-r--r--External/CUDA/cmath.cu6
-rw-r--r--External/CUDA/complex.cu16
4 files changed, 30 insertions, 21 deletions
diff --git a/External/CUDA/CMakeLists.txt b/External/CUDA/CMakeLists.txt
index 27ea93a4..b80a472f 100644
--- a/External/CUDA/CMakeLists.txt
+++ b/External/CUDA/CMakeLists.txt
@@ -316,10 +316,6 @@ macro(create_cuda_tests)
set(_Std_LDFLAGS -std=${_Std})
foreach(_GccPath IN LISTS GCC_PATHS)
get_version(_GccVersion ${_GccPath})
- # libstdc++ seems not to support C++14 before version 5.0.
- if(${_Std} STREQUAL "c++14" AND ${_GccVersion} VERSION_LESS "5.0")
- continue()
- endif()
set(_Gcc_Suffix "libstdc++-${_GccVersion}")
# Tell clang to use libstdc++ and where to find it.
set(_Stdlib_CPPFLAGS -stdlib=libstdc++ -gcc-toolchain ${_GccPath})
@@ -327,17 +323,26 @@ macro(create_cuda_tests)
# Add libstdc++ as link dependency.
set(_Stdlib_Libs libstdcxx-${_GccVersion})
+ # libstdc++ seems not to support C++14 before version 5.0. We still
+ # want to run in C++14 mode with old libstdc++s to test compiler C++14
+ # with stdlib C++11, but we add a -D so that our tests can detect this.
+ if (${_GccVersion} VERSION_LESS "5.0")
+ list(APPEND _Stdlib_CPPFLAGS -DSTDLIB_VERSION=2011)
+ else()
+ list(APPEND _Stdlib_CPPFLAGS -DSTDLIB_VERSION=2014)
+ endif()
+
create_cuda_test_variant(${_Std} "${_Cuda_Suffix}-${_Std_Suffix}-${_Gcc_Suffix}")
endforeach()
if(HAVE_LIBCXX)
- # Same as above, but for libc++
- # Tell clang to use libc++
- # We also need to add compiler's include path for cxxabi.h
- get_filename_component(_compiler_path ${CMAKE_CXX_COMPILER} DIRECTORY)
- set(_Stdlib_CPPFLAGS -stdlib=libc++ -I${_compiler_path}/../include/c++-build)
- set(_Stdlib_LDFLAGS -stdlib=libc++)
- set(_Stdlib_Libs libcxx)
+ # Same as above, but for libc++
+ # Tell clang to use libc++
+ # We also need to add compiler's include path for cxxabi.h
+ get_filename_component(_compiler_path ${CMAKE_CXX_COMPILER} DIRECTORY)
+ set(_Stdlib_CPPFLAGS -stdlib=libc++ -I${_compiler_path}/../include/c++-build -DSTDLIB_VERSION=2017)
+ set(_Stdlib_LDFLAGS -stdlib=libc++)
+ set(_Stdlib_Libs libcxx)
create_cuda_test_variant(${_Std} "${_Cuda_Suffix}-${_Std_Suffix}-libc++")
endif()
endforeach()
diff --git a/External/CUDA/algorithm.cu b/External/CUDA/algorithm.cu
index 0149afa7..f79504fd 100644
--- a/External/CUDA/algorithm.cu
+++ b/External/CUDA/algorithm.cu
@@ -27,7 +27,7 @@ __device__ void max() {
// initializer_lists until C++14, when it gets these for free from the standard
// library (because they're constexpr).
__device__ void cpp14_tests() {
-#if __cplusplus >= 201402L
+#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014
assert(std::greater<int>()(1, 0));
assert(std::min({5, 1, 10}) == 1);
assert(std::max({5, 1, 10}, std::less<int>()) == 10);
diff --git a/External/CUDA/cmath.cu b/External/CUDA/cmath.cu
index 31760427..e12f3ef8 100644
--- a/External/CUDA/cmath.cu
+++ b/External/CUDA/cmath.cu
@@ -1145,7 +1145,7 @@ __device__ void test_hypot()
assert(std::hypot(3.f, 4.) == 5);
assert(std::hypot(3.f, 4.f) == 5);
-#if TEST_STD_VER > 14
+#if __cplusplus >= 201703L && STDLIB_VERSION >= 2017
static_assert((std::is_same<decltype(std::hypot((float)0, (float)0, (float)0)), float>::value), "");
static_assert((std::is_same<decltype(std::hypot((float)0, (bool)0, (float)0)), double>::value), "");
static_assert((std::is_same<decltype(std::hypot((float)0, (unsigned short)0, (double)0)), double>::value), "");
@@ -1158,8 +1158,8 @@ __device__ void test_hypot()
static_assert((std::is_same<decltype(std::hypot((int)0, (int)0, (int)0)), double>::value), "");
static_assert((std::is_same<decltype(hypot(Ambiguous(), Ambiguous(), Ambiguous())), Ambiguous>::value), "");
- assert(std::hypot(2,3,6) == 7);
- assert(std::hypot(1,4,8) == 9);
+ assert(std::hypot(2, 3, 6) == 7);
+ assert(std::hypot(1, 4, 8) == 9);
#endif
}
diff --git a/External/CUDA/complex.cu b/External/CUDA/complex.cu
index ef955cdb..e1ec117b 100644
--- a/External/CUDA/complex.cu
+++ b/External/CUDA/complex.cu
@@ -7,10 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include <assert.h>
-#include <stdio.h>
-#include <complex>
-
// These are loosely adapted from libc++'s tests. In general, we don't care a
// ton about verifying the return types or results we get, on the assumption
// that our standard library is correct. But we care deeply about calling every
@@ -19,13 +15,21 @@
// We do care about the results of complex multiplication / division, since
// these use code we've written.
+#include <stdio.h>
+
// These tests are pretty annoying to write without C++11, so we require that.
// In addition, these tests currently don't compile with libc++, because of the
// issue in https://reviews.llvm.org/D25403.
//
// TODO: Once that issue is resolved, take out !defined(_LIBCPP_VERSION) here.
-#if __cplusplus >= 201103L && !defined(_LIBCPP_VERSION)
+//
+// In addition, these tests don't work in C++14 mode with pre-C++14 versions of
+// libstdc++ (compile errors in <complex>).
+#if __cplusplus >= 201103L && !defined(_LIBCPP_VERSION) && \
+ (__cplusplus < 201402L || STDLIB_VERSION >= 2014)
+#include <assert.h>
+#include <complex>
#include <type_traits>
template <class T>
@@ -69,7 +73,7 @@ __device__ void test_promotion() {
}
__device__ void test_literals() {
-#if __cplusplus >= 201402L
+#if __cplusplus >= 201402L && STDLIB_VERSION >= 2014
using namespace std::literals::complex_literals;
{