Clang Project

clang_source_code/test/SemaCUDA/global-initializers-host.cu
1// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-linux-unknown -fsyntax-only -o - -verify
2
3#include "Inputs/cuda.h"
4
5// Check that we get an error if we try to call a __device__ function from a
6// module initializer.
7
8struct S {
9  __device__ S() {}
10  // expected-note@-1 {{'S' declared here}}
11};
12
13S s;
14// expected-error@-1 {{reference to __device__ function 'S' in global initializer}}
15
16struct T {
17  __host__ __device__ T() {}
18};
19T t;  // No error, this is OK.
20
21struct U {
22  __host__ U() {}
23  __device__ U(int) {}
24  // expected-note@-1 {{'U' declared here}}
25};
26U u(42);
27// expected-error@-1 {{reference to __device__ function 'U' in global initializer}}
28
29__device__ int device_fn() { return 42; }
30// expected-note@-1 {{'device_fn' declared here}}
31int n = device_fn();
32// expected-error@-1 {{reference to __device__ function 'device_fn' in global initializer}}
33