annotate clang/test/SemaCUDA/usual-deallocators.cu @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 79ff65ed7e25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 %s --std=c++11 -triple nvptx-unknown-unknown -fcuda-is-device \
anatofuz
parents:
diff changeset
2 // RUN: -emit-llvm -o /dev/null -verify=device
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 %s --std=c++11 -triple nvptx-unknown-unknown \
anatofuz
parents:
diff changeset
4 // RUN: -emit-llvm -o /dev/null -verify=host
anatofuz
parents:
diff changeset
5 // RUN: %clang_cc1 %s --std=c++17 -triple nvptx-unknown-unknown -fcuda-is-device \
anatofuz
parents:
diff changeset
6 // RUN: -emit-llvm -o /dev/null -verify=device
anatofuz
parents:
diff changeset
7 // RUN: %clang_cc1 %s --std=c++17 -triple nvptx-unknown-unknown \
anatofuz
parents:
diff changeset
8 // RUN: -emit-llvm -o /dev/null -verify=host
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 #include "Inputs/cuda.h"
anatofuz
parents:
diff changeset
11 extern __host__ void host_fn();
anatofuz
parents:
diff changeset
12 extern __device__ void dev_fn();
anatofuz
parents:
diff changeset
13 extern __host__ __device__ void hd_fn();
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 struct H1D1 {
anatofuz
parents:
diff changeset
16 __host__ void operator delete(void *) { host_fn(); };
anatofuz
parents:
diff changeset
17 __device__ void operator delete(void *) { dev_fn(); };
anatofuz
parents:
diff changeset
18 };
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 struct h1D1 {
anatofuz
parents:
diff changeset
21 __host__ void operator delete(void *) = delete;
anatofuz
parents:
diff changeset
22 // host-note@-1 {{'operator delete' has been explicitly marked deleted here}}
anatofuz
parents:
diff changeset
23 __device__ void operator delete(void *) { dev_fn(); };
anatofuz
parents:
diff changeset
24 };
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 struct H1d1 {
anatofuz
parents:
diff changeset
27 __host__ void operator delete(void *) { host_fn(); };
anatofuz
parents:
diff changeset
28 __device__ void operator delete(void *) = delete;
anatofuz
parents:
diff changeset
29 // device-note@-1 {{'operator delete' has been explicitly marked deleted here}}
anatofuz
parents:
diff changeset
30 };
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 struct H1D2 {
anatofuz
parents:
diff changeset
33 __host__ void operator delete(void *) { host_fn(); };
anatofuz
parents:
diff changeset
34 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
anatofuz
parents:
diff changeset
35 };
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 struct H2D1 {
anatofuz
parents:
diff changeset
38 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
anatofuz
parents:
diff changeset
39 __device__ void operator delete(void *) { dev_fn(); };
anatofuz
parents:
diff changeset
40 };
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 struct H2D2 {
anatofuz
parents:
diff changeset
43 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
anatofuz
parents:
diff changeset
44 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
anatofuz
parents:
diff changeset
45 };
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 struct H1D1D2 {
anatofuz
parents:
diff changeset
48 __host__ void operator delete(void *) { host_fn(); };
anatofuz
parents:
diff changeset
49 __device__ void operator delete(void *) { dev_fn(); };
anatofuz
parents:
diff changeset
50 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
anatofuz
parents:
diff changeset
51 };
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 struct H1H2D1 {
anatofuz
parents:
diff changeset
54 __host__ void operator delete(void *) { host_fn(); };
anatofuz
parents:
diff changeset
55 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
anatofuz
parents:
diff changeset
56 __device__ void operator delete(void *) { dev_fn(); };
anatofuz
parents:
diff changeset
57 };
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 struct H1H2D2 {
anatofuz
parents:
diff changeset
60 __host__ void operator delete(void *) { host_fn(); };
anatofuz
parents:
diff changeset
61 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
anatofuz
parents:
diff changeset
62 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
anatofuz
parents:
diff changeset
63 };
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 struct H1H2D1D2 {
anatofuz
parents:
diff changeset
66 __host__ void operator delete(void *) { host_fn(); };
anatofuz
parents:
diff changeset
67 __host__ void operator delete(void *, __SIZE_TYPE__) { host_fn(); };
anatofuz
parents:
diff changeset
68 __device__ void operator delete(void *) { dev_fn(); };
anatofuz
parents:
diff changeset
69 __device__ void operator delete(void *, __SIZE_TYPE__) { dev_fn(); };
anatofuz
parents:
diff changeset
70 };
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 template <typename T>
anatofuz
parents:
diff changeset
74 __host__ __device__ void test_hd(void *p) {
anatofuz
parents:
diff changeset
75 T *t = (T *)p;
anatofuz
parents:
diff changeset
76 delete t;
anatofuz
parents:
diff changeset
77 // host-error@-1 {{attempt to use a deleted function}}
anatofuz
parents:
diff changeset
78 // device-error@-2 {{attempt to use a deleted function}}
anatofuz
parents:
diff changeset
79 }
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 __host__ __device__ void tests_hd(void *t) {
anatofuz
parents:
diff changeset
82 test_hd<H1D1>(t);
anatofuz
parents:
diff changeset
83 test_hd<h1D1>(t);
anatofuz
parents:
diff changeset
84 // host-note@-1 {{in instantiation of function template specialization 'test_hd<h1D1>' requested here}}
anatofuz
parents:
diff changeset
85 test_hd<H1d1>(t);
anatofuz
parents:
diff changeset
86 // device-note@-1 {{in instantiation of function template specialization 'test_hd<H1d1>' requested here}}
anatofuz
parents:
diff changeset
87 test_hd<H1D2>(t);
anatofuz
parents:
diff changeset
88 test_hd<H2D1>(t);
anatofuz
parents:
diff changeset
89 test_hd<H2D2>(t);
anatofuz
parents:
diff changeset
90 test_hd<H1D1D2>(t);
anatofuz
parents:
diff changeset
91 test_hd<H1H2D1>(t);
anatofuz
parents:
diff changeset
92 test_hd<H1H2D1>(t);
anatofuz
parents:
diff changeset
93 test_hd<H1H2D2>(t);
anatofuz
parents:
diff changeset
94 test_hd<H1H2D1D2>(t);
anatofuz
parents:
diff changeset
95 }
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
96
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
97 // This should produce no errors. Defaulted destructor should be treated as HD,
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
98 // which allows referencing host-only `operator delete` with a deferred
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
99 // diagnostics that would fire if we ever attempt to codegen it on device..
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
100 struct H {
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
101 virtual ~H() = default;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
102 static void operator delete(void *) {}
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
103 };
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
104 H h;