[PATCH] D39818: [CUDA] [test-suite] Test std::min and std::max with C++11.
Justin Lebar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 8 13:56:21 PST 2017
jlebar created this revision.
Herald added a subscriber: sanjoy.
Previously we only tested on C++14 and newer, which let slip a bug where
std::min returned the max. :(
https://reviews.llvm.org/D39818
Files:
External/CUDA/algorithm.cu
Index: External/CUDA/algorithm.cu
===================================================================
--- External/CUDA/algorithm.cu
+++ External/CUDA/algorithm.cu
@@ -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() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39818.122152.patch
Type: text/x-patch
Size: 1578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171108/64a7e8e2/attachment.bin>
More information about the cfe-commits
mailing list