Skip to content

Commit

Permalink
Change first supported version to 7.0. Clean pre-clang 7 compat fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-penev authored and vgvassilev committed Jan 1, 2024
1 parent 3fa7fb6 commit dbc4d21
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 4 additions & 41 deletions include/clad/Differentiator/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Stmt *> 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) /**/
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion lib/Differentiator/CladUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
21 changes: 6 additions & 15 deletions lib/Differentiator/VisitorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NamespaceDecl>(CladR.getFoundDecl());
Expand All @@ -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<TemplateDecl>(TapeR.getFoundDecl()) &&
"cannot find clad::tape");
Expand Down
2 changes: 1 addition & 1 deletion tools/ClangPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit dbc4d21

Please sign in to comment.