Skip to content

Commit c4da2ce

Browse files
committed
Remove const casts
Signed-off-by: Mariya Podchishchaeva <[email protected]>
1 parent d642fb9 commit c4da2ce

File tree

1 file changed

+76
-24
lines changed

1 file changed

+76
-24
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,25 +1144,78 @@ template <typename Derived> class SyclKernelFieldHandler {
11441144
// should be still working.
11451145

11461146
// Accessor can be a base class or a field decl, so both must be handled.
1147-
virtual void handleSyclAccessorType(const CXXBaseSpecifier &, QualType) {}
1148-
virtual void handleSyclAccessorType(const FieldDecl *, QualType) {}
1149-
virtual void handleSyclSamplerType(const FieldDecl *, QualType) {}
1150-
virtual void handleSyclSpecConstantType(const FieldDecl *, QualType) {}
1151-
virtual void handleSyclStreamType(const CXXBaseSpecifier &, QualType) {}
1152-
virtual void handleSyclStreamType(const FieldDecl *, QualType) {}
1153-
virtual void handleStructType(const FieldDecl *, QualType) {}
1154-
virtual void handleReferenceType(const FieldDecl *, QualType) {}
1155-
virtual void handlePointerType(const FieldDecl *, QualType) {}
1156-
virtual void handleArrayType(const FieldDecl *, QualType) {}
1157-
virtual void handleScalarType(const FieldDecl *, QualType) {}
1147+
virtual void handleSyclAccessorType(CXXBaseSpecifier &, QualType) {}
1148+
virtual void handleSyclAccessorType(FieldDecl *, QualType) {}
1149+
virtual void handleSyclSamplerType(FieldDecl *, QualType) {}
1150+
virtual void handleSyclSpecConstantType(FieldDecl *, QualType) {}
1151+
virtual void handleSyclStreamType(CXXBaseSpecifier &, QualType) {}
1152+
virtual void handleSyclStreamType(FieldDecl *, QualType) {}
1153+
virtual void handleStructType(FieldDecl *, QualType) {}
1154+
virtual void handleReferenceType(FieldDecl *, QualType) {}
1155+
virtual void handlePointerType(FieldDecl *, QualType) {}
1156+
virtual void handleArrayType(FieldDecl *, QualType) {}
1157+
virtual void handleScalarType(FieldDecl *, QualType) {}
11581158
// Most handlers shouldn't be handling this, just the field checker.
1159-
virtual void handleOtherType(const FieldDecl *, QualType) {}
1159+
virtual void handleOtherType(FieldDecl *, QualType) {}
1160+
1161+
// TODO: fix warnings from derived classes
1162+
virtual void handleSyclAccessorType(const CXXBaseSpecifier &BS, QualType Ty) {
1163+
static_cast<Derived *>(this)->handleSyclAccessorType(
1164+
const_cast<CXXBaseSpecifier &>(BS), Ty);
1165+
}
1166+
virtual void handleSyclAccessorType(const FieldDecl *FD, QualType Ty) {
1167+
static_cast<Derived *>(this)->handleSyclAccessorType(
1168+
const_cast<FieldDecl *>(FD), Ty);
1169+
}
1170+
virtual void handleSyclStreamType(const CXXBaseSpecifier &BS, QualType Ty) {
1171+
static_cast<Derived *>(this)->handleSyclStreamType(
1172+
const_cast<CXXBaseSpecifier &>(BS), Ty);
1173+
}
1174+
virtual void handleSyclStreamType(const FieldDecl *FD, QualType Ty) {
1175+
static_cast<Derived *>(this)->handleSyclStreamType(
1176+
const_cast<FieldDecl *>(FD), Ty);
1177+
}
1178+
virtual void handleSyclSamplerType(const FieldDecl *FD, QualType Ty) {
1179+
static_cast<Derived *>(this)->handleSyclSamplerType(
1180+
const_cast<FieldDecl *>(FD), Ty);
1181+
}
1182+
virtual void handleSyclSpecConstantType(const FieldDecl *FD, QualType Ty) {
1183+
static_cast<Derived *>(this)->handleSyclSpecConstantType(
1184+
const_cast<FieldDecl *>(FD), Ty);
1185+
}
1186+
virtual void handleStructType(const FieldDecl *FD, QualType Ty) {
1187+
static_cast<Derived *>(this)->handleStructType(
1188+
const_cast<FieldDecl *>(FD), Ty);
1189+
}
1190+
virtual void handleReferenceType(const FieldDecl *FD, QualType Ty) {
1191+
static_cast<Derived *>(this)->handleReferenceType(
1192+
const_cast<FieldDecl *>(FD), Ty);
1193+
}
1194+
virtual void handlePointerType(const FieldDecl *FD, QualType Ty) {
1195+
static_cast<Derived *>(this)->handlePointerType(
1196+
const_cast<FieldDecl *>(FD), Ty);
1197+
}
1198+
virtual void handleArrayType(const FieldDecl *FD, QualType Ty) {
1199+
static_cast<Derived *>(this)->handleArrayType(
1200+
const_cast<FieldDecl *>(FD), Ty);
1201+
}
1202+
virtual void handleScalarType(const FieldDecl *FD, QualType Ty) {
1203+
static_cast<Derived *>(this)->handleScalarType(
1204+
const_cast<FieldDecl *>(FD), Ty);
1205+
}
1206+
virtual void handleOtherType(const FieldDecl *FD, QualType Ty) {
1207+
static_cast<Derived *>(this)->handleOtherType(
1208+
const_cast<FieldDecl *>(FD), Ty);
1209+
}
11601210

11611211
// The following are only used for keeping track of where we are in the base
11621212
// class/field graph. Int Headers use this to calculate offset, most others
11631213
// don't have a need for these.
1214+
virtual void enterStruct(const CXXRecordDecl *, FieldDecl *) {}
11641215

1165-
virtual void enterStruct(const CXXRecordDecl *, const FieldDecl *) {}
1216+
virtual void enterStruct(const CXXRecordDecl *RD, const FieldDecl *FD) {
1217+
static_cast<Derived *>(this)->enterStruct(RD, const_cast<FieldDecl *>(FD));
1218+
}
11661219
virtual void leaveStruct(const CXXRecordDecl *, const FieldDecl *) {}
11671220
virtual void enterStruct(const CXXRecordDecl *, const CXXBaseSpecifier &) {}
11681221
virtual void leaveStruct(const CXXRecordDecl *, const CXXBaseSpecifier &) {}
@@ -1521,13 +1574,13 @@ class SyclKernelBodyCreator
15211574
DeclCreator.setBody(KernelBody);
15221575
}
15231576

