@@ -1774,8 +1774,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
1774
1774
// is an element of an array. This will determine whether we do
1775
1775
// MemberExprBases in some cases or not, AND determines how we initialize
1776
1776
// values.
1777
- bool IsArrayElement (FieldDecl *FD, QualType Ty) {
1778
- // TODO, better way to detect that we're in an array?
1777
+ bool IsArrayElement (const FieldDecl *FD, QualType Ty) const {
1779
1778
SemaRef.getASTContext ().hasSameType (FD->getType (), Ty);
1780
1779
return FD->getType () != Ty;
1781
1780
}
@@ -2075,7 +2074,6 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
2075
2074
CXXCastPath BasePath;
2076
2075
QualType DerivedTy (RD->getTypeForDecl (), 0 );
2077
2076
QualType BaseTy = BS.getType ();
2078
- // // TODO: Why is this here? Do we think this check could fail?
2079
2077
SemaRef.CheckDerivedToBaseConversion (DerivedTy, BaseTy, SourceLocation (),
2080
2078
SourceRange (), &BasePath,
2081
2079
/* IgnoreBaseAccess*/ true );
@@ -2178,12 +2176,30 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2178
2176
2179
2177
void addParam (const FieldDecl *FD, QualType ArgTy,
2180
2178
SYCLIntegrationHeader::kernel_param_kind_t Kind) {
2179
+ addParam (FD, ArgTy, Kind, IsArrayElement (FD, ArgTy));
2180
+ }
2181
+ void addParam (const FieldDecl *FD, QualType ArgTy,
2182
+ SYCLIntegrationHeader::kernel_param_kind_t Kind,
2183
+ bool IsArrayElem) {
2181
2184
uint64_t Size;
2182
2185
Size = SemaRef.getASTContext ().getTypeSizeInChars (ArgTy).getQuantity ();
2186
+ uint64_t Offset = CurOffset;
2187
+ if (!IsArrayElem)
2188
+ Offset += offsetOf (FD);
2183
2189
Header.addParamDesc (Kind, static_cast <unsigned >(Size),
2184
- static_cast <unsigned >(CurOffset + offsetOf (FD)));
2190
+ static_cast <unsigned >(Offset));
2191
+ }
2192
+
2193
+ // Returns 'true' if the thing we're visiting (Based on the FD/QualType pair)
2194
+ // is an element of an array. This will determine whether we do
2195
+ // MemberExprBases in some cases or not, AND determines how we initialize
2196
+ // values.
2197
+ bool IsArrayElement (const FieldDecl *FD, QualType Ty) const {
2198
+ SemaRef.getASTContext ().hasSameType (FD->getType (), Ty);
2199
+ return FD->getType () != Ty;
2185
2200
}
2186
2201
2202
+
2187
2203
public:
2188
2204
SyclKernelIntHeaderCreator (Sema &S, SYCLIntegrationHeader &H,
2189
2205
const CXXRecordDecl *KernelObj, QualType NameType,
@@ -2216,8 +2232,12 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2216
2232
int Dims = static_cast <int >(
2217
2233
AccTy->getTemplateArgs ()[1 ].getAsIntegral ().getExtValue ());
2218
2234
int Info = getAccessTarget (AccTy) | (Dims << 11 );
2235
+
2236
+ uint64_t Offset = CurOffset;
2237
+ if (!IsArrayElement (FD, FieldTy))
2238
+ Offset += offsetOf (FD);
2219
2239
Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
2220
- CurOffset + offsetOf (FD) );
2240
+ Offset );
2221
2241
return true ;
2222
2242
}
2223
2243
@@ -2231,7 +2251,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2231
2251
const ParmVarDecl *SamplerArg = InitMethod->getParamDecl (0 );
2232
2252
assert (SamplerArg && " sampler __init method must have sampler parameter" );
2233
2253
2234
- addParam (FD, SamplerArg->getType (), SYCLIntegrationHeader::kind_sampler);
2254
+ addParam (FD, SamplerArg->getType (), SYCLIntegrationHeader::kind_sampler,
2255
+ IsArrayElement (FD, FieldTy));
2235
2256
return true ;
2236
2257
}
2237
2258
@@ -2284,35 +2305,31 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2284
2305
return true ;
2285
2306
}
2286
2307
2287
- bool enterStream (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2308
+ bool enterStream (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2288
2309
++StructDepth;
2289
- // TODO: Is this right?! I think this only needs to be incremented when we
2290
- // aren't in an array, otherwise 'enterArray's base offsets should handle
2291
- // this right. Otherwise an array of structs is going to be in the middle
2292
- // of nowhere.
2293
- CurOffset += offsetOf (FD);
2310
+ if (!IsArrayElement (FD, Ty))
2311
+ CurOffset += offsetOf (FD);
2294
2312
return true ;
2295
2313
}
2296
2314
2297
- bool leaveStream (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2315
+ bool leaveStream (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2298
2316
--StructDepth;
2299
- CurOffset -= offsetOf (FD);
2317
+ if (!IsArrayElement (FD, Ty))
2318
+ CurOffset -= offsetOf (FD);
2300
2319
return true ;
2301
2320
}
2302
2321
2303
- bool enterStruct (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2322
+ bool enterStruct (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2304
2323
++StructDepth;
2305
- // TODO: Is this right?! I think this only needs to be incremented when we
2306
- // aren't in an array, otherwise 'enterArray's base offsets should handle
2307
- // this right. Otherwise an array of structs is going to be in the middle
2308
- // of nowhere.
2309
- CurOffset += offsetOf (FD);
2324
+ if (!IsArrayElement (FD, Ty))
2325
+ CurOffset += offsetOf (FD);
2310
2326
return true ;
2311
2327
}
2312
2328
2313
- bool leaveStruct (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2329
+ bool leaveStruct (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2314
2330
--StructDepth;
2315
- CurOffset -= offsetOf (FD);
2331
+ if (!IsArrayElement (FD, Ty))
2332
+ CurOffset -= offsetOf (FD);
2316
2333
return true ;
2317
2334
}
2318
2335
@@ -2328,8 +2345,12 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2328
2345
return true ;
2329
2346
}
2330
2347
2331
- bool enterArray (FieldDecl *, QualType, QualType) final {
2332
- ArrayBaseOffsets.push_back (CurOffset);
2348
+ bool enterArray (FieldDecl *FD, QualType ArrayTy, QualType) final {
2349
+ uint64_t Offset = CurOffset;
2350
+ if (!IsArrayElement (FD, ArrayTy))
2351
+ Offset += offsetOf (FD);
2352
+
2353
+ ArrayBaseOffsets.push_back (Offset);
2333
2354
return true ;
2334
2355
}
2335
2356
0 commit comments