Skip to content

Commit

Permalink
[NFC][SYCL] Add const to some uses of CXXRecordDecl
Browse files Browse the repository at this point in the history
This adds const-correctness to a bit of the visitor, as brought up in
review on intel#1785.
  • Loading branch information
Erich Keane committed Jul 21, 2020
1 parent 630a6de commit 2a22824
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ getKernelInvocationKind(FunctionDecl *KernelCallerFunc) {
.Default(InvokeUnknown);
}

static CXXRecordDecl *getKernelObjectType(FunctionDecl *Caller) {
static const CXXRecordDecl *getKernelObjectType(FunctionDecl *Caller) {
return (*Caller->param_begin())->getType()->getAsCXXRecordDecl();
}

Expand Down Expand Up @@ -878,12 +878,12 @@ class KernelObjVisitor {
}

template <typename ParentTy, typename... Handlers>
void VisitRecord(CXXRecordDecl *Owner, ParentTy &Parent,
CXXRecordDecl *Wrapper, Handlers &... handlers);
void VisitRecord(const CXXRecordDecl *Owner, ParentTy &Parent,
const CXXRecordDecl *Wrapper, Handlers &... handlers);

template <typename... Handlers>
void VisitRecordHelper(CXXRecordDecl *Owner,
clang::CXXRecordDecl::base_class_range Range,
void VisitRecordHelper(const CXXRecordDecl *Owner,
clang::CXXRecordDecl::base_class_const_range Range,
Handlers &... handlers) {
for (const auto &Base : Range) {
(void)std::initializer_list<int>{
Expand All @@ -906,15 +906,15 @@ class KernelObjVisitor {
}

template <typename... Handlers>
void VisitRecordHelper(CXXRecordDecl *Owner,
clang::RecordDecl::field_range Range,
void VisitRecordHelper(const CXXRecordDecl *Owner,
RecordDecl::field_range Range,
Handlers &... handlers) {
VisitRecordFields(Owner, handlers...);
}

// FIXME: Can this be refactored/handled some other way?
template <typename ParentTy, typename... Handlers>
void VisitStreamRecord(CXXRecordDecl *Owner, ParentTy &Parent,
void VisitStreamRecord(const CXXRecordDecl *Owner, ParentTy &Parent,
CXXRecordDecl *Wrapper, Handlers &... handlers) {
(void)std::initializer_list<int>{
(handlers.enterStruct(Owner, Parent), 0)...};
Expand All @@ -933,14 +933,14 @@ class KernelObjVisitor {
}

template <typename... Handlers>
void VisitRecordBases(CXXRecordDecl *KernelFunctor, Handlers &... handlers) {
void VisitRecordBases(const CXXRecordDecl *KernelFunctor, Handlers &... handlers) {
VisitRecordHelper(KernelFunctor, KernelFunctor->bases(), handlers...);
}

// A visitor function that dispatches to functions as defined in
// SyclKernelFieldHandler for the purposes of kernel generation.
template <typename... Handlers>
void VisitRecordFields(CXXRecordDecl *Owner, Handlers &... handlers) {
void VisitRecordFields(const CXXRecordDecl *Owner, Handlers &... handlers) {

for (const auto Field : Owner->fields()) {
(void)std::initializer_list<int>{
Expand Down Expand Up @@ -987,8 +987,8 @@ class KernelObjVisitor {
// type (which doesn't exist in cases where it is a FieldDecl in the
// 'root'), and Wrapper is the current struct being unwrapped.
template <typename ParentTy, typename... Handlers>
void KernelObjVisitor::VisitRecord(CXXRecordDecl *Owner, ParentTy &Parent,
CXXRecordDecl *Wrapper,
void KernelObjVisitor::VisitRecord(const CXXRecordDecl *Owner, ParentTy &Parent,
const CXXRecordDecl *Wrapper,
Handlers &... handlers) {
(void)std::initializer_list<int>{(handlers.enterStruct(Owner, Parent), 0)...};
VisitRecordHelper(Wrapper, Wrapper->bases(), handlers...);
Expand Down Expand Up @@ -1357,7 +1357,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
llvm::SmallVector<Expr *, 16> InitExprs;
VarDecl *KernelObjClone;
InitializedEntity VarEntity;
CXXRecordDecl *KernelObj;
const CXXRecordDecl *KernelObj;
llvm::SmallVector<Expr *, 16> MemberExprBases;
uint64_t ArrayIndex;
FunctionDecl *KernelCallerFunc;
Expand Down Expand Up @@ -1524,7 +1524,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
// FIXME Avoid creation of kernel obj clone.
// See https://github.com/intel/llvm/issues/1544 for details.
static VarDecl *createKernelObjClone(ASTContext &Ctx, DeclContext *DC,
CXXRecordDecl *KernelObj) {
const CXXRecordDecl *KernelObj) {
TypeSourceInfo *TSInfo =
KernelObj->isLambda() ? KernelObj->getLambdaTypeInfo() : nullptr;
VarDecl *VD = VarDecl::Create(
Expand Down Expand Up @@ -1572,7 +1572,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {

public:
SyclKernelBodyCreator(Sema &S, SyclKernelDeclCreator &DC,
CXXRecordDecl *KernelObj,
const CXXRecordDecl *KernelObj,
FunctionDecl *KernelCallerFunc)
: SyclKernelFieldHandler(S), DeclCreator(DC),
KernelObjClone(createKernelObjClone(S.getASTContext(),
Expand Down Expand Up @@ -1934,7 +1934,7 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
void Sema::ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc,
MangleContext &MC) {
// The first argument to the KernelCallerFunc is the lambda object.
CXXRecordDecl *KernelObj = getKernelObjectType(KernelCallerFunc);
const CXXRecordDecl *KernelObj = getKernelObjectType(KernelCallerFunc);
assert(KernelObj && "invalid kernel caller");

// Calculate both names, since Integration headers need both.
Expand Down

0 comments on commit 2a22824

Please sign in to comment.