[test-suite] r317962 - [CUDA] [test-suite] Test std::min and std::max with C++11.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 17:26:39 PST 2017
Author: jlebar
Date: Fri Nov 10 17:26:39 2017
New Revision: 317962
URL: http://llvm.org/viewvc/llvm-project?rev=317962&view=rev
Log:
[CUDA] [test-suite] Test std::min and std::max with C++11.
Summary:
Previously we only tested on C++14 and newer, which let slip a bug where
std::min returned the max. :(
Reviewers: tra
Subscribers: sanjoy, cfe-commits
Differential Revision: https://reviews.llvm.org/D39818
Modified:
test-suite/trunk/External/CUDA/algorithm.cu
Modified: test-suite/trunk/External/CUDA/algorithm.cu
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/algorithm.cu?rev=317962&r1=317961&r2=317962&view=diff
==============================================================================
--- test-suite/trunk/External/CUDA/algorithm.cu (original)
+++ test-suite/trunk/External/CUDA/algorithm.cu Fri Nov 10 17:26:39 2017
@@ -7,39 +7,42 @@
// we can successfully compile and run the standard library's implementations
// of these functions.
-#if __cplusplus >= 201402L
+#if __cplusplus >= 201103L
#include <assert.h>
#include <algorithm>
#include <functional>
#include <stdio.h>
-__device__ void greater() {
- assert(std::greater<int>()(1, 0));
-}
-
__device__ void min() {
assert(std::min(0, 1) == 0);
- assert(std::min({5, 1, 10}) == 1);
}
__device__ void max() {
assert(std::max(0, 1) == 1);
- assert(std::max({5, 1, 10}, std::less<int>()) == 10);
}
-__device__ void minmax() {
+// Clang has device-side shims implementing std::min and std::max for scalars
+// starting in C++11, but doesn't implement minimax or std::min/max on
+// 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
+ assert(std::greater<int>()(1, 0));
+ assert(std::min({5, 1, 10}) == 1);
+ assert(std::max({5, 1, 10}, std::less<int>()) == 10);
+
assert(std::minmax(1, 0).first == 0);
assert(std::minmax(1, 0).second == 1);
assert(std::minmax({0, 10, -10, 100}, std::less<int>()).first == -10);
assert(std::minmax({0, 10, -10, 100}, std::less<int>()).second == 100);
+#endif
}
__global__ void kernel() {
- greater();
min();
max();
- minmax();
+ cpp14_tests();
}
int main() {
More information about the llvm-commits
mailing list