Skip to content

Commit

Permalink
LLVM/Clang 10 support. Compatibility fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-penev authored and vgvassilev committed Sep 13, 2020
1 parent 9401215 commit 72b4c6d
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 8 deletions.
111 changes: 110 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ addons: &common-addons
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
homebrew: &common-brew
packages: &common-brew-packages
- ccache
Expand Down Expand Up @@ -166,6 +170,23 @@ addons-9: &addons-9
]
update: true

addons-10: &addons-10
<<: *common-addons
apt: &apt-10
<<: *common-apt
packages: &apt-packages-10 [*common-apt-packages,
'clang-10',
'libclang-10-dev',
'llvm-10-tools',
'llvm-10-dev'
]
homebrew: &brew-10
<<: *common-brew
packages: &brew-packages-10 [*common-brew-packages,
'llvm' #llvm@10
]
update: true


before_cache:
- brew cleanup
Expand Down Expand Up @@ -295,7 +316,6 @@ jobs:
- sourceline: 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'


##################### Clad for clang 6.0 #####################
# OSX 10.13, Clang and XCode 9.4
- os: osx
Expand Down Expand Up @@ -582,6 +602,95 @@ jobs:
<<: *apt-9
packages: [*apt-packages-9, 'clang-9', 'llvm-9-tools', 'g++-multilib', 'libc6-dbg']

##################### Clad for clang 10 #####################
# OSX 10.13, Clang and XCode 9.4
- os: osx
env: CLANG_RUNTIME=10 CXX=clang++ CC=clang
osx_image: xcode9.4
compiler: clang
addons:
<<: *addons-10

# Ubuntu, GCC 5
- env: CLANG_RUNTIME=10 CXX=g++-5 CC=gcc
compiler: gcc
dist: bionic
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'g++-5', 'g++-5-multilib', 'libc6-dbg']

# GCC 6 Code Coverage
- env: CLANG_RUNTIME=10 CODE_COVERAGE=1 CXX=g++-6 CC=gcc BUILD_TYPE=Debug
compiler: gcc
dist: bionic
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'g++-6', 'g++-6-multilib', 'libc6-dbg']

# GCC 8
- env: CLANG_RUNTIME=10 CXX=g++-8 CC=gcc
compiler: gcc
dist: bionic
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'g++-8', 'g++-8-multilib', 'libc6-dbg']

# GCC 9
- env: CLANG_RUNTIME=10 CXX=g++-9 CC=gcc
compiler: gcc
dist: bionic
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'g++-9', 'g++-9-multilib', 'libc6-dbg']

# Clang 4
- env: CLANG_RUNTIME=10 CXX=clang++-4.0 CC=clang-4.0
compiler: clang
dist: bionic
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'clang-4.0', 'llvm-4.0-tools', 'g++-multilib', 'libc6-dbg']

# Clang 8
- env: CLANG_RUNTIME=10 CXX=clang++-8 CC=clang-8
dist: bionic
compiler: clang
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'clang-8', 'g++-multilib', 'libc6-dbg']

# Clang 9
- env: CLANG_RUNTIME=10 CXX=clang++-9 CC=clang-9
dist: bionic
compiler: clang
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'clang-9', 'llvm-9-tools', 'g++-multilib', 'libc6-dbg']

# Clang 10
- env: CLANG_RUNTIME=10 CXX=clang++-10 CC=clang-10
dist: bionic
compiler: clang
addons:
<<: *addons-10
apt:
<<: *apt-10
packages: [*apt-packages-10, 'clang-10', 'llvm-10-tools', 'g++-multilib', 'libc6-dbg']


before_install:
- export
Expand Down
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ 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 9.0.1)
set(CLANG_MAX_SUPPORTED 10.0.1)
set(LLVM_MIN_SUPPORTED 5.0)
set(LLVM_MAX_SUPPORTED 9.0.1)
set(LLVM_MAX_SUPPORTED 10.0.1)

if (NOT DEFINED Clang_DIR)
set(Clang_DIR ${LLVM_DIR})
Expand Down Expand Up @@ -120,6 +120,16 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
message(STATUS "Found supported version: Clang ${CLANG_PACKAGE_VERSION}")
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")

## Clang 10 test
if (CLANG_VERSION_MAJOR GREATER_EQUAL 10)
if (NOT CMAKE_CXX_STANDARD)
set (CMAKE_CXX_STANDARD 14)
endif()
if (CMAKE_CXX_STANDARD LESS 14)
message(fatal "LLVM/Clad requires c++14 or later")
endif()
endif()

# When clad is in debug mode the llvm package thinks it is built with -frtti.
# For consistency we should set it to the correct value.
set(LLVM_CONFIG_HAS_RTTI NO CACHE BOOL "" FORCE)
Expand Down
24 changes: 24 additions & 0 deletions include/clad/Differentiator/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,30 @@ static inline QualType getConstantArrayType(const ASTContext &Ctx,
#endif
}

// Clang 10 add new last param TrailingRequiresClause in FunctionDecl::Create

#if CLANG_VERSION_MAJOR < 10
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) /**/
#elif CLANG_VERSION_MAJOR >= 10
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) ,((x)?Clone((x)):nullptr)
#endif

// Clang 10 remove GetTemporaryExpr(). Use getSubExpr() instead

