annotate clang/test/SemaCUDA/host-device-constexpr.cu @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs %s \
anatofuz
parents:
diff changeset
3 // RUN: -fcuda-is-device
anatofuz
parents:
diff changeset
4 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs \
anatofuz
parents:
diff changeset
5 // RUN: -fopenmp %s
anatofuz
parents:
diff changeset
6 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs \
anatofuz
parents:
diff changeset
7 // RUN: -fopenmp %s -fcuda-is-device
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #include "Inputs/cuda.h"
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 // Declares one function and pulls it into namespace ns:
anatofuz
parents:
diff changeset
12 //
anatofuz
parents:
diff changeset
13 // __device__ int OverloadMe();
anatofuz
parents:
diff changeset
14 // namespace ns { using ::OverloadMe; }
anatofuz
parents:
diff changeset
15 //
anatofuz
parents:
diff changeset
16 // Clang cares that this is done in a system header.
anatofuz
parents:
diff changeset
17 #include <overload.h>
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 // Opaque type used to determine which overload we're invoking.
anatofuz
parents:
diff changeset
20 struct HostReturnTy {};
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 // These shouldn't become host+device because they already have attributes.
anatofuz
parents:
diff changeset
23 __host__ constexpr int HostOnly() { return 0; }
anatofuz
parents:
diff changeset
24 // expected-note@-1 0+ {{not viable}}
anatofuz
parents:
diff changeset
25 __device__ constexpr int DeviceOnly() { return 0; }
anatofuz
parents:
diff changeset
26 // expected-note@-1 0+ {{not viable}}
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 constexpr int HostDevice() { return 0; }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 // This should be a host-only function, because there's a previous __device__
anatofuz
parents:
diff changeset
31 // overload in <overload.h>.
anatofuz
parents:
diff changeset
32 constexpr HostReturnTy OverloadMe() { return HostReturnTy(); }
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 namespace ns {
anatofuz
parents:
diff changeset
35 // The "using" statement in overload.h should prevent OverloadMe from being
anatofuz
parents:
diff changeset
36 // implicitly host+device.
anatofuz
parents:
diff changeset
37 constexpr HostReturnTy OverloadMe() { return HostReturnTy(); }
anatofuz
parents:
diff changeset
38 } // namespace ns
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 // This is an error, because NonSysHdrOverload was not defined in a system
anatofuz
parents:
diff changeset
41 // header.
anatofuz
parents:
diff changeset
42 __device__ int NonSysHdrOverload() { return 0; }
anatofuz
parents:
diff changeset
43 // expected-note@-1 {{conflicting __device__ function declared here}}
anatofuz
parents:
diff changeset
44 constexpr int NonSysHdrOverload() { return 0; }
anatofuz
parents:
diff changeset
45 // expected-error@-1 {{constexpr function 'NonSysHdrOverload' without __host__ or __device__ attributes}}
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 // Variadic device functions are not allowed, so this is just treated as
anatofuz
parents:
diff changeset
48 // host-only.
anatofuz
parents:
diff changeset
49 constexpr void Variadic(const char*, ...);
anatofuz
parents:
diff changeset
50 // expected-note@-1 {{call to __host__ function from __device__ function}}
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 __host__ void HostFn() {
anatofuz
parents:
diff changeset
53 HostOnly();
anatofuz
parents:
diff changeset
54 DeviceOnly(); // expected-error {{no matching function}}
anatofuz
parents:
diff changeset
55 HostReturnTy x = OverloadMe();
anatofuz
parents:
diff changeset
56 HostReturnTy y = ns::OverloadMe();
anatofuz
parents:
diff changeset
57 Variadic("abc", 42);
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 __device__ void DeviceFn() {
anatofuz
parents:
diff changeset
61 HostOnly(); // expected-error {{no matching function}}
anatofuz
parents:
diff changeset
62 DeviceOnly();
anatofuz
parents:
diff changeset
63 int x = OverloadMe();
anatofuz
parents:
diff changeset
64 int y = ns::OverloadMe();
anatofuz
parents:
diff changeset
65 Variadic("abc", 42); // expected-error {{no matching function}}
anatofuz
parents:
diff changeset
66 }
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 __host__ __device__ void HostDeviceFn() {
anatofuz
parents:
diff changeset
69 #ifdef __CUDA_ARCH__
anatofuz
parents:
diff changeset
70 int y = OverloadMe();
anatofuz
parents:
diff changeset
71 #else
anatofuz
parents:
diff changeset
72 constexpr HostReturnTy y = OverloadMe();
anatofuz
parents:
diff changeset
73 #endif
anatofuz
parents:
diff changeset
74 }