blob: 5aaff9759673cea09e6a7d3b13948f71c266afca [file] [log] [blame]
Justin Lebar3eaaf862016-01-13 01:07:35 +00001// Tests handling of CUDA attributes that are bad either because they're
2// applied to the wrong sort of thing, or because they're given in illegal
3// combinations.
4//
5// You should be able to run this file through nvcc for compatibility testing.
6//
Justin Lebarc66a1062016-01-20 00:26:57 +00007// RUN: %clang_cc1 -fsyntax-only -Wcuda-compat -verify -DEXPECT_INLINE_WARNING %s
8// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -Wcuda-compat -verify %s
Justin Lebar3eaaf862016-01-13 01:07:35 +00009
10#include "Inputs/cuda.h"
11
12// Try applying attributes to functions and variables. Some should generate
13// warnings; others not.
14__device__ int a1;
15__device__ void a2();
16__host__ int b1; // expected-warning {{attribute only applies to functions}}
17__host__ void b2();
18__constant__ int c1;
19__constant__ void c2(); // expected-warning {{attribute only applies to variables}}
20__shared__ int d1;
21__shared__ void d2(); // expected-warning {{attribute only applies to variables}}
22__global__ int e1; // expected-warning {{attribute only applies to functions}}
23__global__ void e2();
24
25// Try all pairs of attributes which can be present on a function or a
26// variable. Check both orderings of the attributes, as that can matter in
27// clang.
28__device__ __host__ void z1();
29__device__ __constant__ int z2;
30__device__ __shared__ int z3;
31__device__ __global__ void z4(); // expected-error {{attributes are not compatible}}
32// expected-note@-1 {{conflicting attribute is here}}
33
34__host__ __device__ void z5();
35__host__ __global__ void z6(); // expected-error {{attributes are not compatible}}
36// expected-note@-1 {{conflicting attribute is here}}
37
38__constant__ __device__ int z7;
39__constant__ __shared__ int z8; // expected-error {{attributes are not compatible}}
40// expected-note@-1 {{conflicting attribute is here}}
41
42__shared__ __device__ int z9;
43__shared__ __constant__ int z10; // expected-error {{attributes are not compatible}}
44// expected-note@-1 {{conflicting attribute is here}}
Justin Lebar10411012016-09-30 23:57:30 +000045__constant__ __shared__ int z10a; // expected-error {{attributes are not compatible}}
46// expected-note@-1 {{conflicting attribute is here}}
Justin Lebar3eaaf862016-01-13 01:07:35 +000047
48__global__ __device__ void z11(); // expected-error {{attributes are not compatible}}
49// expected-note@-1 {{conflicting attribute is here}}
50__global__ __host__ void z12(); // expected-error {{attributes are not compatible}}
51// expected-note@-1 {{conflicting attribute is here}}
Justin Lebarc66a1062016-01-20 00:26:57 +000052
53struct S {
54 __global__ void foo() {}; // expected-error {{must be a free function or static member function}}
55 __global__ static void bar(); // expected-warning {{kernel function 'bar' is a member function}}
56 // Although this is implicitly inline, we shouldn't warn.
57 __global__ static void baz() {}; // expected-warning {{kernel function 'baz' is a member function}}
58};
59
60__global__ static inline void foobar() {};
61#ifdef EXPECT_INLINE_WARNING
62// expected-warning@-2 {{ignored 'inline' attribute on kernel function 'foobar'}}
63#endif
Justin Lebare71b2fa2016-09-30 23:57:34 +000064
65__constant__ int global_constant;
66void host_fn() {
67 __constant__ int c; // expected-error {{__constant__ variables must be global}}
Justin Lebaraa370bd2016-10-13 18:45:13 +000068 __shared__ int s; // expected-error {{__shared__ local variables not allowed in __host__ functions}}
Justin Lebare71b2fa2016-09-30 23:57:34 +000069}
70__device__ void device_fn() {
71 __constant__ int c; // expected-error {{__constant__ variables must be global}}
72}