Skip to content

Commit 133517e

Browse files
authored
Merge pull request #420 from bkryza/add-support-for-llvm-21
Add support for llvm 21
2 parents 378ea0c + 49d02d2 commit 133517e

File tree

9 files changed

+66
-25
lines changed

9 files changed

+66
-25
lines changed

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
param (
2-
$Prefix="C:\clang-uml-llvm19",
2+
$Prefix="C:\clang-uml-llvm20",
33
$BuildType="Release"
44
)
55

cmake/LLVMSetup.cmake

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ if(NOT "${LLVM_CONFIG_PATH}" STREQUAL "")
1818
OUTPUT_VARIABLE LLVM_VERSION_STR OUTPUT_STRIP_TRAILING_WHITESPACE)
1919

2020
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.(.+)"
21-
GIT_VERSION_MATCH ${LLVM_VERSION_STR})
21+
LLVM_VERSION_MATCH ${LLVM_VERSION_STR})
2222
set(LLVM_VERSION ${CMAKE_MATCH_1})
23+
set(LLVM_VERSION_MINOR ${CMAKE_MATCH_2})
2324
endif()
2425

25-
if(LLVM_VERSION STREQUAL "18")
26-
set(LLVM_VERSION "18.1")
27-
endif()
28-
29-
if(LLVM_VERSION STREQUAL "19")
30-
set(LLVM_VERSION "19.1")
26+
if("${LLVM_VERSION_MINOR}" STREQUAL "")
27+
if("${LLVM_VERSION}" STRGREATER_EQUAL "18")
28+
set(LLVM_VERSION_MINOR "1")
29+
else()
30+
set(LLVM_VERSION_MINOR "0")
31+
endif()
3132
endif()
3233

33-
if(LLVM_VERSION STREQUAL "20")
34-
set(LLVM_VERSION "20.1")
34+
if(NOT "${LLVM_VERSION}" STREQUAL "" AND NOT "${LLVM_VERSION_MINOR}" STREQUAL "")
35+
set(LLVM_VERSION "${LLVM_VERSION}.${LLVM_VERSION_MINOR}")
3536
endif()
3637

3738
find_package(LLVM ${LLVM_VERSION} CONFIG REQUIRED)

docs/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Build and install `yaml-cpp`:
216216
```bash
217217
git clone https://github.com/jbeder/yaml-cpp
218218
cd yaml-cpp
219-
git checkout yaml-cpp-0.8.0
219+
git checkout 0.8.0
220220
cd ..
221221
cmake -S .\yaml-cpp\ -B .\yaml-cpp-build\ -DYAML_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="C:\clang-uml" -Thost=x64
222222
cd yaml-cpp-build
@@ -228,7 +228,7 @@ Build and install `LLVM`:
228228
```bash
229229
pip install psutil
230230
# Update the LLVM branch if necessary
231-
git clone --branch llvmorg-19.1.3 --depth 1 https://github.com/llvm/llvm-project.git llvm
231+
git clone --branch llvmorg-20.1.7 --depth 1 https://github.com/llvm/llvm-project.git llvm
232232
cmake -S .\llvm\llvm -B llvm-build -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_INSTALL_PREFIX="C:\clang-uml" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -Thost=x64
233233
cd llvm-build
234234
msbuild .\INSTALL.vcxproj -maxcpucount /p:Configuration=Release

packaging/make_installer.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This script assumes that all clang-uml dependencies are instaled in C:\clang-uml
22

3-
param ($Prefix="C:\clang-uml-llvm19", $BuildType="Release")
3+
param ($Prefix="C:\clang-uml-llvm20", $BuildType="Release")
44

55
mkdir _BUILD
66

src/class_diagram/visitor/translation_unit_visitor.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,26 @@ bool translation_unit_visitor::VisitClassTemplateDecl(
321321
id_mapper().add(cls->getID(), id);
322322

323323
constexpr auto kMaxConstraintCount = 24U;
324+
325+
#if LLVM_VERSION_MAJOR < 21
324326
llvm::SmallVector<const clang::Expr *, kMaxConstraintCount> constraints{};
325327
if (cls->hasAssociatedConstraints()) {
326328
cls->getAssociatedConstraints(constraints);
327329
}
328-
329330
for (const auto *expr : constraints) {
330331
find_relationships_in_constraint_expression(*c_ptr, expr);
331332
}
333+
#else
334+
llvm::SmallVector<clang::AssociatedConstraint, kMaxConstraintCount>
335+
constraints{};
336+
if (cls->hasAssociatedConstraints()) {
337+
cls->getAssociatedConstraints(constraints);
338+
}
339+
for (const auto &constraint : constraints) {
340+
find_relationships_in_constraint_expression(
341+
*c_ptr, constraint.ConstraintExpr);
342+
}
343+
#endif
332344

333345
return add_or_update(cls->getTemplatedDecl(), std::move(c_ptr));
334346
}
@@ -500,6 +512,8 @@ bool translation_unit_visitor::TraverseConceptDecl(clang::ConceptDecl *cpt)
500512
tbuilder().build_from_template_declaration(*concept_model, *cpt);
501513

