blob: 95a93a7a5459d08fea6de4d1bad6a1b40e8cb836 [file] [log] [blame]
Justin Lebar4c2c6fd2016-07-12 23:23:12 +00001// expected-no-diagnostics
2
3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
4// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s
5
6#include "Inputs/cuda.h"
7
8struct S {
9 __host__ static void operator delete(void*, size_t) {}
10 __device__ static void operator delete(void*, size_t) {}
11};
12
13__host__ __device__ void test(S* s) {
14 // This shouldn't be ambiguous -- we call the host overload in host mode and
15 // the device overload in device mode.
16 delete s;
17}
18
Artem Belevich07db5cf2016-10-21 20:34:05 +000019// Code should work with no explicit declarations/definitions of
20// allocator functions.
21__host__ __device__ void test_default_global_delete_hd(int *ptr) {
22 // Again, there should be no ambiguity between which operator delete we call.
23 ::delete ptr;
24}
25
26__device__ void test_default_global_delete(int *ptr) {
27 // Again, there should be no ambiguity between which operator delete we call.
28 ::delete ptr;
29}
30__host__ void test_default_global_delete(int *ptr) {
31 // Again, there should be no ambiguity between which operator delete we call.
32 ::delete ptr;
33}
34
35// It should work with only some of allocators (re-)declared.
36__device__ void operator delete(void *ptr);
37
38__host__ __device__ void test_partial_global_delete_hd(int *ptr) {
39 // Again, there should be no ambiguity between which operator delete we call.
40 ::delete ptr;
41}
42
43__device__ void test_partial_global_delete(int *ptr) {
44 // Again, there should be no ambiguity between which operator delete we call.
45 ::delete ptr;
46}
47__host__ void test_partial_global_delete(int *ptr) {
48 // Again, there should be no ambiguity between which operator delete we call.
49 ::delete ptr;
50}
51
52
53// We should be able to define both host and device variants.
Justin Lebar4c2c6fd2016-07-12 23:23:12 +000054__host__ void operator delete(void *ptr) {}
55__device__ void operator delete(void *ptr) {}
56
Artem Belevich07db5cf2016-10-21 20:34:05 +000057__host__ __device__ void test_overloaded_global_delete_hd(int *ptr) {
58 // Again, there should be no ambiguity between which operator delete we call.
59 ::delete ptr;
60}
61
62__device__ void test_overloaded_global_delete(int *ptr) {
63 // Again, there should be no ambiguity between which operator delete we call.
64 ::delete ptr;
65}
66__host__ void test_overloaded_global_delete(int *ptr) {
Justin Lebar4c2c6fd2016-07-12 23:23:12 +000067 // Again, there should be no ambiguity between which operator delete we call.
68 ::delete ptr;
69}