Skip to content

Commit

Permalink
Add LLVM/Clang 17 support
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-penev authored and vgvassilev committed Sep 19, 2023
1 parent 71dd694 commit 4bc0d63
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
## Define clad supported version of clang and llvm

set(CLANG_MIN_SUPPORTED 5.0)
set(CLANG_MAX_SUPPORTED "16.0.x")
set(CLANG_VERSION_UPPER_BOUND 16.1.0)
set(CLANG_MAX_SUPPORTED "17.0.x")
set(CLANG_VERSION_UPPER_BOUND 17.1.0)
set(LLVM_MIN_SUPPORTED 5.0)
set(LLVM_MAX_SUPPORTED "16.0.x")
set(LLVM_VERSION_UPPER_BOUND 16.1.0)
set(LLVM_MAX_SUPPORTED "17.0.x")
set(LLVM_VERSION_UPPER_BOUND 17.1.0)

if (NOT DEFINED Clang_DIR)
set(Clang_DIR ${LLVM_DIR})
Expand Down
22 changes: 22 additions & 0 deletions include/clad/Differentiator/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -767,5 +767,27 @@ static inline bool IsPRValue(const Expr* E) { return E->isPRValue(); }
,Fn->isThisDeclarationADefinition()
#endif


// Clang 17 change type of last param of ActOnStartOfLambdaDefinition
// from Scope* to 'const DeclSpec&'
#if CLANG_VERSION_MAJOR < 17
static inline Scope* Sema_ActOnStartOfLambdaDefinition_ScopeOrDeclSpec(Scope *CurScope, const DeclSpec &DS) {
return CurScope;
}
#elif CLANG_VERSION_MAJOR >= 17
static inline const DeclSpec& Sema_ActOnStartOfLambdaDefinition_ScopeOrDeclSpec(Scope *CurScope, const DeclSpec &DS) {
return DS;
}
#endif

// Clang 17 add one extra param to clang::PredefinedExpr::Create - isTransparent

#if CLANG_VERSION_MAJOR < 17
#define CLAD_COMPAT_CLANG17_IsTransparent(Node) /**/
#elif CLANG_VERSION_MAJOR >= 17
#define CLAD_COMPAT_CLANG17_IsTransparent(Node) \
,Node->isTransparent()
#endif

} // namespace clad_compat
#endif //CLAD_COMPATIBILITY
3 changes: 2 additions & 1 deletion include/clad/Differentiator/VisitorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ namespace clad {
S.PushLambdaScope();
V.beginScope(clang::Scope::BlockScope | clang::Scope::FnScope |
clang::Scope::DeclScope);
S.ActOnStartOfLambdaDefinition(Intro, D, V.getCurrentScope());
S.ActOnStartOfLambdaDefinition(Intro, D,
clad_compat::Sema_ActOnStartOfLambdaDefinition_ScopeOrDeclSpec(V.getCurrentScope(), DS));
V.beginBlock();
func();
clang::CompoundStmt* body = V.endBlock();
Expand Down
2 changes: 1 addition & 1 deletion lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Stmt* StmtClone::VisitDeclRefExpr(DeclRefExpr *Node) {
return DeclRefExpr::Create(Ctx, Node->getQualifierLoc(), Node->getTemplateKeywordLoc(), Node->getDecl(), Node->refersToEnclosingVariableOrCapture(), Node->getNameInfo(), Node->getType(), Node->getValueKind(), Node->getFoundDecl(), &TAListInfo);
}
DEFINE_CREATE_EXPR(IntegerLiteral, (Ctx, Node->getValue(), Node->getType(), Node->getLocation()))
DEFINE_CLONE_EXPR_CO(PredefinedExpr, (CLAD_COMPAT_CLANG8_Ctx_ExtraParams Node->getLocation(), Node->getType(), Node->getIdentKind(), Node->getFunctionName()))
DEFINE_CLONE_EXPR_CO(PredefinedExpr, (CLAD_COMPAT_CLANG8_Ctx_ExtraParams Node->getLocation(), Node->getType(), Node->getIdentKind() CLAD_COMPAT_CLANG17_IsTransparent(Node), Node->getFunctionName()))
DEFINE_CLONE_EXPR(CharacterLiteral, (Node->getValue(), Node->getKind(), Node->getType(), Node->getLocation()))
DEFINE_CLONE_EXPR(ImaginaryLiteral, (Clone(Node->getSubExpr()), Node->getType()))
DEFINE_CLONE_EXPR(ParenExpr, (Node->getLParen(), Node->getRParen(), Clone(Node->getSubExpr())))
Expand Down
3 changes: 3 additions & 0 deletions tools/ClangBackendPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Pass.h"
#include "llvm/PassRegistry.h"

#if LLVM_VERSION_MAJOR >= 10 && LLVM_VERSION_MAJOR < 16
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#endif // LLVM_VERSION_MAJOR >= 10 && LLVM_VERSION_MAJOR < 16

namespace clad {
using namespace llvm;
Expand Down

0 comments on commit 4bc0d63

Please sign in to comment.