502514
constexpr auto kMaxConstraintCount = 24U;
515+
516+
#if LLVM_VERSION_MAJOR < 21
503517
llvm::SmallVector<const clang::Expr *, kMaxConstraintCount> constraints{};
504518
if (cpt->hasAssociatedConstraints()) {
505519
cpt->getAssociatedConstraints(constraints);
@@ -508,6 +522,17 @@ bool translation_unit_visitor::TraverseConceptDecl(clang::ConceptDecl *cpt)
508522
for (const auto *expr : constraints) {
509523
find_relationships_in_constraint_expression(*concept_model, expr);
510524
}
525+
#else
526+
llvm::SmallVector<clang::AssociatedConstraint, kMaxConstraintCount>
527+
constraints{};
528+
if (cpt->hasAssociatedConstraints()) {
529+
cpt->getAssociatedConstraints(constraints);
530+
}
531+
for (const auto &constraint : constraints) {
532+
find_relationships_in_constraint_expression(
533+
*concept_model, constraint.ConstraintExpr);
534+
}
535+
#endif
511536

512537
if (cpt->getConstraintExpr() != nullptr) {
513538
process_constraint_requirements(

src/common/clang_utils.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
189189

190190
clang::PrintingPolicy print_policy(ctx.getLangOpts());
191191
print_policy.SuppressScope = 0;
192+
#if LLVM_VERSION_MAJOR < 21
192193
print_policy.PrintCanonicalTypes = 0;
194+
#else
195+
print_policy.PrintAsCanonical = 0;
196+
#endif
193197

194198
std::string result;
195199

src/common/generators/clang_tool.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ class clang_tool {
103103
ArgumentsAdjuster args_adjuster_;
104104

105105
std::unique_ptr<diagnostic_consumer> diag_consumer_;
106+
#if LLVM_VERSION_MAJOR < 21
106107
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diag_opts_;
108+
#else
109+
std::unique_ptr<clang::DiagnosticOptions> diag_opts_;
110+
#endif
107111
};
108112
} // namespace clanguml::generators
109113

src/common/visitor/template_builder.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,13 +1385,17 @@ template_builder<VisitorT>::try_as_member_pointer(
13851385

13861386
argument.add_template_param(std::move(pointee_arg));
13871387

1388+
#if LLVM_VERSION_MAJOR < 21
13881389
const auto *member_class_type = mp_type->getClass();
1390+
#else
1391+
const auto *member_class_type = mp_type->getQualifier()->getAsType();
1392+
#endif
13891393

13901394
if (member_class_type == nullptr)
13911395
return {};
13921396

13931397
auto class_type_arg = process_type_argument(location_decl, parent, cls,
1394-
template_decl, mp_type->getClass()->getCanonicalTypeUnqualified(),
1398+
template_decl, member_class_type->getCanonicalTypeUnqualified(),
13951399
template_instantiation, argument_index);
13961400

13971401
argument.add_template_param(std::move(class_type_arg));
@@ -1413,13 +1417,17 @@ template_builder<VisitorT>::try_as_member_pointer(
14131417
// Add return type argument
14141418
argument.add_template_param(std::move(return_type_arg));
14151419

1420+
#if LLVM_VERSION_MAJOR < 21
14161421
const auto *member_class_type = mp_type->getClass();
1422+
#else
1423+
const auto *member_class_type = mp_type->getQualifier()->getAsType();
1424+
#endif
14171425

14181426
if (member_class_type == nullptr)
14191427
return {};
14201428

14211429
auto class_type_arg = process_type_argument(location_decl, parent, cls,
1422-
template_decl, mp_type->getClass()->getCanonicalTypeUnqualified(),
1430+
template_decl, member_class_type->getCanonicalTypeUnqualified(),
14231431
template_instantiation, argument_index);
14241432

14251433
// Add class type argument

tests/CMakeLists.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,19 @@ foreach(TEST_NAME ${TEST_NAMES})
164164
# We need to link the objective test cases sources to a separate
165165
# ObjC library than the rest of C++ test cases
166166
add_library(test_cases_objc)
167-
if(APPLE)
168-
target_compile_options(
169-
test_cases_objc
170-
PRIVATE
171-
"SHELL:-isystem ${LLVM_INCLUDE_DIR}/c++/v1"
172-
"SHELL:-isystem ${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION_MAJOR}/include"
173-
)
174-
else(APPLE)
167+
target_compile_options(
168+
test_cases_objc
169+
PRIVATE
170+
"SHELL:-isystem ${LLVM_INCLUDE_DIR}/c++/v1"
171+
"SHELL:-isystem ${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION_MAJOR}/include"
172+
)
173+
if(NOT APPLE)
175174
target_compile_options(test_cases_objc
176175
PRIVATE ${GNUSTEP_CFLAGS})
177176
target_link_libraries(
178177
test_cases_objc PRIVATE ${GNUSTEP_LDFLAGS}
179178
${FETCHED_LIBOBJC2_NAME})
180-
endif(APPLE)
179+
endif(NOT APPLE)
181180
target_sources(test_cases_objc PUBLIC ${TEST_CASES_OBJC_SOURCES})
182181
endif(ENABLE_OBJECTIVE_C_TEST_CASES)
183182
target_sources(${TEST_NAME} PUBLIC ${TEST_NAME}.cc

0 commit comments

Comments
 (0)