summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCUDA/bad-calls-on-same-line.cu
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/SemaCUDA/bad-calls-on-same-line.cu')
-rw-r--r--clang/test/SemaCUDA/bad-calls-on-same-line.cu39
1 files changed, 39 insertions, 0 deletions
diff --git a/clang/test/SemaCUDA/bad-calls-on-same-line.cu b/clang/test/SemaCUDA/bad-calls-on-same-line.cu
new file mode 100644
index 00000000000..e91baff5d28
--- /dev/null
+++ b/clang/test/SemaCUDA/bad-calls-on-same-line.cu
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// The hd function template is instantiated three times.
+//
+// Two of those instantiations call a device function, which is an error when
+// compiling for host. Clang should report both errors.
+
+#include "Inputs/cuda.h"
+
+template <typename T>
+struct Selector {};
+
+template <>
+struct Selector<int> {
+ __host__ void f() {}
+};
+
+template <>
+struct Selector<float> {
+ __device__ void f() {} // expected-note {{declared here}}
+};
+
+template <>
+struct Selector<double> {
+ __device__ void f() {} // expected-note {{declared here}}
+};
+
+template <typename T>
+inline __host__ __device__ void hd() {
+ Selector<T>().f();
+ // expected-error@-1 {{reference to __device__ function}}
+ // expected-error@-2 {{reference to __device__ function}}
+}
+
+void host_fn() {
+ hd<int>();
+ hd<double>(); // expected-note {{function template specialization 'hd<double>'}}
+ hd<float>(); // expected-note {{function template specialization 'hd<float>'}}
+}
OpenPOWER on IntegriCloud