[test-suite] r312682 - [CUDA] Tests for device-side overloads of non-placement new/delete.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 6 17:38:40 PDT 2017


Author: jlebar
Date: Wed Sep  6 17:38:40 2017
New Revision: 312682

URL: http://llvm.org/viewvc/llvm-project?rev=312682&view=rev
Log:
[CUDA] Tests for device-side overloads of non-placement new/delete.

Reviewers: tra

Subscribers: sanjoy, llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D37540

Added:
    test-suite/trunk/External/CUDA/new.cu
    test-suite/trunk/External/CUDA/new.reference_output
Modified:
    test-suite/trunk/External/CUDA/CMakeLists.txt

Modified: test-suite/trunk/External/CUDA/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/CMakeLists.txt?rev=312682&r1=312681&r2=312682&view=diff
==============================================================================
--- test-suite/trunk/External/CUDA/CMakeLists.txt (original)
+++ test-suite/trunk/External/CUDA/CMakeLists.txt Wed Sep  6 17:38:40 2017
@@ -53,6 +53,7 @@ macro(create_local_cuda_tests VariantSuf
   create_one_local_test(cmath cmath.cu)
   create_one_local_test(complex complex.cu)
   create_one_local_test(math_h math_h.cu)
+  create_one_local_test(new new.cu)
   create_one_local_test(empty empty.cu)
   create_one_local_test(printf printf.cu)
   create_one_local_test(future future.cu)

Added: test-suite/trunk/External/CUDA/new.cu
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/new.cu?rev=312682&view=auto
==============================================================================
--- test-suite/trunk/External/CUDA/new.cu (added)
+++ test-suite/trunk/External/CUDA/new.cu Wed Sep  6 17:38:40 2017
@@ -0,0 +1,69 @@
+// Check that operator new and operator delete work.
+
+#include <assert.h>
+#include <new>
+#include <stdio.h>
+
+__device__ void global_new() {
+  void* x = ::operator new(42);
+  assert(x != NULL);
+  ::operator delete(x);
+
+  x = ::operator new(42, std::nothrow);
+  assert(x != NULL);
+  ::operator delete(x, std::nothrow);
+
+  x = ::operator new[](42);
+  assert(x != NULL);
+  ::operator delete[](x);
+
+  x = ::operator new[](42, std::nothrow);
+  assert(x != NULL);
+  ::operator delete[](x, std::nothrow);
+}
+
+__device__ void sized_delete() {
+#if __cplusplus>= 201402L
+  void* x = ::operator new(42);
+  assert(x != NULL);
+  ::operator delete(x, 42);
+
+  x = ::operator new[](42);
+  assert(x != NULL);
+  ::operator delete[](x, 42);
+#endif
+}
+
+__device__ void int_new() {
+  int* x = new int();
+  assert(*x == 0);
+  delete x;
+}
+
+struct Foo {
+  __device__ Foo() : x(42) {}
+  int x;
+};
+__device__ void class_new() {
+  Foo* foo = new Foo();
+  assert(foo->x == 42);
+  delete foo;
+}
+
+__global__ void kernel() {
+  global_new();
+  sized_delete();
+  int_new();
+  class_new();
+}
+
+int main() {
+  kernel<<<32, 32>>>();
+  cudaError_t err = cudaDeviceSynchronize();
+  if (err != cudaSuccess) {
+    printf("CUDA error %d\n", (int)err);
+    return 1;
+  }
+  printf("Success!\n");
+  return 0;
+}

Added: test-suite/trunk/External/CUDA/new.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/new.reference_output?rev=312682&view=auto
==============================================================================
--- test-suite/trunk/External/CUDA/new.reference_output (added)
+++ test-suite/trunk/External/CUDA/new.reference_output Wed Sep  6 17:38:40 2017
@@ -0,0 +1,2 @@
+Success!
+exit 0




More information about the llvm-commits mailing list