From 171bd92e3163f3f804c0d4952b8f3cc105bcfedf Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Fri, 29 Dec 2023 17:53:47 +0000 Subject: [PATCH 1/2] Add old, still supported versions in CI matrix --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c683dd5c..5867bdf10 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -403,6 +403,19 @@ jobs: os: ubuntu-22.04 compiler: clang-16 clang-runtime: '17' + + # Оld, still supported versions + + - name: ubu20-gcc9-runtime7 + os: ubuntu-20.04 + compiler: gcc-9 + clang-runtime: '7' + + - name: ubu20-gcc9-runtime8 + os: ubuntu-20.04 + compiler: gcc-9 + clang-runtime: '8' + steps: - uses: actions/checkout@v3 with: From d906af676b52056667ec8af74f23a439d257f877 Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Sat, 30 Dec 2023 11:54:46 +0000 Subject: [PATCH 2/2] Change first supported version to 7.0. Clean pre-clang 7 compat fixes. --- README.md | 2 +- include/clad/Differentiator/Compatibility.h | 45 ++------------------- lib/Differentiator/CladUtils.cpp | 2 +- lib/Differentiator/VisitorBase.cpp | 21 +++------- tools/ClangPlugin.cpp | 2 +- 5 files changed, 13 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index bd13047f4..4b05524a2 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 5.0.x - 17.0.x are supported. +At the moment, LLVM/Clang 7.0.x - 17.0.x are supported. ### Conda Installation diff --git a/include/clad/Differentiator/Compatibility.h b/include/clad/Differentiator/Compatibility.h index 0ac2dcbdc..62d71641c 100644 --- a/include/clad/Differentiator/Compatibility.h +++ b/include/clad/Differentiator/Compatibility.h @@ -21,33 +21,17 @@ namespace clad_compat { using namespace clang; using namespace llvm; -// Compatibility helper function for creation CompoundStmt. Clang 6 and above use Create. -// Clang 15 +// Compatibility helper function for creation CompoundStmt. // Clang 15 and above use a extra param FPFeatures in CompoundStmt::Create. static inline bool SourceManager_isPointWithin(const SourceManager& SM, SourceLocation Loc, SourceLocation B, SourceLocation E) { -#if CLANG_VERSION_MAJOR == 5 - return Loc == B || Loc == E || (SM.isBeforeInTranslationUnit(B, Loc) && - SM.isBeforeInTranslationUnit(Loc, E)); -#elif CLANG_VERSION_MAJOR >= 6 return SM.isPointWithin(Loc, B, E); -#endif } -#if CLANG_VERSION_MAJOR == 5 -#define CLAD_COMPAT_CLANG15_CompoundStmt_Create_ExtraParam(Node) /**/ -#define CLAD_COMPAT_CLANG15_CompoundStmt_Create_ExtraParam1(CS) /**/ -#define CLAD_COMPAT_CLANG15_CompoundStmt_Create_ExtraParam2(FP) /**/ -static inline CompoundStmt* CompoundStmt_Create( - const ASTContext &Ctx, ArrayRef Stmts, - SourceLocation LB, SourceLocation RB) -{ - return new (Ctx) CompoundStmt(Ctx, Stmts, LB, RB); -} -#elif CLANG_VERSION_MAJOR < 15 +#if CLANG_VERSION_MAJOR < 15 #define CLAD_COMPAT_CLANG15_CompoundStmt_Create_ExtraParam(Node) /**/ #define CLAD_COMPAT_CLANG15_CompoundStmt_Create_ExtraParam1(CS) /**/ #define CLAD_COMPAT_CLANG15_CompoundStmt_Create_ExtraParam2(FP) /**/ @@ -87,31 +71,10 @@ NamespaceDecl_Create(ASTContext& C, DeclContext* DC, bool Inline, } #endif -// Clang 6 rename Sema::ForRedeclaration to Sema::ForVisibleRedeclaration - -#if CLANG_VERSION_MAJOR == 5 - const auto Sema_ForVisibleRedeclaration = Sema::ForRedeclaration; -#elif CLANG_VERSION_MAJOR >= 6 - const auto Sema_ForVisibleRedeclaration = Sema::ForVisibleRedeclaration; -#endif - - -// Clang 6 rename Declarator to DeclaratorContext, but Declarator is used -// as name for another class. - -#if CLANG_VERSION_MAJOR == 5 - using DeclaratorContext = Declarator; -#elif CLANG_VERSION_MAJOR >= 6 - using DeclaratorContext = DeclaratorContext; -#endif - - // Clang 7 add one extra param in UnaryOperator constructor. -#if CLANG_VERSION_MAJOR < 7 - #define CLAD_COMPAT_CLANG7_UnaryOperator_ExtraParams /**/ -#elif CLANG_VERSION_MAJOR >= 7 - #define CLAD_COMPAT_CLANG7_UnaryOperator_ExtraParams ,Node->canOverflow() +#if CLANG_VERSION_MAJOR >= 7 +#define CLAD_COMPAT_CLANG7_UnaryOperator_ExtraParams , Node->canOverflow() #endif diff --git a/lib/Differentiator/CladUtils.cpp b/lib/Differentiator/CladUtils.cpp index a49d52477..44d64c744 100644 --- a/lib/Differentiator/CladUtils.cpp +++ b/lib/Differentiator/CladUtils.cpp @@ -243,7 +243,7 @@ namespace clad { // Find the builtin derivatives/numerical diff namespace DeclarationName Name = &C.Idents.get(namespc); LookupResult R(S, Name, SourceLocation(), Sema::LookupNamespaceName, - clad_compat::Sema_ForVisibleRedeclaration); + Sema::ForVisibleRedeclaration); S.LookupQualifiedName(R, DC, /*allowBuiltinCreation*/ false); if (!shouldExist && R.empty()) diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 3de0394e9..e50cfca7a 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -168,11 +168,8 @@ namespace clad { NamespaceDecl* PrevNS = nullptr; // From Sema::ActOnStartNamespaceDef: if (II) { - LookupResult R(m_Sema, - II, - noLoc, - Sema::LookupOrdinaryName, - clad_compat::Sema_ForVisibleRedeclaration); + LookupResult R(m_Sema, II, noLoc, Sema::LookupOrdinaryName, + Sema::ForVisibleRedeclaration); m_Sema.LookupQualifiedName(R, m_Sema.CurContext->getRedeclContext()); NamedDecl* FoundDecl = R.isSingleResult() ? R.getRepresentativeDecl() : nullptr; @@ -423,11 +420,8 @@ namespace clad { if (Result) return Result; DeclarationName CladName = &m_Context.Idents.get("clad"); - LookupResult CladR(m_Sema, - CladName, - noLoc, - Sema::LookupNamespaceName, - clad_compat::Sema_ForVisibleRedeclaration); + LookupResult CladR(m_Sema, CladName, noLoc, Sema::LookupNamespaceName, + Sema::ForVisibleRedeclaration); m_Sema.LookupQualifiedName(CladR, m_Context.getTranslationUnitDecl()); assert(!CladR.empty() && "cannot find clad namespace"); Result = cast(CladR.getFoundDecl()); @@ -440,11 +434,8 @@ namespace clad { CXXScopeSpec CSS; CSS.Extend(m_Context, CladNS, noLoc, noLoc); DeclarationName TapeName = &m_Context.Idents.get(ClassName); - LookupResult TapeR(m_Sema, - TapeName, - noLoc, - Sema::LookupUsingDeclName, - clad_compat::Sema_ForVisibleRedeclaration); + LookupResult TapeR(m_Sema, TapeName, noLoc, Sema::LookupUsingDeclName, + Sema::ForVisibleRedeclaration); m_Sema.LookupQualifiedName(TapeR, CladNS, CSS); assert(!TapeR.empty() && isa(TapeR.getFoundDecl()) && "cannot find clad::tape"); diff --git a/tools/ClangPlugin.cpp b/tools/ClangPlugin.cpp index 70e39aa1b..c4ab7039a 100644 --- a/tools/ClangPlugin.cpp +++ b/tools/ClangPlugin.cpp @@ -330,7 +330,7 @@ namespace clad { DeclarationName Name = &C.Idents.get("clad"); Sema &SemaR = m_CI.getSema(); LookupResult R(SemaR, Name, SourceLocation(), Sema::LookupNamespaceName, - clad_compat::Sema_ForVisibleRedeclaration); + Sema::ForVisibleRedeclaration); SemaR.LookupQualifiedName(R, C.getTranslationUnitDecl(), /*allowBuiltinCreation*/ false); m_HasRuntime = !R.empty();