xref: /aosp_15_r20/external/clang/test/CodeGenCUDA/Inputs/cuda-initializers.h (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // CUDA struct types with interesting initialization properties.
2*67e74705SXin Li // Keep in sync with ../SemaCUDA/Inputs/cuda-initializers.h.
3*67e74705SXin Li 
4*67e74705SXin Li // Base classes with different initializer variants.
5*67e74705SXin Li 
6*67e74705SXin Li // trivial constructor -- allowed
7*67e74705SXin Li struct T {
8*67e74705SXin Li   int t;
9*67e74705SXin Li };
10*67e74705SXin Li 
11*67e74705SXin Li // empty constructor
12*67e74705SXin Li struct EC {
13*67e74705SXin Li   int ec;
ECEC14*67e74705SXin Li   __device__ EC() {}     // -- allowed
ECEC15*67e74705SXin Li   __device__ EC(int) {}  // -- not allowed
16*67e74705SXin Li };
17*67e74705SXin Li 
18*67e74705SXin Li // empty destructor
19*67e74705SXin Li struct ED {
~EDED20*67e74705SXin Li   __device__ ~ED() {}     // -- allowed
21*67e74705SXin Li };
22*67e74705SXin Li 
23*67e74705SXin Li struct ECD {
ECDECD24*67e74705SXin Li   __device__ ECD() {}     // -- allowed
~ECDECD25*67e74705SXin Li   __device__ ~ECD() {}    // -- allowed
26*67e74705SXin Li };
27*67e74705SXin Li 
28*67e74705SXin Li // empty templated constructor -- allowed with no arguments
29*67e74705SXin Li struct ETC {
ETCETC30*67e74705SXin Li   template <typename... T> __device__ ETC(T...) {}
31*67e74705SXin Li };
32*67e74705SXin Li 
33*67e74705SXin Li // undefined constructor -- not allowed
34*67e74705SXin Li struct UC {
35*67e74705SXin Li   int uc;
36*67e74705SXin Li   __device__ UC();
37*67e74705SXin Li };
38*67e74705SXin Li 
39*67e74705SXin Li // undefined destructor -- not allowed
40*67e74705SXin Li struct UD {
41*67e74705SXin Li   int ud;
42*67e74705SXin Li   __device__ ~UD();
43*67e74705SXin Li };
44*67e74705SXin Li 
45*67e74705SXin Li // empty constructor w/ initializer list -- not allowed
46*67e74705SXin Li struct ECI {
47*67e74705SXin Li   int eci;
ECIECI48*67e74705SXin Li   __device__ ECI() : eci(1) {}
49*67e74705SXin Li };
50*67e74705SXin Li 
51*67e74705SXin Li // non-empty constructor -- not allowed
52*67e74705SXin Li struct NEC {
53*67e74705SXin Li   int nec;
NECNEC54*67e74705SXin Li   __device__ NEC() { nec = 1; }
55*67e74705SXin Li };
56*67e74705SXin Li 
57*67e74705SXin Li // non-empty destructor -- not allowed
58*67e74705SXin Li struct NED {
59*67e74705SXin Li   int ned;
~NEDNED60*67e74705SXin Li   __device__ ~NED() { ned = 1; }
61*67e74705SXin Li };
62*67e74705SXin Li 
63*67e74705SXin Li // no-constructor,  virtual method -- not allowed
64*67e74705SXin Li struct NCV {
65*67e74705SXin Li   int ncv;
vmNCV66*67e74705SXin Li   __device__ virtual void vm() {}
67*67e74705SXin Li };
68*67e74705SXin Li 
69*67e74705SXin Li // virtual destructor -- not allowed.
70*67e74705SXin Li struct VD {
~VDVD71*67e74705SXin Li   __device__ virtual ~VD() {}
72*67e74705SXin Li };
73*67e74705SXin Li 
74*67e74705SXin Li // dynamic in-class field initializer -- not allowed
75*67e74705SXin Li __device__ int f();
76*67e74705SXin Li struct NCF {
77*67e74705SXin Li   int ncf = f();
78*67e74705SXin Li };
79*67e74705SXin Li 
80*67e74705SXin Li // static in-class field initializer.  NVCC does not allow it, but
81*67e74705SXin Li // clang generates static initializer for this, so we'll accept it.
82*67e74705SXin Li // We still can't use it on __shared__ vars as they don't allow *any*
83*67e74705SXin Li // initializers.
84*67e74705SXin Li struct NCFS {
85*67e74705SXin Li   int ncfs = 3;
86*67e74705SXin Li };
87*67e74705SXin Li 
88*67e74705SXin Li // undefined templated constructor -- not allowed
89*67e74705SXin Li struct UTC {
90*67e74705SXin Li   template <typename... T> __device__ UTC(T...);
91*67e74705SXin Li };
92*67e74705SXin Li 
93*67e74705SXin Li // non-empty templated constructor -- not allowed
94*67e74705SXin Li struct NETC {
95*67e74705SXin Li   int netc;
NETCNETC96*67e74705SXin Li   template <typename... T> __device__ NETC(T...) { netc = 1; }
97*67e74705SXin Li };
98*67e74705SXin Li 
99*67e74705SXin Li // Regular base class -- allowed
100*67e74705SXin Li struct T_B_T : T {};
101*67e74705SXin Li 
102*67e74705SXin Li // Incapsulated object of allowed class -- allowed
103*67e74705SXin Li struct T_F_T {
104*67e74705SXin Li   T t;
105*67e74705SXin Li };
106*67e74705SXin Li 
107*67e74705SXin Li // array of allowed objects -- allowed
108*67e74705SXin Li struct T_FA_T {
109*67e74705SXin Li   T t[2];
110*67e74705SXin Li };
111*67e74705SXin Li 
112*67e74705SXin Li 
113*67e74705SXin Li // Calling empty base class initializer is OK
114*67e74705SXin Li struct EC_I_EC : EC {
EC_I_ECEC_I_EC115*67e74705SXin Li   __device__ EC_I_EC() : EC() {}
116*67e74705SXin Li };
117*67e74705SXin Li 
118*67e74705SXin Li // .. though passing arguments is not allowed.
119*67e74705SXin Li struct EC_I_EC1 : EC {
EC_I_EC1EC_I_EC1120*67e74705SXin Li   __device__ EC_I_EC1() : EC(1) {}
121*67e74705SXin Li };
122*67e74705SXin Li 
123*67e74705SXin Li // Virtual base class -- not allowed
124*67e74705SXin Li struct T_V_T : virtual T {};
125*67e74705SXin Li 
126*67e74705SXin Li // Inherited from or incapsulated class with non-empty constructor --
127*67e74705SXin Li // not allowed
128*67e74705SXin Li struct T_B_NEC : NEC {};
129*67e74705SXin Li struct T_F_NEC {
130*67e74705SXin Li   NEC nec;
131*67e74705SXin Li };
132*67e74705SXin Li struct T_FA_NEC {
133*67e74705SXin Li   NEC nec[2];
134*67e74705SXin Li };
135*67e74705SXin Li 
136*67e74705SXin Li 
137*67e74705SXin Li // Inherited from or incapsulated class with non-empty desstructor --
138*67e74705SXin Li // not allowed
139*67e74705SXin Li struct T_B_NED : NED {};
140*67e74705SXin Li struct T_F_NED {
141*67e74705SXin Li   NED ned;
142*67e74705SXin Li };
143*67e74705SXin Li struct T_FA_NED {
144*67e74705SXin Li   NED ned[2];
145*67e74705SXin Li };
146