diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e0e9b102..87d087b7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,11 @@ jobs: os: macos-14 compiler: clang clang-runtime: '17' + #Turn on once clang-18 available through Homebrew + #- name: osx14-arm-clang-runtime18 + # os: macos-14 + # compiler: clang + # clang-runtime: '18' - name: osx13-x86-clang-runtime12 os: macos-13 @@ -78,6 +83,11 @@ jobs: os: macos-13 compiler: clang clang-runtime: '17' + #Turn on once clang-18 available through Homebrew + #- name: osx13-x86-clang-runtime18 + # os: macos-13 + # compiler: clang + # clang-runtime: '18' - name: win2022-msvc-runtime14 os: windows-2022 @@ -99,6 +109,11 @@ jobs: compiler: msvc clang-runtime: '17' + - name: win2022-msvc-runtime18 + os: windows-2022 + compiler: msvc + clang-runtime: '18' + - name: ubu22-clang15-runtime16-debug os: ubuntu-22.04 compiler: clang-15 @@ -442,12 +457,12 @@ jobs: extra_packages: 'libtrilinos-kokkos-dev ninja-build' extra_cmake_options: '-G Ninja' - # Оld, still supported versions + - name: ubu22-clang16-runtime18 + os: ubuntu-22.04 + compiler: clang-16 + clang-runtime: '18' - - name: ubu20-gcc9-runtime7 - os: ubuntu-20.04 - compiler: gcc-9 - clang-runtime: '7' + # Оld, still supported versions - name: ubu20-gcc9-runtime8 os: ubuntu-20.04 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e8e1900e..2170c60ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,12 +39,12 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) ## Define clad supported version of clang and llvm - set(CLANG_MIN_SUPPORTED 7.0) - set(CLANG_MAX_SUPPORTED "17.0.x") - set(CLANG_VERSION_UPPER_BOUND 17.1.0) - set(LLVM_MIN_SUPPORTED 7.0) - set(LLVM_MAX_SUPPORTED "17.0.x") - set(LLVM_VERSION_UPPER_BOUND 17.1.0) + set(CLANG_MIN_SUPPORTED 8.0) + set(CLANG_MAX_SUPPORTED "18.1.x") + set(CLANG_VERSION_UPPER_BOUND 18.2.0) + set(LLVM_MIN_SUPPORTED 8.0) + set(LLVM_MAX_SUPPORTED "18.1.x") + set(LLVM_VERSION_UPPER_BOUND 18.2.0) if (NOT DEFINED Clang_DIR) set(Clang_DIR ${LLVM_DIR}) diff --git a/README.md b/README.md index 00703d1eb..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 7.0.x - 17.0.x are supported. +At the moment, LLVM/Clang 8.0.x - 18.1.x are supported. ### Conda Installation @@ -276,7 +276,7 @@ make check-clad ``` pip3 install lit ``` -Clone the LLVM project and checkout the required LLVM version (Currently supported versions 7.x - 17.x) +Clone the LLVM project and checkout the required LLVM version (Currently supported versions 8.x - 18.x) ``` git clone https://github.com/llvm/llvm-project.git diff --git a/docs/internalDocs/ReleaseNotes.md b/docs/internalDocs/ReleaseNotes.md index c8081306d..f5b002e11 100644 --- a/docs/internalDocs/ReleaseNotes.md +++ b/docs/internalDocs/ReleaseNotes.md @@ -21,7 +21,7 @@ described first. External Dependencies --------------------- -* Clad now works with clang-7 to clang-17 +* Clad now works with clang-8 to clang-18 Forward Mode & Reverse Mode diff --git a/include/clad/Differentiator/Compatibility.h b/include/clad/Differentiator/Compatibility.h index 9f11a652e..8d1e836a5 100644 --- a/include/clad/Differentiator/Compatibility.h +++ b/include/clad/Differentiator/Compatibility.h @@ -21,6 +21,76 @@ namespace clad_compat { using namespace clang; using namespace llvm; +// clang-18 CXXThisExpr got extra argument + +#if CLANG_VERSION_MAJOR > 17 +#define CLAD_COMPAT_CLANG17_CXXThisExpr_ExtraParam DEFINE_CREATE_EXPR(CXXThisExpr, (Ctx, +#else +#define CLAD_COMPAT_CLANG17_CXXThisExpr_ExtraParam DEFINE_CLONE_EXPR(CXXThisExpr, ( +#endif + +// clang-18 ActOnLambdaExpr got extra argument + +#if CLANG_VERSION_MAJOR > 17 +#define CLAD_COMPAT_CLANG17_ActOnLambdaExpr_getCurrentScope_ExtraParam(V) /**/ +#else +#define CLAD_COMPAT_CLANG17_ActOnLambdaExpr_getCurrentScope_ExtraParam(V) \ + , (V).getCurrentScope() +#endif + +// Clang 18 ArrayType::Normal -> ArraySizeModifier::Normal + +#if LLVM_VERSION_MAJOR < 18 +const auto ArraySizeModifier_Normal = clang::ArrayType::Normal; +#else +const auto ArraySizeModifier_Normal = clang::ArraySizeModifier::Normal; +#endif + +// Compatibility helper function for creation UnresolvedLookupExpr. +// Clang-18 extra argument knowndependent. +// FIXME: Knowndependent set to false temporarily until known value found for +// initialisation. + +static inline Stmt* UnresolvedLookupExpr_Create( + const ASTContext& Ctx, CXXRecordDecl* NamingClass, + NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, + const DeclarationNameInfo& NameInfo, bool RequiresADL, + const TemplateArgumentListInfo* Args, UnresolvedSetIterator Begin, + UnresolvedSetIterator End) { + +#if CLANG_VERSION_MAJOR < 18 + return UnresolvedLookupExpr::Create(Ctx, NamingClass, QualifierLoc, + TemplateKWLoc, NameInfo, RequiresADL, + // They get copied again by + // OverloadExpr, so we are safe. + Args, Begin, End); + +#else + bool KnownDependent = false; + return UnresolvedLookupExpr::Create(Ctx, NamingClass, QualifierLoc, + TemplateKWLoc, NameInfo, RequiresADL, + // They get copied again by + // OverloadExpr, so we are safe. + Args, Begin, End, KnownDependent); +#endif +} + +// Clang 18 ETK_None -> ElaboratedTypeKeyword::None + +#if LLVM_VERSION_MAJOR < 18 +const auto ElaboratedTypeKeyword_None = ETK_None; +#else +const auto ElaboratedTypeKeyword_None = ElaboratedTypeKeyword::None; +#endif + +// Clang 18 endswith->ends_with +// and starstwith->starts_with + +#if LLVM_VERSION_MAJOR < 18 +#define starts_with startswith +#define ends_with startswith +#endif + // Compatibility helper function for creation CompoundStmt. // Clang 15 and above use a extra param FPFeatures in CompoundStmt::Create. @@ -71,31 +141,6 @@ NamespaceDecl_Create(ASTContext& C, DeclContext* DC, bool Inline, } #endif -// Clang 7 add one extra param in UnaryOperator constructor. - -#if CLANG_VERSION_MAJOR >= 7 -#define CLAD_COMPAT_CLANG7_UnaryOperator_ExtraParams , Node->canOverflow() -#endif - - -// Clang 8 change E->EvaluateAsInt(APSInt int, context) ===> E->EvaluateAsInt(Expr::EvalResult res, context) - -static inline bool Expr_EvaluateAsInt(const Expr *E, - APSInt &IntValue, const ASTContext &Ctx, - Expr::SideEffectsKind AllowSideEffects = Expr::SideEffectsKind::SE_NoSideEffects) -{ -#if CLANG_VERSION_MAJOR < 8 - return E->EvaluateAsInt(IntValue, Ctx, AllowSideEffects); -#elif CLANG_VERSION_MAJOR >= 8 - Expr::EvalResult res; - if (E->EvaluateAsInt(res, Ctx, AllowSideEffects)) { - IntValue = res.Val.getInt(); - return true; - } - return false; -#endif -} - // Clang 12: bool Expr::EvaluateAsConstantExpr(EvalResult &Result, // ConstExprUsage Usage, ASTContext &) // => bool Expr::EvaluateAsConstantExpr(EvalResult &Result, ASTContext &) @@ -111,7 +156,6 @@ static inline bool Expr_EvaluateAsConstantExpr(const Expr* E, } // Compatibility helper function for creation IfStmt. -// Clang 8 and above use Create. // Clang 12 and above use two extra params. static inline IfStmt* IfStmt_Create(const ASTContext &Ctx, @@ -120,12 +164,12 @@ static inline IfStmt* IfStmt_Create(const ASTContext &Ctx, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr) { -#if CLANG_VERSION_MAJOR < 8 - return new (Ctx) IfStmt(Ctx, IL, IsConstexpr, Init, Var, Cond, Then, EL, Else); -#elif CLANG_VERSION_MAJOR < 12 - return IfStmt::Create(Ctx, IL, IsConstexpr, Init, Var, Cond, Then, EL, Else); + +#if CLANG_VERSION_MAJOR < 12 + return IfStmt::Create(Ctx, IL, IsConstexpr, Init, Var, Cond, Then, EL, Else); #elif CLANG_VERSION_MAJOR < 14 - return IfStmt::Create(Ctx, IL, IsConstexpr, Init, Var, Cond, LPL, RPL, Then, EL, Else); + return IfStmt::Create(Ctx, IL, IsConstexpr, Init, Var, Cond, LPL, RPL, Then, + EL, Else); #elif CLANG_VERSION_MAJOR >= 14 IfStatementKind kind = IfStatementKind::Ordinary; if (IsConstexpr) @@ -134,34 +178,10 @@ static inline IfStmt* IfStmt_Create(const ASTContext &Ctx, #endif } - -// Clang 8 change Node->getIdentType() ===> Node->getIdentKind() - -#if CLANG_VERSION_MAJOR < 8 - #define getIdentKind() getIdentType() -#endif - - -// Clang 8 change Stmt(...) constructor to private ===> Use Stmt::Create(...) - -#if CLANG_VERSION_MAJOR < 8 - #define CLAD_COMPAT_CREATE(CLASS, CTORARGS) (new (Ctx) CLASS CTORARGS) -#elif CLANG_VERSION_MAJOR >= 8 - #define CLAD_COMPAT_CREATE(CLASS, CTORARGS) (CLASS::Create CTORARGS) -#endif - - // Compatibility helper function for creation CallExpr. -// Clang 8 and above use Create. // Clang 12 and above use one extra param. -#if CLANG_VERSION_MAJOR < 8 -static inline CallExpr* CallExpr_Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr *> Args, - QualType Ty, ExprValueKind VK, SourceLocation RParenLoc) -{ - return new (Ctx) CallExpr(Ctx, Fn, Args, Ty, VK, RParenLoc); -} -#elif CLANG_VERSION_MAJOR < 12 +#if CLANG_VERSION_MAJOR < 12 static inline CallExpr* CallExpr_Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, unsigned MinNumArgs = 0, CallExpr::ADLCallKind UsesADL = CallExpr::NotADL) @@ -177,14 +197,11 @@ static inline CallExpr* CallExpr_Create(const ASTContext &Ctx, Expr *Fn, ArrayRe } #endif - -// Clang 8 add one extra param (Ctx) in some constructors. // Clang 12 and above use one extra param. -#if CLANG_VERSION_MAJOR < 8 - #define CLAD_COMPAT_CLANG8_CallExpr_ExtraParams /**/ -#elif CLANG_VERSION_MAJOR < 12 - #define CLAD_COMPAT_CLANG8_CallExpr_ExtraParams ,Node->getNumArgs(),Node->getADLCallKind() +#if CLANG_VERSION_MAJOR < 12 +#define CLAD_COMPAT_CLANG8_CallExpr_ExtraParams \ + , Node->getNumArgs(), Node->getADLCallKind() #elif CLANG_VERSION_MAJOR >= 12 #define CLAD_COMPAT_CLANG8_CallExpr_ExtraParams ,Node->getFPFeatures(),Node->getNumArgs(),Node->getADLCallKind() #endif @@ -239,35 +256,10 @@ static inline void ExprSetDeps(Expr* result, Expr* Node) { #define CLAD_COMPAT_CLANG11_WhileStmt_ExtraParams ,Node->getLParenLoc(),Node->getRParenLoc() #endif -// Compatibility helper function for creation CXXOperatorCallExpr. Clang 8 and above use Create. - -static inline CXXOperatorCallExpr* CXXOperatorCallExpr_Create(ASTContext &Ctx, - OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef Args, QualType Ty, - ExprValueKind VK, SourceLocation OperatorLoc, CLAD_COMPAT_CLANG11_CXXOperatorCallExpr_Create_ExtraParamsOverride FPFeatures - CLAD_COMPAT_CLANG11_CXXOperatorCallExpr_Create_ExtraParamsPar - ) -{ -#if CLANG_VERSION_MAJOR < 8 - return new (Ctx) CXXOperatorCallExpr(Ctx, OpKind, Fn, Args, Ty, VK, OperatorLoc, FPFeatures); -#elif CLANG_VERSION_MAJOR >= 8 - return CXXOperatorCallExpr::Create(Ctx, OpKind, Fn, Args, Ty, VK, OperatorLoc, FPFeatures - CLAD_COMPAT_CLANG11_CXXOperatorCallExpr_Create_ExtraParamsUse - ); -#endif -} - - // Compatibility helper function for creation CXXMemberCallExpr. -// Clang 8 and above use Create. // Clang 12 and above use two extra param. -#if CLANG_VERSION_MAJOR < 8 -static inline CXXMemberCallExpr* CXXMemberCallExpr_Create(ASTContext &Ctx, - Expr *Fn, ArrayRef Args, QualType Ty, ExprValueKind VK, SourceLocation RP) -{ - return new (Ctx) CXXMemberCallExpr(Ctx, Fn, Args, Ty, VK, RP); -} -#elif CLANG_VERSION_MAJOR < 12 +#if CLANG_VERSION_MAJOR < 12 static inline CXXMemberCallExpr* CXXMemberCallExpr_Create(ASTContext &Ctx, Expr *Fn, ArrayRef Args, QualType Ty, ExprValueKind VK, SourceLocation RP) { @@ -283,64 +275,21 @@ static inline CXXMemberCallExpr* CXXMemberCallExpr_Create(ASTContext &Ctx, } #endif - -// Compatibility helper function for creation CaseStmt. Clang 8 and above use Create. - -static inline CaseStmt* CaseStmt_Create(ASTContext &Ctx, - Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc) -{ -#if CLANG_VERSION_MAJOR < 8 - return new (Ctx) CaseStmt(lhs, rhs, caseLoc, ellipsisLoc, colonLoc); -#elif CLANG_VERSION_MAJOR >= 8 - return CaseStmt::Create(const_cast(Ctx), lhs, rhs, caseLoc, ellipsisLoc, colonLoc); -#endif -} - - // Compatibility helper function for creation SwitchStmt. -// Clang 8 and above use Create. // Clang 12 and above use two extra params. static inline SwitchStmt* SwitchStmt_Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc) { -#if CLANG_VERSION_MAJOR < 8 - return new (Ctx) SwitchStmt(Ctx, Init, Var, Cond); -#elif CLANG_VERSION_MAJOR < 12 - return SwitchStmt::Create(Ctx, Init, Var, Cond); + +#if CLANG_VERSION_MAJOR < 12 + return SwitchStmt::Create(Ctx, Init, Var, Cond); #elif CLANG_VERSION_MAJOR >= 12 return SwitchStmt::Create(Ctx, Init, Var, Cond, LParenLoc, RParenLoc); #endif } - -// Clang 8 change E->getLocStart() ===> E->getBeginLoc() -// E->getLocEnd() ===> E->getEndLoc() -// Clang 7 define both for compatibility - -#if CLANG_VERSION_MAJOR < 7 - #define getBeginLoc() getLocStart() - #define getEndLoc() getLocEnd() -#endif - - -// Clang 8 add one extra param (Ctx) in some constructors. - -#if CLANG_VERSION_MAJOR < 8 - #define CLAD_COMPAT_CLANG8_Ctx_ExtraParams /**/ -#elif CLANG_VERSION_MAJOR >= 8 - #define CLAD_COMPAT_CLANG8_Ctx_ExtraParams Ctx, -#endif - - -// Clang 8 change result->setNumArgs(Ctx, Num) ===> result->setNumArgsUnsafe(Num) - -#if CLANG_VERSION_MAJOR < 8 - #define setNumArgsUnsafe(NUM) setNumArgs(Ctx, NUM) -#endif - - // Compatibility helper function for getConstexprKind(). Clang 9 template @@ -382,22 +331,30 @@ static inline ConstexprSpecKind Function_GetConstexprKind(const FunctionDecl* F) #define PragmaIntroducer PragmaIntroducerKind #endif - // Clang 10 change add new param in getConstantArrayType. - -static inline QualType getConstantArrayType(const ASTContext &Ctx, - QualType EltTy, - const APInt &ArySize, - const Expr* SizeExpr, - clang::ArrayType::ArraySizeModifier ASM, - unsigned IndexTypeQuals) -{ +// clang 18 clang::ArrayType::ArraySizeModifier became clang::ArraySizeModifier +#if CLANG_VERSION_MAJOR < 18 +static inline QualType +getConstantArrayType(const ASTContext& Ctx, QualType EltTy, + const APInt& ArySize, const Expr* SizeExpr, + clang::ArrayType::ArraySizeModifier ASM, + unsigned IndexTypeQuals) { #if CLANG_VERSION_MAJOR < 10 return Ctx.getConstantArrayType(EltTy, ArySize, ASM, IndexTypeQuals); #elif CLANG_VERSION_MAJOR >= 10 - return Ctx.getConstantArrayType(EltTy, ArySize, SizeExpr, ASM, IndexTypeQuals); + return Ctx.getConstantArrayType(EltTy, ArySize, SizeExpr, ASM, + IndexTypeQuals); #endif } +#else +static inline QualType +getConstantArrayType(const ASTContext& Ctx, QualType EltTy, + const APInt& ArySize, const Expr* SizeExpr, + clang::ArraySizeModifier ASM, unsigned IndexTypeQuals) { + return Ctx.getConstantArrayType(EltTy, ArySize, SizeExpr, ASM, + IndexTypeQuals); +} +#endif // Clang 10 add new last param TrailingRequiresClause in FunctionDecl::Create @@ -474,22 +431,10 @@ static inline QualType getConstantArrayType(const ASTContext &Ctx, #define CLAD_COMPAT_CLANG12_LR_ExtraParams(Node) ,Node->getLParenLoc(),Node->getRParenLoc() #endif -/// In Clang < 8, `CXXMethodDecl::getThisType()` member function requires -/// `ASTContext` to be passed as an argument. -static inline QualType CXXMethodDecl_getThisType(Sema& SemaRef, - const CXXMethodDecl* method) { -#if CLANG_VERSION_MAJOR >= 8 - auto thisType = method->getThisType(); -#elif CLANG_VERSION_MAJOR < 8 - auto thisType = method->getThisType(SemaRef.getASTContext()); -#endif - return thisType; -} - /// Clang < 9, do not provide `Sema::BuildCXXThisExpr` function. static inline CXXThisExpr* Sema_BuildCXXThisExpr(Sema& SemaRef, const CXXMethodDecl* method) { - auto thisType = CXXMethodDecl_getThisType(SemaRef, method); + auto thisType = method->getThisType(); SourceLocation noLoc; #if CLANG_VERSION_MAJOR >= 9 return cast( @@ -563,10 +508,13 @@ static inline Qualifiers CXXMethodDecl_getMethodQualifiers(const CXXMethodDecl* static inline Qualifiers CXXMethodDecl_getMethodQualifiers(const CXXMethodDecl* MD) { return MD->getTypeQualifiers(); } -#elif CLANG_VERSION_MAJOR < 8 -static inline Qualifiers CXXMethodDecl_getMethodQualifiers(const CXXMethodDecl* MD) { - return Qualifiers::fromFastMask(MD->getTypeQualifiers()); -} +#endif + +// Clone declarations. `ValueStmt` node is only available after clang 8. +#if CLANG_VERSION_MAJOR <= 8 +#define CLAD_COMPAT_8_DECLARE_CLONE_FN(ValueStmt) /**/ +#elif CLANG_VERSION_MAJOR > 8 +#define CLAD_COMPAT_8_DECLARE_CLONE_FN(ValueStmt) DECLARE_CLONE_FN(ValueStmt) #endif #if CLANG_VERSION_MAJOR <= 13 @@ -617,12 +565,6 @@ static inline Expr* GetSubExpr(const MaterializeTemporaryExpr* MTE) { } #endif -#if CLANG_VERSION_MAJOR < 7 -#define CLAD_COMPAT_IS_LIST_INITIALIZATION_PARAM(E) -#else -#define CLAD_COMPAT_IS_LIST_INITIALIZATION_PARAM(E) , E->isListInitialization() -#endif - #if CLANG_VERSION_MAJOR < 9 static inline QualType CXXMethodDecl_GetThisObjectType(Sema& semaRef, const CXXMethodDecl* MD) { @@ -636,7 +578,12 @@ CXXMethodDecl_GetThisObjectType(Sema& semaRef, const CXXMethodDecl* MD) { #else static inline QualType CXXMethodDecl_GetThisObjectType(Sema& semaRef, const CXXMethodDecl* MD) { +// clang-18 renamed getThisObjectType to getFunctionObjectParameterType +#if CLANG_VERSION_MAJOR < 18 return MD->getThisObjectType(); +#else + return MD->getFunctionObjectParameterType(); +#endif } #endif @@ -727,12 +674,19 @@ static inline bool IsPRValue(const Expr* E) { return E->isPRValue(); } #define CLAD_COMPAT_CLANG16_CXXDefaultArgExpr_getRewrittenExpr_Param(Node) /**/ #endif -// Clang 15 rename StringKind::Ascii to StringKind::Ordinary +// Clang 15 renamed StringKind::Ascii to StringKind::Ordinary +// 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 - const auto StringKind_Ordinary = clang::StringLiteral::StringKind::Ordinary; +#if CLANG_VERSION_MAJOR < 18 +const auto StringLiteralKind_Ordinary = + clang::StringLiteral::StringKind::Ordinary; +#else +const auto StringLiteralKind_Ordinary = clang::StringLiteralKind::Ordinary; +#endif #endif // Clang 15 add one extra param to Sema::CheckFunctionDeclaration diff --git a/include/clad/Differentiator/StmtClone.h b/include/clad/Differentiator/StmtClone.h index 79f7ff1cb..00c901cfa 100644 --- a/include/clad/Differentiator/StmtClone.h +++ b/include/clad/Differentiator/StmtClone.h @@ -8,6 +8,8 @@ #ifndef CLAD_UTILS_STMTCLONE_H #define CLAD_UTILS_STMTCLONE_H +#include "Compatibility.h" + #include "clang/AST/StmtVisitor.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/Version.h" @@ -122,14 +124,8 @@ namespace utils { DECLARE_CLONE_FN(PseudoObjectExpr) DECLARE_CLONE_FN(SubstNonTypeTemplateParmExpr) DECLARE_CLONE_FN(CXXScalarValueInitExpr) - // `ConstantExpr` node is only available after clang 7. - #if CLANG_VERSION_MAJOR > 7 DECLARE_CLONE_FN(ConstantExpr) - #endif -#if CLANG_VERSION_MAJOR > 8 - // `ValueStmt` node is only available after clang 8. - DECLARE_CLONE_FN(ValueStmt) -#endif + CLAD_COMPAT_8_DECLARE_CLONE_FN(ValueStmt) clang::Stmt* VisitStmt(clang::Stmt*); }; diff --git a/include/clad/Differentiator/VisitorBase.h b/include/clad/Differentiator/VisitorBase.h index 9feeb6624..0bbc13290 100644 --- a/include/clad/Differentiator/VisitorBase.h +++ b/include/clad/Differentiator/VisitorBase.h @@ -170,6 +170,7 @@ namespace clad { CLAD_COMPAT_CLANG12_Declarator_LambdaExpr); #if CLANG_VERSION_MAJOR > 16 V.beginScope(clang::Scope::LambdaScope | clang::Scope::DeclScope | + clang::Scope::FunctionDeclarationScope | clang::Scope::FunctionPrototypeScope); #endif // CLANG_VERSION_MAJOR @@ -192,7 +193,12 @@ namespace clad { func(); clang::CompoundStmt* body = V.endBlock(); clang::Expr* lambda = - S.ActOnLambdaExpr(noLoc, body, V.getCurrentScope()).get(); + S.ActOnLambdaExpr( + noLoc, + body /*,*/ + CLAD_COMPAT_CLANG17_ActOnLambdaExpr_getCurrentScope_ExtraParam( + V)) + .get(); V.endScope(); return S.ActOnCallExpr(V.getCurrentScope(), lambda, noLoc, {}, noLoc) .get(); diff --git a/lib/Differentiator/BaseForwardModeVisitor.cpp b/lib/Differentiator/BaseForwardModeVisitor.cpp index 520e025c7..958b05ad4 100644 --- a/lib/Differentiator/BaseForwardModeVisitor.cpp +++ b/lib/Differentiator/BaseForwardModeVisitor.cpp @@ -268,7 +268,7 @@ BaseForwardModeVisitor::Derive(const FunctionDecl* FD, if (MD->isInstance() && !MD->getParent()->isLambda()) { QualType thisObjectType = clad_compat::CXXMethodDecl_GetThisObjectType(m_Sema, MD); - QualType thisType = clad_compat::CXXMethodDecl_getThisType(m_Sema, MD); + QualType thisType = MD->getThisType(); // Here we are effectively doing: // ``` // Class _d_this_obj; @@ -405,7 +405,7 @@ BaseForwardModeVisitor::DerivePushforward(const FunctionDecl* FD, // derivative of `this` pointer with respect to the independent parameter. if (const auto* MD = dyn_cast(FD)) { if (MD->isInstance()) { - QualType thisType = clad_compat::CXXMethodDecl_getThisType(m_Sema, MD); + QualType thisType = MD->getThisType(); derivedParamTypes.push_back(thisType); } } @@ -447,7 +447,7 @@ BaseForwardModeVisitor::DerivePushforward(const FunctionDecl* FD, // `this` pointer with respect to the independent parameter. if (const auto* MFD = dyn_cast(FD)) { if (MFD->isInstance()) { - auto thisType = clad_compat::CXXMethodDecl_getThisType(m_Sema, MFD); + auto thisType = MFD->getThisType(); IdentifierInfo* derivedPVDII = CreateUniqueIdentifier("_d_this"); auto* derivedPVD = utils::BuildParmVarDecl(m_Sema, m_Sema.CurContext, derivedPVDII, thisType); @@ -857,14 +857,16 @@ BaseForwardModeVisitor::VisitArraySubscriptExpr(const ArraySubscriptExpr* ASE) { if (VD == m_IndependentVar) { llvm::APSInt index; Expr* diffExpr = nullptr; - - if (!clad_compat::Expr_EvaluateAsInt(clonedIndices.back(), index, - m_Context)) { + Expr::EvalResult res; + Expr::SideEffectsKind AllowSideEffects = + Expr::SideEffectsKind::SE_NoSideEffects; + if (!clonedIndices.back()->EvaluateAsInt(res, m_Context, + AllowSideEffects)) { diffExpr = BuildParens(BuildOp(BO_EQ, clonedIndices.back(), ConstantFolder::synthesizeLiteral( ExprTy, m_Context, m_IndependentVarIndex))); - } else if (index.getExtValue() == m_IndependentVarIndex) { + } else if (res.Val.getInt().getExtValue() == m_IndependentVarIndex) { diffExpr = ConstantFolder::synthesizeLiteral(ExprTy, m_Context, 1); } else { diffExpr = zero; @@ -1619,11 +1621,7 @@ static SwitchCase* getContainedSwitchCaseStmt(const CompoundStmt* CS) { /// Returns top switch statement in the `SwitchStack` of the given /// Function Scope. static SwitchStmt* getTopSwitchStmtOfSwitchStack(sema::FunctionScopeInfo* FSI) { -#if CLANG_VERSION_MAJOR < 7 - return FSI->SwitchStack.back(); -#elif CLANG_VERSION_MAJOR >= 7 return FSI->SwitchStack.back().getPointer(); -#endif } StmtDiff BaseForwardModeVisitor::VisitSwitchStmt(const SwitchStmt* SS) { @@ -1730,8 +1728,9 @@ BaseForwardModeVisitor::DeriveSwitchStmtBodyHelper(const Stmt* stmt, (newCaseSC->getLHS() ? Clone(newCaseSC->getLHS()) : nullptr); Expr* rhsClone = (newCaseSC->getRHS() ? Clone(newCaseSC->getRHS()) : nullptr); - newActiveSC = clad_compat::CaseStmt_Create( - 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); @@ -1870,20 +1869,20 @@ StmtDiff BaseForwardModeVisitor::VisitCXXTemporaryObjectExpr( clonedArgs.push_back(argDiff.getExpr()); derivedArgs.push_back(argDiff.getExpr_dx()); } - Expr* clonedTOE = m_Sema - .ActOnCXXTypeConstructExpr( - OpaquePtr::make(TOE->getType()), - utils::GetValidSLoc(m_Sema), clonedArgs, - utils::GetValidSLoc(m_Sema) - CLAD_COMPAT_IS_LIST_INITIALIZATION_PARAM(TOE)) - .get(); - Expr* derivedTOE = m_Sema - .ActOnCXXTypeConstructExpr( - OpaquePtr::make(TOE->getType()), - utils::GetValidSLoc(m_Sema), derivedArgs, - utils::GetValidSLoc(m_Sema) - CLAD_COMPAT_IS_LIST_INITIALIZATION_PARAM(TOE)) - .get(); + Expr* clonedTOE = + m_Sema + .ActOnCXXTypeConstructExpr(OpaquePtr::make(TOE->getType()), + utils::GetValidSLoc(m_Sema), clonedArgs, + utils::GetValidSLoc(m_Sema), + TOE->isListInitialization()) + .get(); + Expr* derivedTOE = + m_Sema + .ActOnCXXTypeConstructExpr(OpaquePtr::make(TOE->getType()), + utils::GetValidSLoc(m_Sema), derivedArgs, + utils::GetValidSLoc(m_Sema), + TOE->isListInitialization()) + .get(); return {clonedTOE, derivedTOE}; } @@ -1997,4 +1996,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 6144ae23a..adaf5d29b 100644 --- a/lib/Differentiator/CladUtils.cpp +++ b/lib/Differentiator/CladUtils.cpp @@ -77,10 +77,8 @@ namespace clad { return "operator_less_equal"; case OverloadedOperatorKind::OO_GreaterEqual: return "operator_greater_equal"; -#if CLANG_VERSION_MAJOR > 5 case OverloadedOperatorKind::OO_Spaceship: return "operator_spaceship"; -#endif case OverloadedOperatorKind::OO_AmpAmp: return "operator_AmpAmp"; case OverloadedOperatorKind::OO_PipePipe: @@ -166,7 +164,8 @@ namespace clad { utils::BuildNNS(semaRef, const_cast(declContext), CSS); NestedNameSpecifier* NS = CSS.getScopeRep(); if (auto* Prefix = NS->getPrefix()) - return C.getElaboratedType(ETK_None, Prefix, QT); + return C.getElaboratedType(clad_compat::ElaboratedTypeKeyword_None, + Prefix, QT); } return QT; } @@ -268,16 +267,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/DiffPlanner.cpp b/lib/Differentiator/DiffPlanner.cpp index 061d747a3..a86576d8e 100644 --- a/lib/Differentiator/DiffPlanner.cpp +++ b/lib/Differentiator/DiffPlanner.cpp @@ -463,7 +463,11 @@ namespace clad { // Case 2) // Check if the provided literal can be evaluated as an integral value. llvm::APSInt intValue; - if (clad_compat::Expr_EvaluateAsInt(E, intValue, C)) { + Expr::EvalResult res; + Expr::SideEffectsKind AllowSideEffects = + Expr::SideEffectsKind::SE_NoSideEffects; + if (E->EvaluateAsInt(res, C, AllowSideEffects)) { + intValue = res.Val.getInt(); DiffInputVarInfo dVarInfo; auto idx = intValue.getExtValue(); // If we are differentiating a call operator that have no parameters, then diff --git a/lib/Differentiator/HessianModeVisitor.cpp b/lib/Differentiator/HessianModeVisitor.cpp index ececdfbc7..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/ReverseModeForwPassVisitor.cpp b/lib/Differentiator/ReverseModeForwPassVisitor.cpp index 3d1a39290..cce53a594 100644 --- a/lib/Differentiator/ReverseModeForwPassVisitor.cpp +++ b/lib/Differentiator/ReverseModeForwPassVisitor.cpp @@ -109,7 +109,7 @@ ReverseModeForwPassVisitor::ComputeParamTypes(const DiffParams& diffParams) { if (const auto* MD = dyn_cast(m_Function)) { const CXXRecordDecl* RD = MD->getParent(); if (MD->isInstance() && !RD->isLambda()) { - QualType thisType = clad_compat::CXXMethodDecl_getThisType(m_Sema, MD); + QualType thisType = MD->getThisType(); paramTypes.push_back( GetParameterDerivativeType(effectiveReturnType, thisType)); } diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 9672ea190..e50a0ea80 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -2260,10 +2260,14 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, std::string DRE_str = DRE->getDecl()->getNameAsString(); llvm::APSInt intIdx; + Expr::EvalResult res; + Expr::SideEffectsKind AllowSideEffects = + Expr::SideEffectsKind::SE_NoSideEffects; auto isIdxValid = - clad_compat::Expr_EvaluateAsInt(ASE->getIdx(), intIdx, m_Context); + ASE->getIdx()->EvaluateAsInt(res, m_Context, AllowSideEffects); if (DRE_str == outputArrayStr && isIdxValid) { + intIdx = res.Val.getInt(); if (isVectorValued) { outputArrayCursor = intIdx.getExtValue(); @@ -3440,8 +3444,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 = clad_compat::CaseStmt_Create(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); @@ -3623,8 +3627,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, CaseStmt* ReverseModeVisitor::BreakContStmtHandler::GetNextCFCaseStmt() { ++m_CaseCounter; auto* counterLiteral = CreateSizeTLiteralExpr(m_CaseCounter); - CaseStmt* CS = clad_compat::CaseStmt_Create(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 @@ -3857,8 +3861,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, if (const auto* MD = dyn_cast(m_Function)) { const CXXRecordDecl* RD = MD->getParent(); if (MD->isInstance() && !RD->isLambda()) { - QualType thisType = - clad_compat::CXXMethodDecl_getThisType(m_Sema, MD); + QualType thisType = MD->getThisType(); paramTypes.push_back( GetParameterDerivativeType(effectiveReturnType, thisType)); } diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index 2a65e5b54..467b43e20 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -25,11 +25,10 @@ Stmt* StmtClone::Visit ## CLASS(CLASS *Node) \ return new (Ctx) CLASS CTORARGS; \ } -#define DEFINE_CLONE_STMT_CO(CLASS, CTORARGS) \ -Stmt* StmtClone::Visit ## CLASS(CLASS *Node) \ -{ \ - return CLAD_COMPAT_CREATE(CLASS, CTORARGS); \ -} +#define DEFINE_CLONE_STMT_CO(CLASS, CTORARGS) \ + Stmt* StmtClone::Visit##CLASS(CLASS* Node) { \ + return (CLASS::Create CTORARGS); \ + } #define DEFINE_CLONE_EXPR(CLASS, CTORARGS) \ Stmt* StmtClone::Visit ## CLASS(CLASS *Node) \ @@ -47,13 +46,12 @@ Stmt* StmtClone::Visit ## CLASS(CLASS *Node) \ return result; \ } -#define DEFINE_CLONE_EXPR_CO(CLASS, CTORARGS) \ -Stmt* StmtClone::Visit ## CLASS(CLASS *Node) \ -{ \ - CLASS* result = CLAD_COMPAT_CREATE(CLASS, CTORARGS); \ - clad_compat::ExprSetDeps(result, Node); \ - return result; \ -} +#define DEFINE_CLONE_EXPR_CO(CLASS, CTORARGS) \ + Stmt* StmtClone::Visit##CLASS(CLASS* Node) { \ + CLASS* result = (CLASS::Create CTORARGS); \ + clad_compat::ExprSetDeps(result, Node); \ + return result; \ + } #define DEFINE_CLONE_EXPR_CO11(CLASS, CTORARGS) \ Stmt* StmtClone::Visit ## CLASS(CLASS *Node) \ @@ -73,9 +71,8 @@ DEFINE_CLONE_EXPR_CO11( UnaryOperator, (CLAD_COMPAT_CLANG11_Ctx_ExtraParams Clone(Node->getSubExpr()), Node->getOpcode(), CloneType(Node->getType()), Node->getValueKind(), - Node->getObjectKind(), - Node->getOperatorLoc() CLAD_COMPAT_CLANG7_UnaryOperator_ExtraParams - CLAD_COMPAT_CLANG11_UnaryOperator_ExtraParams)) + Node->getObjectKind(), Node->getOperatorLoc(), + Node->canOverflow() CLAD_COMPAT_CLANG11_UnaryOperator_ExtraParams)) Stmt* StmtClone::VisitDeclRefExpr(DeclRefExpr *Node) { TemplateArgumentListInfo TAListInfo; Node->copyTemplateArgumentsInto(TAListInfo); @@ -91,8 +88,7 @@ DEFINE_CREATE_EXPR(IntegerLiteral, (Ctx, Node->getValue(), CloneType(Node->getType()), Node->getLocation())) DEFINE_CLONE_EXPR_CO(PredefinedExpr, - (CLAD_COMPAT_CLANG8_Ctx_ExtraParams Node->getLocation(), - CloneType(Node->getType()), + (Ctx, Node->getLocation(), CloneType(Node->getType()), Node->getIdentKind() CLAD_COMPAT_CLANG17_IsTransparent(Node), Node->getFunctionName())) @@ -176,10 +172,10 @@ DEFINE_CREATE_EXPR(CXXFunctionalCastExpr, Node->getLParenLoc(), Node->getRParenLoc())) DEFINE_CREATE_EXPR(ExprWithCleanups, (Ctx, Node->getSubExpr(), Node->cleanupsHaveSideEffects(), {})) -// clang <= 7 do not have `ConstantExpr` node. -#if CLANG_VERSION_MAJOR > 7 -DEFINE_CREATE_EXPR(ConstantExpr, (Ctx, Clone(Node->getSubExpr()) CLAD_COMPAT_ConstantExpr_Create_ExtraParams)) -#endif + +DEFINE_CREATE_EXPR(ConstantExpr, + (Ctx, Clone(Node->getSubExpr()) + CLAD_COMPAT_ConstantExpr_Create_ExtraParams)) DEFINE_CLONE_EXPR_CO( CXXTemporaryObjectExpr, @@ -235,7 +231,9 @@ DEFINE_CLONE_EXPR(CXXScalarValueInitExpr, DEFINE_CLONE_EXPR(ExtVectorElementExpr, (Node->getType(), Node->getValueKind(), Clone(Node->getBase()), Node->getAccessor(), Node->getAccessorLoc())) DEFINE_CLONE_EXPR(CXXBoolLiteralExpr, (Node->getValue(), Node->getType(), Node->getSourceRange().getBegin())) DEFINE_CLONE_EXPR(CXXNullPtrLiteralExpr, (Node->getType(), Node->getSourceRange().getBegin())) -DEFINE_CLONE_EXPR(CXXThisExpr, (Node->getSourceRange().getBegin(), Node->getType(), Node->isImplicit())) + +CLAD_COMPAT_CLANG17_CXXThisExpr_ExtraParam Node->getSourceRange().getBegin(), Node->getType(), Node->isImplicit())) + DEFINE_CLONE_EXPR(CXXThrowExpr, (Clone(Node->getSubExpr()), Node->getType(), Node->getThrowLoc(), Node->isThrownVariableInScope())) #if CLANG_VERSION_MAJOR < 16 DEFINE_CLONE_EXPR( @@ -333,18 +331,12 @@ Stmt* StmtClone::VisitUnresolvedLookupExpr(UnresolvedLookupExpr* Node) { TemplateArgumentListInfo TemplateArgs; if (Node->hasExplicitTemplateArgs()) Node->copyTemplateArgumentsInto(TemplateArgs); - Stmt* result = UnresolvedLookupExpr::Create(Ctx, - Node->getNamingClass(), - Node->getQualifierLoc(), - Node->getTemplateKeywordLoc(), - Node->getNameInfo(), - Node->requiresADL(), - // They get copied again by - // OverloadExpr, so we are safe. - &TemplateArgs, - Node->decls_begin(), - Node->decls_end() - ); + Stmt* result = clad_compat::UnresolvedLookupExpr_Create( + Ctx, Node->getNamingClass(), Node->getQualifierLoc(), + Node->getTemplateKeywordLoc(), Node->getNameInfo(), Node->requiresADL(), + // They get copied again by + // OverloadExpr, so we are safe. + &TemplateArgs, Node->decls_begin(), Node->decls_end()); return result; } @@ -353,11 +345,13 @@ Stmt* StmtClone::VisitCXXOperatorCallExpr(CXXOperatorCallExpr* Node) { for (Expr* arg : Node->arguments()) { clonedArgs.push_back(Clone(arg)); } - CXXOperatorCallExpr* result = clad_compat::CXXOperatorCallExpr_Create( + CallExpr::ADLCallKind UsesADL = CallExpr::NotADL; + CXXOperatorCallExpr* result = CXXOperatorCallExpr::Create( Ctx, Node->getOperator(), Clone(Node->getCallee()), clonedArgs, CloneType(Node->getType()), Node->getValueKind(), Node->getRParenLoc(), Node->getFPFeatures() - CLAD_COMPAT_CLANG11_CXXOperatorCallExpr_Create_ExtraParams); + CLAD_COMPAT_CLANG11_CXXOperatorCallExpr_Create_ExtraParamsUse); + //### result->setNumArgs(Ctx, Node->getNumArgs()); result->setNumArgsUnsafe(Node->getNumArgs()); for (unsigned i = 0, e = Node->getNumArgs(); i < e; ++i) @@ -399,11 +393,9 @@ Stmt* StmtClone::VisitShuffleVectorExpr(ShuffleVectorExpr* Node) { } Stmt* StmtClone::VisitCaseStmt(CaseStmt* Node) { - CaseStmt* result = clad_compat::CaseStmt_Create(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; } @@ -419,7 +411,8 @@ Stmt* StmtClone::VisitSwitchStmt(SwitchStmt* Node) { return result; } -DEFINE_CLONE_STMT_CO(ReturnStmt, (CLAD_COMPAT_CLANG8_Ctx_ExtraParams Node->getReturnLoc(), Clone(Node->getRetValue()), 0)) +DEFINE_CLONE_STMT_CO(ReturnStmt, + (Ctx, Node->getReturnLoc(), Clone(Node->getRetValue()), 0)) DEFINE_CLONE_STMT(DefaultStmt, (Node->getDefaultLoc(), Node->getColonLoc(), Clone(Node->getSubStmt()))) DEFINE_CLONE_STMT(GotoStmt, (Node->getLabel(), Node->getGotoLoc(), Node->getLabelLoc())) DEFINE_CLONE_STMT_CO(WhileStmt, (Ctx, CloneDeclOrNull(Node->getConditionVariable()), Clone(Node->getCond()), Clone(Node->getBody()), Node->getWhileLoc() CLAD_COMPAT_CLANG11_WhileStmt_ExtraParams)) diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index a12fa3c8b..a482c29ab 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -244,9 +244,9 @@ namespace clad { // For intermediate variables, use numbered names (_t0), for everything // else first try a name without number (e.g. first try to use _d_x and // use _d_x0 only if _d_x is taken). - bool countedName = nameBase.startswith("_") && - !nameBase.startswith("_d_") && - !nameBase.startswith("_delta_"); + bool countedName = nameBase.starts_with("_") && + !nameBase.starts_with("_d_") && + !nameBase.starts_with("_delta_"); std::size_t idx = 0; std::size_t& id = countedName ? m_idCtr[nameBase.str()] : idx; std::string idStr = countedName ? std::to_string(id) : ""; @@ -452,7 +452,8 @@ namespace clad { // Create elaborated type with namespace specifier, // i.e. class -> clad::class - return m_Context.getElaboratedType(ETK_None, NS, TT); + return m_Context.getElaboratedType(clad_compat::ElaboratedTypeKeyword_None, + NS, TT); } QualType VisitorBase::InstantiateTemplate(TemplateDecl* CladClassDecl, diff --git a/test/Arrays/ArrayInputsReverseMode.C b/test/Arrays/ArrayInputsReverseMode.C index d16e3da42..618dc8874 100644 --- a/test/Arrays/ArrayInputsReverseMode.C +++ b/test/Arrays/ArrayInputsReverseMode.C @@ -224,8 +224,12 @@ double func4(double x) { //CHECK-NEXT: } double func5(int k) { + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wunknown-warning-option" + #pragma clang diagnostic ignored "-Wvla-cxx-extension" int n = k; double arr[n]; + #pragma clang diagnostic pop for (int i = 0; i < n; i++) { arr[i] = k; } diff --git a/test/FirstDerivative/ClassMethodCall.C b/test/FirstDerivative/ClassMethodCall.C index bdf3fd64f..33dd28263 100644 --- a/test/FirstDerivative/ClassMethodCall.C +++ b/test/FirstDerivative/ClassMethodCall.C @@ -1,5 +1,7 @@ // RUN: %cladclang %s -I%S/../../include -oClassMethods.out 2>&1 | FileCheck %s // RUN: ./ClassMethods.out | FileCheck -check-prefix=CHECK-EXEC %s +// Fails on clang-18 due to https://github.com/llvm/llvm-project/issues/87151 +// XFAIL: clang-18 //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" @@ -15,7 +17,7 @@ public: return x; } - //CHECK: int f_darg0(int x) __attribute__((always_inline)) { + //CHECK:{{[__attribute__((always_inline)) ]*}}int f_darg0(int x){{[ __attribute__((always_inline))]*}} { //CHECK-NEXT: int _d_x = 1; //CHECK-NEXT: A _d_this_obj; //CHECK-NEXT: A *_d_this = &_d_this_obj; diff --git a/test/FirstDerivative/VirtualMethodsCall.C b/test/FirstDerivative/VirtualMethodsCall.C index 606625a5d..8ce06a8f9 100644 --- a/test/FirstDerivative/VirtualMethodsCall.C +++ b/test/FirstDerivative/VirtualMethodsCall.C @@ -1,6 +1,8 @@ // RUN: %cladclang %s -I%S/../../include -oVirtualMethodsCall.out 2>&1 | FileCheck %s // RUN: ./VirtualMethodsCall.out | FileCheck -check-prefix=CHECK-EXEC %s // XFAIL: asserts +// Fails on clang-18 due to https://github.com/llvm/llvm-project/issues/87151 +// XFAIL: clang-18 //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index 16a464404..e5a84b99e 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -16,7 +16,7 @@ __attribute__((always_inline)) double f_add1(double x, double y) { return x + y; } -//CHECK: void f_add1_grad(double x, double y, double *_d_x, double *_d_y) __attribute__((always_inline)) { +//CHECK: {{[__attribute__((always_inline))]*}}void f_add1_grad(double x, double y, double *_d_x, double *_d_y){{[ __attribute__((always_inline))]*}} { //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: //CHECK-NEXT: { diff --git a/test/Hessian/Hessians.C b/test/Hessian/Hessians.C index c13960318..de90a68d5 100644 --- a/test/Hessian/Hessians.C +++ b/test/Hessian/Hessians.C @@ -10,9 +10,16 @@ __attribute__((always_inline)) double f_cubed_add1(double a, double b) { return a * a * a + b * b * b; } +//CHECK:{{[__attribute__((always_inline)) ]*}}double f_cubed_add1_darg0(double a, double b){{[ __attribute__((always_inline))]*}} { +//CHECK-NEXT: double _d_a = 1; +//CHECK-NEXT: double _d_b = 0; +//CHECK-NEXT: double _t0 = a * a; +//CHECK-NEXT: double _t1 = b * b; +//CHECK-NEXT: return (_d_a * a + a * _d_a) * a + _t0 * _d_a + (_d_b * b + b * _d_b) * b + _t1 * _d_b; +//CHECK-NEXT:} void f_cubed_add1_darg0_grad(double a, double b, double *_d_a, double *_d_b); -//CHECK:void f_cubed_add1_darg0_grad(double a, double b, double *_d_a, double *_d_b) __attribute__((always_inline)) { +//CHECK:{{[__attribute__((always_inline)) ]*}}void f_cubed_add1_darg0_grad(double a, double b, double *_d_a, double *_d_b){{[ __attribute__((always_inline))]*}} { //CHECK-NEXT: double _d__d_a = 0; //CHECK-NEXT: double _d__d_b = 0; //CHECK-NEXT: double _d__t0 = 0; @@ -50,7 +57,7 @@ void f_cubed_add1_darg0_grad(double a, double b, double *_d_a, double *_d_b); //CHECK-NEXT:} void f_cubed_add1_darg1_grad(double a, double b, double *_d_a, double *_d_b); -//CHECK:void f_cubed_add1_darg1_grad(double a, double b, double *_d_a, double *_d_b) __attribute__((always_inline)) { +//CHECK:{{[__attribute__((always_inline)) ]*}}void f_cubed_add1_darg1_grad(double a, double b, double *_d_a, double *_d_b){{[ __attribute__((always_inline))]*}} { //CHECK-NEXT: double _d__d_a = 0; //CHECK-NEXT: double _d__d_b = 0; //CHECK-NEXT: double _d__t0 = 0; @@ -88,7 +95,7 @@ void f_cubed_add1_darg1_grad(double a, double b, double *_d_a, double *_d_b); //CHECK-NEXT:} void f_cubed_add1_hessian(double a, double b, double *hessianMatrix); -//CHECK: void f_cubed_add1_hessian(double a, double b, double *hessianMatrix) __attribute__((always_inline)) { +//CHECK:{{[__attribute__((always_inline)) ]*}}void f_cubed_add1_hessian(double a, double b, double *hessianMatrix){{[ __attribute__((always_inline))]*}} { //CHECK-NEXT: f_cubed_add1_darg0_grad(a, b, hessianMatrix + {{0U|0UL}}, hessianMatrix + {{1U|1UL}}); //CHECK-NEXT: f_cubed_add1_darg1_grad(a, b, hessianMatrix + {{2U|2UL}}, hessianMatrix + {{3U|3UL}}); //CHECK-NEXT: } diff --git a/tools/ClangPlugin.cpp b/tools/ClangPlugin.cpp index 9453e3c16..23c416385 100644 --- a/tools/ClangPlugin.cpp +++ b/tools/ClangPlugin.cpp @@ -79,7 +79,7 @@ namespace clad { // Find the path to clad. llvm::StringRef CladSoPath; for (llvm::StringRef P : Opts.Plugins) - if (llvm::sys::path::stem(P).endswith("clad")) { + if (llvm::sys::path::stem(P).ends_with("clad")) { CladSoPath = P; break; }