diff --git a/README.md b/README.md index 20ed1f880..cd17a2464 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ Clad also provides certain flags to save and print the generated derivative code - To print the Clad generated derivative: `-Xclang -plugin-arg-clad -Xclang -fdump-derived-fn` ## How to install -At the moment, LLVM/Clang 8.0.x - 18.x.x are supported. +At the moment, LLVM/Clang 8.0.x - 18.1.x are supported. ### Conda Installation diff --git a/include/clad/Differentiator/Compatibility.h b/include/clad/Differentiator/Compatibility.h index 22e9507a1..c2f1e9bc4 100644 --- a/include/clad/Differentiator/Compatibility.h +++ b/include/clad/Differentiator/Compatibility.h @@ -41,9 +41,9 @@ using namespace llvm; //Clang 18 ArrayType::Normal -> ArraySizeModifier::Normal #if LLVM_VERSION_MAJOR < 18 -#define ArrayType_Normal ArrayType::Normal +const auto ArraySizeModifier_Normal = clang::ArrayType::Normal; #else -#define ArrayType_Normal ArraySizeModifier::Normal +const auto ArraySizeModifier_Normal = clang::ArraySizeModifier::Normal; #endif // Compatibility helper function for creation UnresolvedLookupExpr. @@ -98,9 +98,9 @@ static inline Stmt* UnresolvedLookupExpr_Create(const ASTContext &Ctx, //Clang 18 ETK_None -> ElaboratedTypeKeyword::None #if LLVM_VERSION_MAJOR < 18 -#define ElaboratedTypeKeyword_None ETK_None +const auto ElaboratedTypeKeyword_None = ETK_None; #else -#define ElaboratedTypeKeyword_None ElaboratedTypeKeyword::None +const auto ElaboratedTypeKeyword_None = ElaboratedTypeKeyword::None; #endif //Clang 18 endswith->ends_with @@ -708,13 +708,15 @@ static inline bool IsPRValue(const Expr* E) { return E->isPRValue(); } // Clang 18 renamed clang::StringLiteral::StringKind::Ordinary became clang::StringLiteralKind::Ordinary; #if CLANG_VERSION_MAJOR < 15 - const auto StringKind_Ordinary = clang::StringLiteral::StringKind::Ascii; +const auto StringLiteralKind_Ordinary = clang::StringLiteral::StringKind::Ascii; #elif CLANG_VERSION_MAJOR >= 15 #if CLANG_VERSION_MAJOR < 18 - const auto StringKind_Ordinary = clang::StringLiteral::StringKind::Ordinary; - #else - const auto StringKind_Ordinary = clang::StringLiteralKind::Ordinary; - #endif +const auto StringLiteralKind_Ordinary = + clang::StringLiteral::StringKind::Ordinary; +#else +const auto StringLiteralKind_Ordinary = + clang::StringLiteral::StringKind::Ordinary; +#endif #endif // Clang 15 add one extra param to Sema::CheckFunctionDeclaration diff --git a/lib/Differentiator/BaseForwardModeVisitor.cpp b/lib/Differentiator/BaseForwardModeVisitor.cpp index 8c3176c7b..33327f8b9 100644 --- a/lib/Differentiator/BaseForwardModeVisitor.cpp +++ b/lib/Differentiator/BaseForwardModeVisitor.cpp @@ -1726,8 +1726,9 @@ BaseForwardModeVisitor::DeriveSwitchStmtBodyHelper(const Stmt* stmt, (newCaseSC->getLHS() ? Clone(newCaseSC->getLHS()) : nullptr); Expr* rhsClone = (newCaseSC->getRHS() ? Clone(newCaseSC->getRHS()) : nullptr); - newActiveSC = CaseStmt::Create(const_cast(m_Sema.getASTContext()), lhsClone, rhsClone, noLoc, noLoc, noLoc); - + newActiveSC = CaseStmt::Create(m_Sema.getASTContext(), lhsClone, rhsClone, + noLoc, noLoc, noLoc); + } else if (isa(SC)) { newActiveSC = new (m_Sema.getASTContext()) DefaultStmt(noLoc, noLoc, nullptr); @@ -1993,4 +1994,4 @@ StmtDiff BaseForwardModeVisitor::VisitSubstNonTypeTemplateParmExpr( const clang::SubstNonTypeTemplateParmExpr* NTTP) { return Visit(NTTP->getReplacement()); } -} // end namespace clad \ No newline at end of file +} // end namespace clad diff --git a/lib/Differentiator/CladUtils.cpp b/lib/Differentiator/CladUtils.cpp index 3b407cbd5..ef7dceb55 100644 --- a/lib/Differentiator/CladUtils.cpp +++ b/lib/Differentiator/CladUtils.cpp @@ -166,7 +166,8 @@ namespace clad { utils::BuildNNS(semaRef, const_cast(declContext), CSS); NestedNameSpecifier* NS = CSS.getScopeRep(); if (auto* Prefix = NS->getPrefix()) - return C.getElaboratedType(ElaboratedTypeKeyword_None, Prefix, QT); + return C.getElaboratedType(clad_compat::ElaboratedTypeKeyword_None, + Prefix, QT); } return QT; } @@ -268,16 +269,15 @@ namespace clad { StringLiteral* CreateStringLiteral(ASTContext& C, llvm::StringRef str) { // Copied and adapted from clang::Sema::ActOnStringLiteral. QualType CharTyConst = C.CharTy.withConst(); - QualType - StrTy = clad_compat::getConstantArrayType(C, CharTyConst, - llvm::APInt(/*numBits=*/32, - str.size() + 1), - /*SizeExpr=*/nullptr, - /*ASM=*/ArrayType_Normal, - /*IndexTypeQuals*/ 0); - StringLiteral* SL = StringLiteral::Create(C, str, - /*Kind=*/clad_compat::StringKind_Ordinary, - /*Pascal=*/false, StrTy, noLoc); + QualType StrTy = clad_compat::getConstantArrayType( + C, CharTyConst, llvm::APInt(/*numBits=*/32, str.size() + 1), + /*SizeExpr=*/nullptr, + /*ASM=*/clad_compat::ArraySizeModifier_Normal, + /*IndexTypeQuals*/ 0); + StringLiteral* SL = StringLiteral::Create( + C, str, + /*Kind=*/clad_compat::StringLiteralKind_Ordinary, + /*Pascal=*/false, StrTy, noLoc); return SL; } diff --git a/lib/Differentiator/HessianModeVisitor.cpp b/lib/Differentiator/HessianModeVisitor.cpp index d0494a087..f44443341 100644 --- a/lib/Differentiator/HessianModeVisitor.cpp +++ b/lib/Differentiator/HessianModeVisitor.cpp @@ -36,16 +36,14 @@ namespace clad { static const StringLiteral* CreateStringLiteral(ASTContext& C, std::string str) { QualType CharTyConst = C.CharTy.withConst(); - QualType StrTy = - clad_compat::getConstantArrayType(C, CharTyConst, - llvm::APInt(/*numBits=*/32, - str.size() + 1), - /*SizeExpr=*/nullptr, - /*ASM=*/ArrayType_Normal, - /*IndexTypeQuals*/ 0); - const StringLiteral* SL = - StringLiteral::Create(C, str, /*Kind=*/clad_compat::StringKind_Ordinary, - /*Pascal=*/false, StrTy, noLoc); + QualType StrTy = clad_compat::getConstantArrayType( + C, CharTyConst, llvm::APInt(/*numBits=*/32, str.size() + 1), + /*SizeExpr=*/nullptr, + /*ASM=*/clad_compat::ArraySizeModifier_Normal, + /*IndexTypeQuals*/ 0); + const StringLiteral* SL = StringLiteral::Create( + C, str, /*Kind=*/clad_compat::StringLiteralKind_Ordinary, + /*Pascal=*/false, StrTy, noLoc); return SL; } diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 3058b8955..cc48102cc 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -3443,7 +3443,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, Expr* lhsClone = (CS->getLHS() ? Clone(CS->getLHS()) : nullptr); Expr* rhsClone = (CS->getRHS() ? Clone(CS->getRHS()) : nullptr); - auto* newSC = CaseStmt::Create(const_cast(m_Sema.getASTContext()), lhsClone, rhsClone, noLoc, noLoc, noLoc); + auto* newSC = CaseStmt::Create(m_Sema.getASTContext(), lhsClone, rhsClone, + noLoc, noLoc, noLoc); Expr* ifCond = BuildOp(BinaryOperatorKind::BO_EQ, newSC->getLHS(), SSData->switchStmtCond); @@ -3625,7 +3626,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, CaseStmt* ReverseModeVisitor::BreakContStmtHandler::GetNextCFCaseStmt() { ++m_CaseCounter; auto* counterLiteral = CreateSizeTLiteralExpr(m_CaseCounter); - CaseStmt* CS = CaseStmt::Create(const_cast(m_RMV.m_Context), counterLiteral, nullptr, noLoc, noLoc, noLoc); + CaseStmt* CS = CaseStmt::Create(m_RMV.m_Context, counterLiteral, nullptr, + noLoc, noLoc, noLoc); // Initialise switch case statements with null statement because it is // necessary for switch case statements to have a substatement but it diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index 62d33c4b2..e78c6e8c2 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -402,7 +402,9 @@ Stmt* StmtClone::VisitShuffleVectorExpr(ShuffleVectorExpr* Node) { } Stmt* StmtClone::VisitCaseStmt(CaseStmt* Node) { - CaseStmt* result = CaseStmt::Create(const_cast(Ctx), Clone(Node->getLHS()), Clone(Node->getRHS()), Node->getCaseLoc(), Node->getEllipsisLoc(), Node->getColonLoc()); + CaseStmt* result = CaseStmt::Create( + Ctx, Clone(Node->getLHS()), Clone(Node->getRHS()), Node->getCaseLoc(), + Node->getEllipsisLoc(), Node->getColonLoc()); result->setSubStmt(Clone(Node->getSubStmt())); return result; } diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 7ffb42123..a482c29ab 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -452,7 +452,8 @@ namespace clad { // Create elaborated type with namespace specifier, // i.e. class -> clad::class - return m_Context.getElaboratedType(ElaboratedTypeKeyword_None, NS, TT); + return m_Context.getElaboratedType(clad_compat::ElaboratedTypeKeyword_None, + NS, TT); } QualType VisitorBase::InstantiateTemplate(TemplateDecl* CladClassDecl, diff --git a/tools/ClangPlugin.cpp b/tools/ClangPlugin.cpp index cdcd3daf4..23c416385 100644 --- a/tools/ClangPlugin.cpp +++ b/tools/ClangPlugin.cpp @@ -79,10 +79,10 @@ namespace clad { // Find the path to clad. llvm::StringRef CladSoPath; for (llvm::StringRef P : Opts.Plugins) - if (llvm::sys::path::stem(P).ends_with("clad")) { - CladSoPath = P; - break; - } + if (llvm::sys::path::stem(P).ends_with("clad")) { + CladSoPath = P; + break; + } // Register clad as a backend pass. CodeGenOptions& CGOpts = CI.getCodeGenOpts();