1524-
void handleSyclAccessorType(const FieldDecl *FD, QualType Ty) final {
1577+
void handleSyclAccessorType(FieldDecl *FD, QualType Ty) final {
15251578
const auto *AccDecl = Ty->getAsCXXRecordDecl();
15261579
// TODO : we don't need all this init stuff if remove kernel obj clone
15271580
// Perform initialization only if it is field of kernel object
15281581
if (Bases.size() == 1) {
1529-
InitializedEntity Entity = InitializedEntity::InitializeMember(
1530-
const_cast<FieldDecl *>(FD), &VarEntity);
1582+
InitializedEntity Entity =
1583+
InitializedEntity::InitializeMember(FD, &VarEntity);
15311584
// Initialize with the default constructor.
15321585
InitializationKind InitKind =
15331586
InitializationKind::CreateDefault(SourceLocation());
@@ -1536,8 +1589,7 @@ class SyclKernelBodyCreator
15361589
InitExprs.push_back(MemberInit.get());
15371590
}
15381591
// TODO don't do const-cast
1539-
createSpecialMethodCall(AccDecl, Bases.back(), InitMethodName,
1540-
const_cast<FieldDecl *>(FD));
1592+
createSpecialMethodCall(AccDecl, Bases.back(), InitMethodName, FD);
15411593
}
15421594

15431595
void handleSyclAccessorType(const CXXBaseSpecifier &BS, QualType Ty) final {
@@ -1556,16 +1608,16 @@ class SyclKernelBodyCreator
15561608
// TODO: Creates init/finalize sequence and inits special sycl obj
15571609
}
15581610

1559-
void handleStructType(const FieldDecl *FD, QualType Ty) final {
1560-
createExprForStructOrScalar(const_cast<FieldDecl *>(FD));
1611+
void handleStructType(FieldDecl *FD, QualType Ty) final {
1612+
createExprForStructOrScalar(FD);
15611613
}
15621614

1563-
void handleScalarType(const FieldDecl *FD, QualType Ty) final {
1564-
createExprForStructOrScalar(const_cast<FieldDecl *>(FD));
1615+
void handleScalarType(FieldDecl *FD, QualType Ty) final {
1616+
createExprForStructOrScalar(FD);
15651617
}
15661618

1567-
void enterStruct(const CXXRecordDecl *, const FieldDecl *FD) final {
1568-
Bases.push_back(BuildMemberExpr(Bases.back(), const_cast<FieldDecl *>(FD)));
1619+
void enterStruct(const CXXRecordDecl *, FieldDecl *FD) final {
1620+
Bases.push_back(BuildMemberExpr(Bases.back(), FD));
15691621
}
15701622

15711623
void leaveStruct(const CXXRecordDecl *, const FieldDecl *FD) final {

0 commit comments

Comments
 (0)