diff --git a/include/clad/Differentiator/VisitorBase.h b/include/clad/Differentiator/VisitorBase.h index a07be18f7..9457232c1 100644 --- a/include/clad/Differentiator/VisitorBase.h +++ b/include/clad/Differentiator/VisitorBase.h @@ -408,7 +408,7 @@ namespace clad { /// a sequence of indices. clang::Expr* BuildArraySubscript(clang::Expr* Base, - llvm::SmallVectorImpl& IS); + const llvm::SmallVectorImpl& IS); /// Find namespace clad declaration. clang::NamespaceDecl* GetCladNamespace(); /// Find declaration of clad::class templated type diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 05e27dc10..3b1d2fea8 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -418,19 +418,21 @@ namespace clad { } Expr* VisitorBase::BuildArraySubscript( - Expr* Base, llvm::SmallVectorImpl& Indices) { + Expr* Base, const llvm::SmallVectorImpl& Indices) { Expr* result = Base; SourceLocation fakeLoc = utils::GetValidSLoc(m_Sema); - if (utils::isArrayOrPointerType(Base->getType())) + if (utils::isArrayOrPointerType(Base->getType())) { for (Expr* I : Indices) result = m_Sema.CreateBuiltinArraySubscriptExpr(result, fakeLoc, I, fakeLoc) .get(); - else + } else { + Expr* idx = Indices.back(); result = m_Sema - .ActOnArraySubscriptExpr(getCurrentScope(), Base, fakeLoc, - Indices.back(), fakeLoc) + .ActOnArraySubscriptExpr(getCurrentScope(), Base, fakeLoc, idx, + fakeLoc) .get(); + } return result; }