Skip to content

Commit 34186d6

Browse files
authored
Make CppInterOp work with llvm 19 (#312)
1 parent cff06c7 commit 34186d6

File tree

8 files changed

+153
-34
lines changed

8 files changed

+153
-34
lines changed

.github/workflows/ci.yml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
include:
24+
- name: ubu22-x86-gcc12-clang-repl-19
25+
os: ubuntu-22.04
26+
compiler: gcc-12
27+
clang-runtime: '19'
28+
cling: Off
29+
cppyy: On
30+
coverage: true
2431
- name: ubu22-x86-gcc12-clang-repl-18
2532
os: ubuntu-22.04
2633
compiler: gcc-12
@@ -50,6 +57,12 @@ jobs:
5057
cling-version: '1.0'
5158
cppyy: On
5259
coverage: true
60+
- name: win2022-msvc-clang-repl-19
61+
os: windows-2022
62+
compiler: msvc
63+
clang-runtime: '19'
64+
cling: Off
65+
cppyy: Off
5366
- name: win2022-msvc-clang-repl-18
5467
os: windows-2022
5568
compiler: msvc
@@ -75,6 +88,12 @@ jobs:
7588
cling: On
7689
cling-version: '1.0'
7790
cppyy: Off
91+
- name: osx14-arm-clang-clang-repl-19
92+
os: macos-14
93+
compiler: clang
94+
clang-runtime: '19'
95+
cling: Off
96+
cppyy: On
7897
- name: osx14-arm-clang-clang-repl-18
7998
os: macos-14
8099
compiler: clang
@@ -100,6 +119,12 @@ jobs:
100119
cling: On
101120
cling-version: '1.0'
102121
cppyy: On
122+
- name: osx13-x86-clang-clang-repl-19
123+
os: macos-13
124+
compiler: clang
125+
clang-runtime: '19'
126+
cling: Off
127+
cppyy: On
103128
- name: osx13-x86-clang-clang-repl-18
104129
os: macos-13
105130
compiler: clang
@@ -350,7 +375,7 @@ jobs:
350375
else
351376
# Apply patches
352377
llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]')
353-
if [[ "${llvm_vers}" != "18" ]]; then
378+
if [[ "${llvm_vers}" == "16" ]]||[[ "${llvm_vers}" == "17" ]]; then
354379
git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch
355380
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
356381
fi
@@ -470,6 +495,13 @@ jobs:
470495
fail-fast: false
471496
matrix:
472497
include:
498+
- name: ubu22-x86-gcc12-clang-repl-19-cppyy
499+
os: ubuntu-22.04
500+
compiler: gcc-12
501+
clang-runtime: '19'
502+
cling: Off
503+
cppyy: On
504+
coverage: true
473505
- name: ubu22-x86-gcc12-clang-repl-18-cppyy
474506
os: ubuntu-22.04
475507
compiler: gcc-12
@@ -498,6 +530,12 @@ jobs:
498530
cppyy: On
499531
#FIXME: Windows CppInterOp tests expected to fail
500532
#until https://github.com/compiler-research/CppInterOp/issues/188 is solved
533+
- name: win2022-msvc-clang-repl-19
534+
os: windows-2022
535+
compiler: msvc
536+
clang-runtime: '19'
537+
cling: Off
538+
cppyy: Off
501539
- name: win2022-msvc-clang-repl-18
502540
os: windows-2022
503541
compiler: msvc
@@ -542,6 +580,12 @@ jobs:
542580
# cling: On
543581
# cling-version: '1.0'
544582
# cppyy: On
583+
- name: osx14-arm-clang-clang-repl-19-cppyy
584+
os: macos-14
585+
compiler: clang
586+
clang-runtime: '19'
587+
cling: Off
588+
cppyy: On
545589
- name: osx14-arm-clang-clang-repl-18-cppyy
546590
os: macos-14
547591
compiler: clang
@@ -567,6 +611,12 @@ jobs:
567611
cling: On
568612
cling-version: '1.0'
569613
cppyy: On
614+
- name: osx13-x86-clang-clang-repl-19-cppyy
615+
os: macos-13
616+
compiler: clang
617+
clang-runtime: '19'
618+
cling: Off
619+
cppyy: On
570620
- name: osx13-x86-clang-clang-repl-18-cppyy
571621
os: macos-13
572622
compiler: clang
@@ -1076,6 +1126,12 @@ jobs:
10761126
fail-fast: false
10771127
matrix:
10781128
include:
1129+
- name: ubu22-x86-gcc12-clang-repl-19-emscripten_wasm
1130+
os: ubuntu-22.04
1131+
compiler: gcc-12
1132+
clang-runtime: '19'
1133+
cling: Off
1134+
micromamba_shell_init: bash
10791135
- name: ubu22-x86-gcc12-clang-repl-18-emscripten_wasm
10801136
os: ubuntu-22.04
10811137
compiler: gcc-12
@@ -1101,6 +1157,12 @@ jobs:
11011157
cling: On
11021158
cling-version: '1.0'
11031159
micromamba_shell_init: bash
1160+
- name: osx14-arm-clang-clang-repl-19-emscripten_wasm
1161+
os: macos-14
1162+
compiler: clang
1163+
clang-runtime: '19'
1164+
cling: Off
1165+
micromamba_shell_init: bash
11041166
- name: osx14-arm-clang-clang-repl-18-emscripten_wasm
11051167
os: macos-14
11061168
compiler: clang
@@ -1126,6 +1188,12 @@ jobs:
11261188
cling: On
11271189
cling-version: '1.0'
11281190
micromamba_shell_init: bash
1191+
- name: osx13-x86-clang-clang-repl-19-emscripten_wasm
1192+
os: macos-13
1193+
compiler: clang
1194+
clang-runtime: '19'
1195+
cling: Off
1196+
micromamba_shell_init: bash
11291197
- name: osx13-x86-clang-clang-repl-18-emscripten_wasm
11301198
os: macos-13
11311199
compiler: clang

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
5959
## Define supported version of clang and llvm
6060

