@@ -1775,8 +1775,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
1775
1775
// MemberExprBases in some cases or not, AND determines how we initialize
1776
1776
// values.
1777
1777
bool IsArrayElement (const FieldDecl *FD, QualType Ty) const {
1778
- SemaRef.getASTContext ().hasSameType (FD->getType (), Ty);
1779
- return FD->getType () != Ty;
1778
+ return !SemaRef.getASTContext ().hasSameType (FD->getType (), Ty);
1780
1779
}
1781
1780
1782
1781
// Creates an initialized entity for a field/item. In the case where this is a
@@ -2164,8 +2163,10 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2164
2163
int StructDepth = 0 ;
2165
2164
2166
2165
// A series of functions to calculate the change in offset based on the type.
2167
- int64_t offsetOf (const FieldDecl *FD) const {
2168
- return SemaRef.getASTContext ().getFieldOffset (FD) / 8 ;
2166
+ int64_t offsetOf (const FieldDecl *FD, QualType ArgTy) const {
2167
+ return IsArrayElement (FD, ArgTy)
2168
+ ? 0
2169
+ : SemaRef.getASTContext ().getFieldOffset (FD) / 8 ;
2169
2170
}
2170
2171
2171
2172
int64_t offsetOf (const CXXRecordDecl *RD, const CXXRecordDecl *Base) const {
@@ -2176,10 +2177,23 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2176
2177
2177
2178
void addParam (const FieldDecl *FD, QualType ArgTy,
2178
2179
SYCLIntegrationHeader::kernel_param_kind_t Kind) {
2180
+ addParam (FD, ArgTy, Kind, offsetOf (FD, ArgTy));
2181
+ }
2182
+ void addParam (const FieldDecl *FD, QualType ArgTy,
2183
+ SYCLIntegrationHeader::kernel_param_kind_t Kind,
2184
+ uint64_t OffsetAdj) {
2179
2185
uint64_t Size;
2180
2186
Size = SemaRef.getASTContext ().getTypeSizeInChars (ArgTy).getQuantity ();
2181
2187
Header.addParamDesc (Kind, static_cast <unsigned >(Size),
2182
- static_cast <unsigned >(CurOffset + offsetOf (FD)));
2188
+ static_cast <unsigned >(CurOffset + OffsetAdj));
2189
+ }
2190
+
2191
+ // Returns 'true' if the thing we're visiting (Based on the FD/QualType pair)
2192
+ // is an element of an array. This will determine whether we do
2193
+ // MemberExprBases in some cases or not, AND determines how we initialize
2194
+ // values.
2195
+ bool IsArrayElement (const FieldDecl *FD, QualType Ty) const {
2196
+ return !SemaRef.getASTContext ().hasSameType (FD->getType (), Ty);
2183
2197
}
2184
2198
2185
2199
public:
@@ -2216,7 +2230,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2216
2230
int Info = getAccessTarget (AccTy) | (Dims << 11 );
2217
2231
2218
2232
Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
2219
- CurOffset + offsetOf (FD));
2233
+ CurOffset + offsetOf (FD, FieldTy ));
2220
2234
return true ;
2221
2235
}
2222
2236
@@ -2230,7 +2244,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2230
2244
const ParmVarDecl *SamplerArg = InitMethod->getParamDecl (0 );
2231
2245
assert (SamplerArg && " sampler __init method must have sampler parameter" );
2232
2246
2233
- addParam (FD, SamplerArg->getType (), SYCLIntegrationHeader::kind_sampler);
2247
+ addParam (FD, SamplerArg->getType (), SYCLIntegrationHeader::kind_sampler,
2248
+ offsetOf (FD, FieldTy));
2234
2249
return true ;
2235
2250
}
2236
2251
@@ -2283,35 +2298,27 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2283
2298
return true ;
2284
2299
}
2285
2300
2286
- bool enterStream (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2301
+ bool enterStream (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2287
2302
++StructDepth;
2288
- // TODO: Is this right?! I think this only needs to be incremented when we
2289
- // aren't in an array, otherwise 'enterArray's base offsets should handle
2290
- // this right. Otherwise an array of structs is going to be in the middle
2291
- // of nowhere.
2292
- CurOffset += offsetOf (FD);
2303
+ CurOffset += offsetOf (FD, Ty);
2293
2304
return true ;
2294
2305
}
2295
2306
2296
- bool leaveStream (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2307
+ bool leaveStream (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2297
2308
--StructDepth;
2298
- CurOffset -= offsetOf (FD);
2309
+ CurOffset -= offsetOf (FD, Ty );
2299
2310
return true ;
2300
2311
}
2301
2312
2302
- bool enterStruct (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2313
+ bool enterStruct (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2303
2314
++StructDepth;
2304
- // TODO: Is this right?! I think this only needs to be incremented when we
2305
- // aren't in an array, otherwise 'enterArray's base offsets should handle
2306
- // this right. Otherwise an array of structs is going to be in the middle
2307
- // of nowhere.
2308
- CurOffset += offsetOf (FD);
2315
+ CurOffset += offsetOf (FD, Ty);
2309
2316
return true ;
2310
2317
}
2311
2318
2312
- bool leaveStruct (const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2319
+ bool leaveStruct (const CXXRecordDecl *, FieldDecl *FD, QualType Ty ) final {
2313
2320
--StructDepth;
2314
- CurOffset -= offsetOf (FD);
2321
+ CurOffset -= offsetOf (FD, Ty );
2315
2322
return true ;
2316
2323
}
2317
2324
@@ -2327,8 +2334,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2327
2334
return true ;
2328
2335
}
2329
2336
2330
- bool enterArray (FieldDecl *, QualType, QualType) final {
2331
- ArrayBaseOffsets.push_back (CurOffset);
2337
+ bool enterArray (FieldDecl *FD , QualType ArrayTy , QualType) final {
2338
+ ArrayBaseOffsets.push_back (CurOffset + offsetOf (FD, ArrayTy) );
2332
2339
return true ;
2333
2340
}
2334
2341
@@ -2338,10 +2345,12 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
2338
2345
return true ;
2339
2346
}
2340
2347
2341
- bool leaveArray (FieldDecl *, QualType, QualType) final {
2348
+ bool leaveArray (FieldDecl *FD , QualType ArrayTy , QualType) final {
2342
2349
CurOffset = ArrayBaseOffsets.pop_back_val ();
2350
+ CurOffset -= offsetOf (FD, ArrayTy);
2343
2351
return true ;
2344
2352
}
2353
+
2345
2354
using SyclKernelFieldHandler::enterStruct;
2346
2355
using SyclKernelFieldHandler::handleSyclHalfType;
2347
2356
using SyclKernelFieldHandler::handleSyclSamplerType;
0 commit comments