1 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
2 // RUN: -fsyntax-only -verify
3 // RUN: %clang_cc1 -triple x86_64 -x hip %s \
4 // RUN: -fsyntax-only -verify=host
8 #include "Inputs/cuda.h"
10 // Test const var initialized with address of a const var.
11 // Both are promoted to device side.
17 static const int *const p;
18 __device__ static const int *const p2;
20 const int *const B::p = &a;
21 // Const variable 'a' is treated as __constant__ on device side,
22 // therefore its address can be used as initializer for another
24 __device__ const int *const B::p2 = &a;
33 // Test const var initialized with address of a non-cost var.
34 // Neither is promoted to device side.
38 // expected-note@-1{{host variable declared here}}
44 // expected-note@-1{{const variable cannot be emitted on device side due to dynamic initialization}}
48 // expected-error@-1{{reference to __host__ variable 'a' in __device__ function}}
50 // expected-error@-1{{reference to __host__ variable 'p' in __device__ function}}
54 // Test device var initialized with address of a non-const host var, __shared var,
55 // __managed__ var, __device__ var, __constant__ var, texture var, surface var.
58 struct textureReference {
67 template <typename T, int dim = 1, enum ReadMode mode = ElementType>
68 struct __attribute__((device_builtin_texture_type)) texture : public textureReference {
71 struct surfaceReference {
75 template <typename T, int dim = 1>
76 struct __attribute__((device_builtin_surface_type)) surface : public surfaceReference {
79 // Partial specialization over `void`.
81 struct __attribute__((device_builtin_surface_type)) surface<void, dim> : public surfaceReference {
84 texture<float, 2, ElementType> tex;
85 surface<void, 2> surf;
89 __managed__ int c = 1;
91 __constant__ int e = 1;
93 __device__ static int *const p1;
94 __device__ static int *const p2;
95 __device__ static int *const p3;
96 __device__ static int *const p4;
97 __device__ static int *const p5;
98 __device__ static texture<float, 2, ElementType> *const p6;
99 __device__ static surface<void, 2> *const p7;
101 __device__ int *const B::p1 = &a;
102 // expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
103 __device__ int *const B::p2 = &b;
104 // expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
105 __device__ int *const B::p3 = &c;
106 // expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
107 __device__ int *const B::p4 = &d;
108 __device__ int *const B::p5 = &e;
109 __device__ texture<float, 2, ElementType> *const B::p6 = &tex;
110 __device__ surface<void, 2> *const B::p7 = &surf;