Skip to content

Commit 90ae330

Browse files
author
Erich Keane
committed
Correct behavior of integration header, now that enterField isn't here.
It sorta worked before this, just by chance, but it would have broken in a couple of other cases I can think of. This makes sure that the integration-header code is array-aware.
1 parent 03ad0d2 commit 90ae330

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,8 +1774,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
17741774
// is an element of an array. This will determine whether we do
17751775
// MemberExprBases in some cases or not, AND determines how we initialize
17761776
// 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 {
17791778
SemaRef.getASTContext().hasSameType(FD->getType(), Ty);
17801779
return FD->getType() != Ty;
17811780
}
@@ -2075,7 +2074,6 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
20752074
CXXCastPath BasePath;
20762075
QualType DerivedTy(RD->getTypeForDecl(), 0);
20772076
QualType BaseTy = BS.getType();
2078-
// // TODO: Why is this here? Do we think this check could fail?
20792077
SemaRef.CheckDerivedToBaseConversion(DerivedTy, BaseTy, SourceLocation(),
20802078
SourceRange(), &BasePath,
20812079
/*IgnoreBaseAccess*/ true);
@@ -2178,12 +2176,30 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
21782176

21792177
void addParam(const FieldDecl *FD, QualType ArgTy,
21802178
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) {
21812184
uint64_t Size;
21822185
Size = SemaRef.getASTContext().getTypeSizeInChars(ArgTy).getQuantity();
2186+
uint64_t Offset = CurOffset;
2187+
if (!IsArrayElem)
2188+
Offset += offsetOf(FD);
21832189
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;
21852200
}
21862201

2202+
21872203
public:
21882204
SyclKernelIntHeaderCreator(Sema &S, SYCLIntegrationHeader &H,
21892205
const CXXRecordDecl *KernelObj, QualType NameType,
@@ -2216,8 +2232,12 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
22162232
int Dims = static_cast<int>(
22172233
AccTy->getTemplateArgs()[1].getAsIntegral().getExtValue());
22182234
int Info = getAccessTarget(AccTy) | (Dims << 11);
2235+
2236+
uint64_t Offset = CurOffset;
2237+
if (!IsArrayElement(FD, FieldTy))
2238+
Offset += offsetOf(FD);
22192239
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info,
2220-
CurOffset + offsetOf(FD));
2240+
Offset);
22212241
return true;
22222242
}
22232243

@@ -2231,7 +2251,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
22312251
const ParmVarDecl *SamplerArg = InitMethod->getParamDecl(0);
22322252
assert(SamplerArg && "sampler __init method must have sampler parameter");
22332253

2234-
addParam(FD, SamplerArg->getType(), SYCLIntegrationHeader::kind_sampler);
2254+
addParam(FD, SamplerArg->getType(), SYCLIntegrationHeader::kind_sampler,
2255+
IsArrayElement(FD, FieldTy));
22352256
return true;
22362257
}
22372258

@@ -2284,35 +2305,31 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
22842305
return true;
22852306
}
22862307

2287-
bool enterStream(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2308+
bool enterStream(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
22882309
++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);
22942312
return true;
22952313
}
22962314

2297-
bool leaveStream(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2315+
bool leaveStream(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
22982316
--StructDepth;
2299-
CurOffset -= offsetOf(FD);
2317+
if (!IsArrayElement(FD, Ty))
2318+
CurOffset -= offsetOf(FD);
23002319
return true;
23012320
}
23022321

2303-
bool enterStruct(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2322+
bool enterStruct(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
23042323
++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);
23102326
return true;
23112327
}
23122328

2313-
bool leaveStruct(const CXXRecordDecl *, FieldDecl *FD, QualType) final {
2329+
bool leaveStruct(const CXXRecordDecl *, FieldDecl *FD, QualType Ty) final {
23142330
--StructDepth;
2315-
CurOffset -= offsetOf(FD);
2331+
if (!IsArrayElement(FD, Ty))
2332+
CurOffset -= offsetOf(FD);
23162333
return true;
23172334
}
23182335

@@ -2328,8 +2345,12 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
23282345
return true;
23292346
}
23302347

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);
23332354
return true;
23342355
}
23352356

0 commit comments

Comments
 (0)