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 constexpr var initialized with address of a const var.
11 // Both are promoted to device side.
17 static constexpr const int *p = &a;
18 __device__ static constexpr const int *const p2 = &a;
21 // Const variable 'a' is treated as __constant__ on device side,
22 // therefore its address can be used as initializer for another
27 constexpr const int *x = B::p;
28 constexpr const int *z = B::p2;
32 // Test constexpr var initialized with address of a non-cost var.
33 // Neither is promoted to device side.
37 // expected-note@-1{{host variable declared here}}
40 static constexpr int *const p = &a;
41 // expected-note@-1{{const variable cannot be emitted on device side due to dynamic initialization}}
46 // expected-error@-1{{reference to __host__ variable 'a' in __device__ function}}
47 const int *const *x = &B::p;
48 // expected-error@-1{{reference to __host__ variable 'p' in __device__ function}}
49 // ToDo: use of non-promotable constexpr variable in device compilation should be treated as
50 // ODR-use and diagnosed.
51 const int *const z = B::p;
55 // Test constexpr device var initialized with address of a non-const host var, __shared var,
56 // __managed__ var, __device__ var, __constant__ var, texture var, surface var.
59 struct textureReference {
68 template <typename T, int dim = 1, enum ReadMode mode = ElementType>
69 struct __attribute__((device_builtin_texture_type)) texture : public textureReference {
72 struct surfaceReference {
76 template <typename T, int dim = 1>
77 struct __attribute__((device_builtin_surface_type)) surface : public surfaceReference {
80 // Partial specialization over `void`.
82 struct __attribute__((device_builtin_surface_type)) surface<void, dim> : public surfaceReference {
85 texture<float, 2, ElementType> tex;
86 surface<void, 2> surf;
90 __managed__ int c = 1;
92 __constant__ int e = 1;
94 __device__ static constexpr int *const p1 = &a;
95 // expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
96 __device__ static constexpr int *const p2 = &b;
97 // expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
98 __device__ static constexpr int *const p3 = &c;
99 // expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
100 __device__ static constexpr int *const p4 = &d;
101 __device__ static constexpr int *const p5 = &e;
102 __device__ static constexpr texture<float, 2, ElementType> *const p6 = &tex;
103 __device__ static constexpr surface<void, 2> *const p7 = &surf;