annotate clang/test/SemaCUDA/call-device-fn-from-host.cu @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children 0572611fdcc8
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 x86_64-unknown-linux -emit-llvm -o - \
anatofuz
parents:
diff changeset
2 // RUN: -verify -verify-ignore-unexpected=note
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 %s --std=c++11 -triple x86_64-unknown-linux -emit-llvm -o - \
anatofuz
parents:
diff changeset
4 // RUN: -verify -verify-ignore-unexpected=note -fopenmp
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // Note: This test won't work with -fsyntax-only, because some of these errors
anatofuz
parents:
diff changeset
7 // are emitted during codegen.
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #include "Inputs/cuda.h"
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 __device__ void device_fn() {}
anatofuz
parents:
diff changeset
12 // expected-note@-1 5 {{'device_fn' declared here}}
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 struct S {
anatofuz
parents:
diff changeset
15 __device__ S() {}
anatofuz
parents:
diff changeset
16 // expected-note@-1 2 {{'S' declared here}}
anatofuz
parents:
diff changeset
17 __device__ ~S() { device_fn(); }
anatofuz
parents:
diff changeset
18 // expected-note@-1 {{'~S' declared here}}
anatofuz
parents:
diff changeset
19 int x;
anatofuz
parents:
diff changeset
20 };
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 struct T {
anatofuz
parents:
diff changeset
23 __host__ __device__ void hd() { device_fn(); }
anatofuz
parents:
diff changeset
24 // expected-error@-1 {{reference to __device__ function 'device_fn' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 // No error; this is (implicitly) inline and is never called, so isn't
anatofuz
parents:
diff changeset
27 // codegen'ed.
anatofuz
parents:
diff changeset
28 __host__ __device__ void hd2() { device_fn(); }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 __host__ __device__ void hd3();
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 __device__ void d() {}
anatofuz
parents:
diff changeset
33 // expected-note@-1 {{'d' declared here}}
anatofuz
parents:
diff changeset
34 };
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 __host__ __device__ void T::hd3() {
anatofuz
parents:
diff changeset
37 device_fn();
anatofuz
parents:
diff changeset
38 // expected-error@-1 {{reference to __device__ function 'device_fn' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
39 }
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 template <typename T> __host__ __device__ void hd2() { device_fn(); }
anatofuz
parents:
diff changeset
42 // expected-error@-1 2 {{reference to __device__ function 'device_fn' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
43 void host_fn() { hd2<int>(); }
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 __host__ __device__ void hd() { device_fn(); }
anatofuz
parents:
diff changeset
46 // expected-error@-1 {{reference to __device__ function 'device_fn' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 // No error because this is never instantiated.
anatofuz
parents:
diff changeset
49 template <typename T> __host__ __device__ void hd3() { device_fn(); }
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 __host__ __device__ void local_var() {
anatofuz
parents:
diff changeset
52 S s;
anatofuz
parents:
diff changeset
53 // expected-error@-1 {{reference to __device__ function 'S' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
54 }
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 __host__ __device__ void placement_new(char *ptr) {
anatofuz
parents:
diff changeset
57 ::new(ptr) S();
anatofuz
parents:
diff changeset
58 // expected-error@-1 {{reference to __device__ function 'S' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
59 }
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 __host__ __device__ void explicit_destructor(S *s) {
anatofuz
parents:
diff changeset
62 s->~S();
anatofuz
parents:
diff changeset
63 // expected-error@-1 {{reference to __device__ function '~S' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
64 }
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 __host__ __device__ void hd_member_fn() {
anatofuz
parents:
diff changeset
67 T t;
anatofuz
parents:
diff changeset
68 // Necessary to trigger an error on T::hd. It's (implicitly) inline, so
anatofuz
parents:
diff changeset
69 // isn't codegen'ed until we call it.
anatofuz
parents:
diff changeset
70 t.hd();
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 __host__ __device__ void h_member_fn() {
anatofuz
parents:
diff changeset
74 T t;
anatofuz
parents:
diff changeset
75 t.d();
anatofuz
parents:
diff changeset
76 // expected-error@-1 {{reference to __device__ function 'd' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
77 }
anatofuz
parents:
diff changeset
78
anatofuz
parents:
diff changeset
79 __host__ __device__ void fn_ptr() {
anatofuz
parents:
diff changeset
80 auto* ptr = &device_fn;
anatofuz
parents:
diff changeset
81 // expected-error@-1 {{reference to __device__ function 'device_fn' in __host__ __device__ function}}
anatofuz
parents:
diff changeset
82 }
anatofuz
parents:
diff changeset
83
anatofuz
parents:
diff changeset
84 template <typename T>
anatofuz
parents:
diff changeset
85 __host__ __device__ void fn_ptr_template() {
anatofuz
parents:
diff changeset
86 auto* ptr = &device_fn; // Not an error because the template isn't instantiated.
anatofuz
parents:
diff changeset
87 }
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 // Launching a kernel from a host function does not result in code generation
anatofuz
parents:
diff changeset
90 // for it, so calling HD function which calls a D function should not trigger
anatofuz
parents:
diff changeset
91 // errors.
anatofuz
parents:
diff changeset
92 static __host__ __device__ void hd_func() { device_fn(); }
anatofuz
parents:
diff changeset
93 __global__ void kernel() { hd_func(); }
anatofuz
parents:
diff changeset
94 void host_func(void) { kernel<<<1, 1>>>(); }
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 // Should allow host function call kernel template with device function argument.
anatofuz
parents:
diff changeset
97 __device__ void f();
anatofuz
parents:
diff changeset
98 template<void(*F)()> __global__ void t() { F(); }
anatofuz
parents:
diff changeset
99 __host__ void g() { t<f><<<1,1>>>(); }