Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LLVM/Clang 17 support #629

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: unused function 'Sema_ActOnStartOfLambdaDefinition_ScopeOrDeclSpec' [clang-diagnostic-unused-function]

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
Loading