6161
set(CLANG_MIN_SUPPORTED 13.0)
62-
set(CLANG_MAX_SUPPORTED "18.1.x")
63-
set(CLANG_VERSION_UPPER_BOUND 19.0.0)
62+
set(CLANG_MAX_SUPPORTED "19.1.x")
63+
set(CLANG_VERSION_UPPER_BOUND 20.0.0)
6464
set(LLVM_MIN_SUPPORTED 13.0)
65-
set(LLVM_MAX_SUPPORTED "18.1.x")
66-
set(LLVM_VERSION_UPPER_BOUND 19.0.0)
65+
set(LLVM_MAX_SUPPORTED "19.1.x")
66+
set(LLVM_VERSION_UPPER_BOUND 20.0.0)
6767

6868
## Set Cmake packages search order
6969

lib/Interpreter/Compatibility.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,38 @@
1010
#include "clang/Basic/Version.h"
1111
#include "clang/Config/config.h"
1212

13+
#if CLANG_VERSION_MAJOR < 19
14+
#define Template_Deduction_Result Sema::TemplateDeductionResult
15+
#define Template_Deduction_Result_Success \
16+
Sema::TemplateDeductionResult::TDK_Success
17+
#else
18+
#define Template_Deduction_Result TemplateDeductionResult
19+
#define Template_Deduction_Result_Success TemplateDeductionResult::Success
20+
#endif
21+
22+
#if CLANG_VERSION_MAJOR < 19
23+
#define For_Visible_Redeclaration Sema::ForVisibleRedeclaration
24+
#define Clang_For_Visible_Redeclaration clang::Sema::ForVisibleRedeclaration
25+
#else
26+
#define For_Visible_Redeclaration RedeclarationKind::ForVisibleRedeclaration
27+
#define Clang_For_Visible_Redeclaration \
28+
RedeclarationKind::ForVisibleRedeclaration
29+
#endif
30+
31+
#if CLANG_VERSION_MAJOR < 19
32+
#define CXXSpecialMemberKindDefaultConstructor \
33+
clang::Sema::CXXDefaultConstructor
34+
#define CXXSpecialMemberKindCopyConstructor clang::Sema::CXXCopyConstructor
35+
#define CXXSpecialMemberKindMoveConstructor clang::Sema::CXXMoveConstructor
36+
#else
37+
#define CXXSpecialMemberKindDefaultConstructor \
38+
CXXSpecialMemberKind::DefaultConstructor
39+
#define CXXSpecialMemberKindCopyConstructor \
40+
CXXSpecialMemberKind::CopyConstructor
41+
#define CXXSpecialMemberKindMoveConstructor \
42+
CXXSpecialMemberKind::MoveConstructor
43+
#endif
44+
1345
#if LLVM_VERSION_MAJOR < 18
1446
#define starts_with startswith
1547
#define ends_with endswith

lib/Interpreter/CppInterOp.cpp

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include "clang/Frontend/CompilerInstance.h"
2525
#include "clang/Sema/Lookup.h"
2626
#include "clang/Sema/Sema.h"
27+
#if CLANG_VERSION_MAJOR >= 19
28+
#include "clang/Sema/Redeclaration.h"
29+
#endif
2730
#include "clang/Sema/TemplateDeduction.h"
2831

