Skip to content

Commit a6ee425

Browse files
author
Erich Keane
committed
Reapply Correct behavior of integration header, now that enterField isn't here.
This reverts commit 693ae2b. Fixed now :)
1 parent 693ae2b commit a6ee425

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,8 +1775,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
17751775
// MemberExprBases in some cases or not, AND determines how we initialize
17761776
// values.
17771777
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);
17801779
}
17811780

17821781
// Creates an initialized entity for a field/item. In the case where this is a
@@ -2164,8 +2163,10 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
21642163
int StructDepth = 0;
21652164

21662165
// 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;
21692170
}
21702171

21712172
int64_t offsetOf(const CXXRecordDecl *RD, const CXXRecordDecl *Base) const {
@@ -2176,10 +2177,23 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
21762177

21772178
void addParam(const FieldDecl *FD, QualType ArgTy,
21782179
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) {
21792185
uint64_t Size;
21802186
Size = SemaRef.getASTContext().getTypeSizeInChars(ArgTy).getQuantity();
21812187
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);
21832197
}
21842198

21852199
public:
@@ -2216,7 +2230,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
22162230
int Info = getAccessTarget(AccTy) | (Dims << 11);
22172231

22182232
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info,
2219-
CurOffset + offsetOf(FD));
2233+
CurOffset + offsetOf(FD, FieldTy));
22202234
return true;
22212235
}
22222236

@@ -2230,7 +2244,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
22302244
const ParmVarDecl *SamplerArg = InitMethod->getParamDecl(0);
22312245
assert(SamplerArg && "sampler __init method must have sampler parameter");
22322246

2233-
addParam(FD, SamplerArg->getType(), SYCLIntegrationHeader::kind_sampler);
2247+
addParam(FD, SamplerArg->getType(), SYCLIntegrationHeader::kind_sampler,
2248+
offsetOf(FD, FieldTy));
22342249
return true;
22352250
}
22362251

@@ -2283,35 +2298,27 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
22832298
return true;
22842299
}
22852300

2286-
bool enterStream(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2301+
bool enterStream(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
22872302
++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);
22932304
return true;
22942305
}
22952306

2296-
bool leaveStream(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2307+
bool leaveStream(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
22972308
--StructDepth;
2298-
CurOffset -= offsetOf(FD);
2309+
CurOffset -= offsetOf(FD, Ty);
22992310
return true;
23002311
}
23012312

2302-
bool enterStruct(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2313+
bool enterStruct(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
23032314
++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);
23092316
return true;
23102317
}
23112318

2312-
bool leaveStruct(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2319+
bool leaveStruct(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
23132320
--StructDepth;
2314-
CurOffset -= offsetOf(FD);
2321+
CurOffset -= offsetOf(FD, Ty);
23152322
return true;
23162323
}
23172324

@@ -2327,8 +2334,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
23272334
return true;
23282335
}
23292336

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));
23322339
return true;
23332340
}
23342341

@@ -2338,10 +2345,12 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
23382345
return true;
23392346
}
23402347

2341-
bool leaveArray(FieldDecl *, QualType, QualType) final {
2348+
bool leaveArray(FieldDecl *FD, QualType ArrayTy, QualType) final {
23422349
CurOffset = ArrayBaseOffsets.pop_back_val();
2350+
CurOffset -= offsetOf(FD, ArrayTy);
23432351
return true;
23442352
}
2353+
23452354
using SyclKernelFieldHandler::enterStruct;
23462355
using SyclKernelFieldHandler::handleSyclHalfType;
23472356
using SyclKernelFieldHandler::handleSyclSamplerType;

0 commit comments

Comments
 (0)