From 2a22824783a8285adbbd3dc5e5ecc6cea24f3cb1 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 21 Jul 2020 07:10:19 -0700 Subject: [PATCH] [NFC][SYCL] Add const to some uses of CXXRecordDecl This adds const-correctness to a bit of the visitor, as brought up in review on #1785. --- clang/lib/Sema/SemaSYCL.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index c176f6e639f51..c2a74b0c21659 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -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(); } @@ -878,12 +878,12 @@ class KernelObjVisitor { } template - void VisitRecord(CXXRecordDecl *Owner, ParentTy &Parent, - CXXRecordDecl *Wrapper, Handlers &... handlers); + void VisitRecord(const CXXRecordDecl *Owner, ParentTy &Parent, + const CXXRecordDecl *Wrapper, Handlers &... handlers); template - 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{ @@ -906,15 +906,15 @@ class KernelObjVisitor { } template - 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 - void VisitStreamRecord(CXXRecordDecl *Owner, ParentTy &Parent, + void VisitStreamRecord(const CXXRecordDecl *Owner, ParentTy &Parent, CXXRecordDecl *Wrapper, Handlers &... handlers) { (void)std::initializer_list{ (handlers.enterStruct(Owner, Parent), 0)...}; @@ -933,14 +933,14 @@ class KernelObjVisitor { } template - 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 - void VisitRecordFields(CXXRecordDecl *Owner, Handlers &... handlers) { + void VisitRecordFields(const CXXRecordDecl *Owner, Handlers &... handlers) { for (const auto Field : Owner->fields()) { (void)std::initializer_list{ @@ -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 -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{(handlers.enterStruct(Owner, Parent), 0)...}; VisitRecordHelper(Wrapper, Wrapper->bases(), handlers...); @@ -1357,7 +1357,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler { llvm::SmallVector InitExprs; VarDecl *KernelObjClone; InitializedEntity VarEntity; - CXXRecordDecl *KernelObj; + const CXXRecordDecl *KernelObj; llvm::SmallVector MemberExprBases; uint64_t ArrayIndex; FunctionDecl *KernelCallerFunc; @@ -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( @@ -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(), @@ -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.