2932
#include "llvm/ADT/StringRef.h"
@@ -49,6 +52,8 @@
4952
#include <unistd.h>
5053
#endif // WIN32
5154

55+
#include <stack>
56+
5257
namespace Cpp {
5358

5459
using namespace clang;
@@ -805,11 +810,8 @@ namespace Cpp {
805810
llvm::StringRef Name(name);
806811
auto &S = getSema();
807812
DeclarationName DName = &getASTContext().Idents.get(name);
808-
clang::LookupResult R(S,
809-
DName,
810-
SourceLocation(),
811-
Sema::LookupOrdinaryName,
812-
Sema::ForVisibleRedeclaration);
813+
clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName,
814+
For_Visible_Redeclaration);
813815

814816
Cpp_utils::Lookup::Named(&S, R, Decl::castToDeclContext(D));
815817

@@ -962,7 +964,7 @@ namespace Cpp {
962964
auto& S = getSema();
963965
DeclarationName DName = &getASTContext().Idents.get(name);
964966
clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName,
965-
Sema::ForVisibleRedeclaration);
967+
For_Visible_Redeclaration);
966968

967969
Cpp_utils::Lookup::Named(&S, R, Decl::castToDeclContext(D));
968970

@@ -1348,36 +1350,43 @@ namespace Cpp {
13481350
isunsigned = true;
13491351
typeName = StringRef(typeName.data()+9, typeName.size()-9);
13501352
}
1351-
if (typeName.equals("char")) {
1353+
if (typeName == "char") {
13521354
if (isunsigned) return Context.UnsignedCharTy;
13531355
return Context.SignedCharTy;
13541356
}
1355-
if (typeName.equals("short")) {
1357+
if (typeName == "short") {
13561358
if (isunsigned) return Context.UnsignedShortTy;
13571359
return Context.ShortTy;
13581360
}
1359-
if (typeName.equals("int")) {
1361+
if (typeName == "int") {
13601362
if (isunsigned) return Context.UnsignedIntTy;
13611363
return Context.IntTy;
13621364
}
1363-
if (typeName.equals("long")) {
1365+
if (typeName == "long") {
13641366
if (isunsigned) return Context.UnsignedLongTy;
13651367
return Context.LongTy;
13661368
}
1367-
if (typeName.equals("long long")) {
1369+
if (typeName == "long long") {
13681370
if (isunsigned)
13691371
return Context.UnsignedLongLongTy;
13701372
return Context.LongLongTy;
13711373
}
13721374
if (!issigned && !isunsigned) {
1373-
if (typeName.equals("bool")) return Context.BoolTy;
1374-
if (typeName.equals("float")) return Context.FloatTy;
1375-
if (typeName.equals("double")) return Context.DoubleTy;
1376-
if (typeName.equals("long double")) return Context.LongDoubleTy;
1377-
1378-
if (typeName.equals("wchar_t")) return Context.WCharTy;
1379-
if (typeName.equals("char16_t")) return Context.Char16Ty;
1380-
if (typeName.equals("char32_t")) return Context.Char32Ty;
1375+
if (typeName == "bool")
1376+
return Context.BoolTy;
1377+
if (typeName == "float")
1378+
return Context.FloatTy;
1379+
if (typeName == "double")
1380+
return Context.DoubleTy;
1381+
if (typeName == "long double")
1382+
return Context.LongDoubleTy;
1383+
1384+
if (typeName == "wchar_t")
1385+
return Context.WCharTy;
1386+
if (typeName == "char16_t")
1387+
return Context.Char16Ty;
1388+
if (typeName == "char32_t")
1389+
return Context.Char32Ty;
13811390
}
13821391
/* Missing
13831392
CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99.
@@ -1747,9 +1756,11 @@ namespace Cpp {
17471756
if (const CXXConstructorDecl* CD = dyn_cast<CXXConstructorDecl>(FD)) {
17481757
if (N <= 1 && llvm::isa<UsingShadowDecl>(FD)) {
17491758
auto SpecMemKind = I.getCI()->getSema().getSpecialMember(CD);
1750-
if ((N == 0 && SpecMemKind == clang::Sema::CXXDefaultConstructor) ||
1751-
(N == 1 && (SpecMemKind == clang::Sema::CXXCopyConstructor ||
1752-
SpecMemKind == clang::Sema::CXXMoveConstructor))) {
1759+
if ((N == 0 &&
1760+
SpecMemKind == CXXSpecialMemberKindDefaultConstructor) ||
1761+
(N == 1 &&
1762+
(SpecMemKind == CXXSpecialMemberKindCopyConstructor ||
1763+
SpecMemKind == CXXSpecialMemberKindMoveConstructor))) {
17531764
// Using declarations cannot inject special members; do not call
17541765
// them as such. This might happen by using `Base(Base&, int = 12)`,
17551766
// which is fine to be called as `Derived d(someBase, 42)` but not
@@ -2866,9 +2877,10 @@ namespace Cpp {
28662877
if (auto* FunctionTemplate = dyn_cast<FunctionTemplateDecl>(TemplateD)) {
28672878
FunctionDecl* Specialization = nullptr;
28682879
clang::sema::TemplateDeductionInfo Info(fakeLoc);
2869-
if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments(
2870-
FunctionTemplate, &TLI, Specialization, Info,
2871-
/*IsAddressOfFunction*/ true)) {
2880+
Template_Deduction_Result Result = S.DeduceTemplateArguments(
2881+
FunctionTemplate, &TLI, Specialization, Info,
2882+
/*IsAddressOfFunction*/ true);
2883+
if (Result != Template_Deduction_Result_Success) {
28722884
// FIXME: Diagnose what happened.
28732885
(void)Result;
28742886
}

lib/Interpreter/CppInterOpInterpreter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "clang/Lex/Preprocessor.h"
2323
#include "clang/Sema/Lookup.h"
2424
#include "clang/Sema/Sema.h"
25+
#if CLANG_VERSION_MAJOR >= 19
26+
#include "clang/Sema/Redeclaration.h"
27+
#endif
2528

2629
#include "llvm/ADT/DenseMap.h"
2730
#include "llvm/ADT/SmallSet.h"
@@ -105,7 +108,7 @@ inline clang::NamedDecl* Named(clang::Sema* S,
105108
const clang::DeclContext* Within = nullptr) {
106109
clang::LookupResult R(*S, Name, clang::SourceLocation(),
107110
clang::Sema::LookupOrdinaryName,
108-
clang::Sema::ForVisibleRedeclaration);
111+
Clang_For_Visible_Redeclaration);
109112
Named(S, R, Within);
110113
return LookupResult2Decl<clang::NamedDecl>(R);
111114
}

lib/Interpreter/DynamicLibraryManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class DynamicLibraryManager {
130130
bool prepend = false) {
131131
if (!dir.empty()) {
132132
for (auto& item : m_SearchPaths)
133-
if (dir.equals(item.Path))
133+
if (dir == item.Path)
134134
return;
135135
auto pos = prepend ? m_SearchPaths.begin() : m_SearchPaths.end();
136136
m_SearchPaths.insert(pos, SearchPathInfo{dir.str(), isUser});

lib/Interpreter/Paths.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ bool LookForFile(const std::vector<const char*>& Args, std::string& Path,
312312
return true;
313313
}
314314
// Don't write same same log entry twice when FilePath == Path
315-
if (FileType && !FilePath.str().equals(Path))
315+
if (FileType && FilePath.str() != Path)
316316
LogFileStatus("Ignoring", FileType, FilePath);
317317
}
318318
else if (llvm::sys::path::is_absolute(Path))
@@ -354,7 +354,7 @@ bool SplitPaths(llvm::StringRef PathStr,
354354

355355
#if defined(_WIN32)
356356
// Support using a ':' delimiter on Windows.
357-
const bool WindowsColon = Delim.equals(":");
357+
const bool WindowsColon = (Delim == ":");
358358
#endif
359359

360360
bool AllExisted = true;

unittests/CppInterOp/ScopeReflectionTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,11 @@ template<class T> constexpr T pi = T(3.1415926535897932385L);
772772
VarTemplateDecl* VDTD1 = VD->getSpecializedTemplate();
773773
EXPECT_TRUE(VDTD1->isThisDeclarationADefinition());
774774
#if CLANG_VERSION_MAJOR > 13
775+
#if CLANG_VERSION_MAJOR <= 18
775776
TemplateArgument TA1 = (*VD->getTemplateArgsInfo())[0].getArgument();
777+
#else
778+
TemplateArgument TA1 = (*VD->getTemplateArgsAsWritten())[0].getArgument();
779+
#endif // CLANG_VERSION_MAJOR
776780
#else
777781
TemplateArgument TA1 = VD->getTemplateArgsInfo()[0].getArgument();
778782
#endif // CLANG_VERSION_MAJOR

0 commit comments

Comments
 (0)