#if CLANG_VERSION_MAJOR < 10
#define CLAD_COMPAT_CLANG10_GetTemporaryExpr(x) (x)->GetTemporaryExpr()
#elif CLANG_VERSION_MAJOR >= 10
#define CLAD_COMPAT_CLANG10_GetTemporaryExpr(x) (x)->getSubExpr()?Clone((x)->getSubExpr()):nullptr
#endif

// Clang 10 add one param to StmtExpr constructor: unsigned TemplateDepth

#if CLANG_VERSION_MAJOR < 10
#define CLAD_COMPAT_CLANG10_StmtExpr_Create_ExtraParams /**/
#elif CLANG_VERSION_MAJOR >= 10
#define CLAD_COMPAT_CLANG10_StmtExpr_Create_ExtraParams ,Node->getTemplateDepth()
#endif


} // namespace clad_compat

Expand Down
12 changes: 9 additions & 3 deletions lib/Differentiator/DerivativeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ namespace clad {
m_Function->getStorageClass(),
m_Function->isInlineSpecified(),
m_Function->hasWrittenPrototype(),
clad_compat::Function_GetConstexprKind(m_Function));
clad_compat::Function_GetConstexprKind(m_Function)
CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(m_Function->getTrailingRequiresClause())
);
} else {
diag(DiagnosticsEngine::Error, m_Function->getEndLoc(),
"attempted differentiation of '%0' which is of unsupported type",
Expand Down Expand Up @@ -728,7 +730,9 @@ namespace clad {
/*default*/
FD->isInlineSpecified(),
FD->hasWrittenPrototype(),
clad_compat::Function_GetConstexprKind(FD));
clad_compat::Function_GetConstexprKind(FD)
CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(FD->getTrailingRequiresClause())
);
}
m_Derivative = derivedFD;

Expand Down Expand Up @@ -1843,7 +1847,9 @@ namespace clad {
m_Function->getStorageClass(),
m_Function->isInlineSpecified(),
m_Function->hasWrittenPrototype(),
clad_compat::Function_GetConstexprKind(m_Function));
clad_compat::Function_GetConstexprKind(m_Function)
CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(m_Function->getTrailingRequiresClause())
);
} else {
diag(DiagnosticsEngine::Error, m_Function->getEndLoc(),
"attempted differentiation of '%0' which is of unsupported type",
Expand Down
4 changes: 2 additions & 2 deletions lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ DEFINE_CREATE_EXPR(CXXFunctionalCastExpr, (Ctx, Node->getType(), Node->getValueK

DEFINE_CLONE_EXPR_CO(CXXTemporaryObjectExpr, (Ctx, Node->getConstructor(), Node->getType(), Node->getTypeSourceInfo(), llvm::makeArrayRef(Node->getArgs(), Node->getNumArgs()), Node->getSourceRange(), Node->hadMultipleCandidates(), Node->isListInitialization(), Node->isStdInitListInitialization(), Node->requiresZeroInitialization()))

DEFINE_CLONE_EXPR(MaterializeTemporaryExpr, (Node->getType(), Clone(Node->GetTemporaryExpr()), Node->isBoundToLvalueReference()))
DEFINE_CLONE_EXPR(MaterializeTemporaryExpr, (Node->getType(), CLAD_COMPAT_CLANG10_GetTemporaryExpr(Node), Node->isBoundToLvalueReference()))
DEFINE_CLONE_EXPR(CompoundAssignOperator, (Clone(Node->getLHS()), Clone(Node->getRHS()), Node->getOpcode(), Node->getType(),
Node->getValueKind(), Node->getObjectKind(), Node->getComputationLHSType(), Node->getComputationResultType(), Node->getOperatorLoc(), Node->getFPFeatures()))
DEFINE_CLONE_EXPR(ConditionalOperator, (Clone(Node->getCond()), Node->getQuestionLoc(), Clone(Node->getLHS()), Node->getColonLoc(), Clone(Node->getRHS()), Node->getType(), Node->getValueKind(), Node->getObjectKind()))
DEFINE_CLONE_EXPR(AddrLabelExpr, (Node->getAmpAmpLoc(), Node->getLabelLoc(), Node->getLabel(), Node->getType()))
DEFINE_CLONE_EXPR(StmtExpr, (Clone(Node->getSubStmt()), Node->getType(), Node->getLParenLoc(), Node->getRParenLoc()))
DEFINE_CLONE_EXPR(StmtExpr, (Clone(Node->getSubStmt()), Node->getType(), Node->getLParenLoc(), Node->getRParenLoc() CLAD_COMPAT_CLANG10_StmtExpr_Create_ExtraParams ))
DEFINE_CLONE_EXPR(ChooseExpr, (Node->getBuiltinLoc(), Clone(Node->getCond()), Clone(Node->getLHS()), Clone(Node->getRHS()), Node->getType(), Node->getValueKind(), Node->getObjectKind(), Node->getRParenLoc(), Node->isConditionTrue(), Node->isTypeDependent(), Node->isValueDependent()))
DEFINE_CLONE_EXPR(GNUNullExpr, (Node->getType(), Node->getTokenLocation()))
DEFINE_CLONE_EXPR(VAArgExpr, (Node->getBuiltinLoc(), Clone(Node->getSubExpr()), Node->getWrittenTypeInfo(), Node->getRParenLoc(), Node->getType(), Node->isMicrosoftABI()))
Expand Down

0 comments on commit 72b4c6d

Please sign in to comment.