Skip to content

Commit f567515

Browse files
authored
Merge pull request #321 from bkryza/llvm-19-support
Llvm 19 support
2 parents 21cea29 + 92c2577 commit f567515

File tree

13 files changed

+96
-23
lines changed

13 files changed

+96
-23
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
max-size: "2000M"
3939
- name: Install deps
40-
run: sudo apt -y install git make grcov ninja-build pkg-config gcc g++ ccache cmake libyaml-cpp-dev llvm-18 clang-18 libclang-18-dev libclang-cpp18-dev clang-format-18 lcov zlib1g-dev libunwind-dev libdw-dev gnustep-back-common libgnustep-base-dev gnustep-make
40+
run: sudo apt -y install git make grcov ninja-build pkg-config gcc g++ ccache cmake libyaml-cpp-dev llvm-18 clang-18 libclang-18-dev libclang-cpp18-dev clang-tools-18 clang-format-18 lcov zlib1g-dev libunwind-dev libdw-dev gnustep-back-common libgnustep-base-dev gnustep-make
4141
- name: Check code formatting
4242
run: |
4343
make check-formatting

.github/workflows/macos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
uses: hendrikmuhs/[email protected]
3838

3939
- name: Install dependencies using homebrew
40-
run: brew install llvm@18 ninja yaml-cpp cmake ccache
40+
run: brew update && brew install llvm@19 ninja yaml-cpp cmake ccache
4141

4242
- name: Build and test
4343
run: CC=/opt/homebrew/opt/llvm/bin/clang CXX=/opt/homebrew/opt/llvm/bin/clang++ CMAKE_PREFIX=/opt/homebrew/opt/llvm/lib/cmake/llvm/ CMAKE_GENERATOR=Ninja CMAKE_EXE_LINKER_FLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++" ENABLE_OBJECTIVE_C_TEST_CASES=ON make test
@@ -46,4 +46,4 @@ jobs:
4646
run: debug/src/clang-uml --version
4747

4848
- name: Print help
49-
run: debug/src/clang-uml --help
49+
run: debug/src/clang-uml --help

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# CHANGELOG
22

3+
* Updated code to work with LLVM 19 (#319)
34
* Added support for Objective C (#296)
45
* Added option to fold repeated activities in sequence diagrams (#317)
56
* Fixed default arguments braces in mermaid diagrams (#312)

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ endif()
112112
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
113113
set(CUSTOM_COMPILE_OPTIONS
114114
${CUSTOM_COMPILE_OPTIONS} -Wno-unused-private-field)
115+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19)
116+
set(CUSTOM_COMPILE_OPTIONS ${CUSTOM_COMPILE_OPTIONS} -Wno-missing-template-arg-list-after-template-kw)
117+
endif()
118+
if(APPLE)
119+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
120+
# Use LLVM bundled unwind on Apple Silicon to fix segfaults on exception throw
121+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${HOMEBREW_PREFIX}/opt/llvm/lib/unwind -lunwind")
122+
endif()
123+
endif(APPLE)
115124
endif()
116125

117126
#

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![macos build status](https://github.com/bkryza/clang-uml/actions/workflows/macos.yml/badge.svg)](https://github.com/bkryza/clang-uml/actions)
77
[![Coverage](https://codecov.io/gh/bkryza/clang-uml/branch/master/graph/badge.svg)](https://codecov.io/gh/bkryza/clang-uml)
88
[![Version](https://img.shields.io/badge/version-0.5.4-blue)](https://github.com/bkryza/clang-uml/releases)
9-
[![Version](https://img.shields.io/badge/LLVM-12,13,14,15,16,17,18-orange)](https://github.com/bkryza/clang-uml/releases)
9+
[![Version](https://img.shields.io/badge/LLVM-12,13,14,15,16,17,18,19-orange)](https://github.com/bkryza/clang-uml/releases)
1010
[![Doxygen](https://img.shields.io/badge/Docs-Doxygen-gainsboro)](https://clang-uml.github.io)
1111

1212
`clang-uml` is an automatic C++ to UML class, sequence, package and include diagram generator, driven by

cmake/LLVMSetup.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ if(LLVM_VERSION STREQUAL "18")
2626
set(LLVM_VERSION "18.1")
2727
endif()
2828

29+
if(LLVM_VERSION STREQUAL "19")
30+
set(LLVM_VERSION "19.1")
31+
endif()
32+
2933
find_package(LLVM ${LLVM_VERSION} CONFIG REQUIRED)
3034

3135
list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})

src/common/clang_utils.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,21 @@ std::string to_string(const clang::ArrayType &array_type,
157157
"{}{}", to_string(underlying_type, ctx, try_canonical), dimensions_str);
158158
}
159159

160+
std::string to_string(
161+
const clang::TemplateArgumentLoc &argLoc, const clang::ASTContext &context)
162+
{
163+
std::string result;
164+
llvm::raw_string_ostream stream(result);
165+
166+
clang::PrintingPolicy policy(context.getLangOpts());
167+
168+
const clang::TemplateArgument &arg = argLoc.getArgument();
169+
arg.print(policy, stream, false);
170+
stream.flush();
171+
172+
return result;
173+
}
174+
160175
std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
161176
bool try_canonical)
162177
{

src/common/clang_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ model::namespace_ get_tag_namespace(const clang::TagDecl &declaration);
102102
model::namespace_ get_template_namespace(
103103
const clang::TemplateDecl &declaration);
104104

105+
std::string to_string(
106+
const clang::TemplateArgumentLoc &argLoc, const clang::ASTContext &context);
107+
105108
std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
106109
bool try_canonical = true);
107110

src/common/types.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ bool operator==(const eid_t &lhs, const uint64_t &v) { return lhs.value_ == v; }
5858

5959
bool operator!=(const eid_t &lhs, const uint64_t &v)
6060
{
61-
// This is sadly necessary to catch accidental comparisons to empty
62-
// std::optional<id_t>:
63-
//
64-
// std::optional<id_t> id{};
65-
// if(id != 0) { /* id is nullopt, not 0 - so this executes... */ }
66-
//
6761
assert(v != 0);
6862

6963
return lhs.value_ != v;

src/common/visitor/template_builder.h

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ template <typename VisitorT> class template_builder {
215215
* @return Return template argument model
216216
*/
217217
template_parameter process_integral_argument(
218-
const clang::TemplateArgument &arg);
218+
const clang::TemplateArgument &arg,
219+
const clang::ASTContext &ast_context);
219220

220221
#if LLVM_VERSION_MAJOR > 17
221222
/**
@@ -229,7 +230,8 @@ template <typename VisitorT> class template_builder {
229230
* @return Return template argument model
230231
*/
231232
template_parameter process_structural_argument(
232-
const clang::TemplateArgument &arg);
233+
const clang::TemplateArgument &arg,
234+
const clang::ASTContext &ast_context);
233235
#endif
234236

235237
/**
@@ -638,7 +640,13 @@ void template_builder<VisitorT>::build_from_template_declaration(
638640
std::optional<std::string> default_arg;
639641
if (template_type_parameter->hasDefaultArgument()) {
640642
default_arg =
643+
#if LLVM_VERSION_MAJOR > 18
644+
common::to_string(
645+
template_type_parameter->getDefaultArgument(),
646+
template_declaration.getASTContext());
647+
#else
641648
template_type_parameter->getDefaultArgument().getAsString();
649+
#endif
642650
}
643651

644652
auto parameter_name = template_type_parameter->getNameAsString();
@@ -686,10 +694,17 @@ void template_builder<VisitorT>::build_from_template_declaration(
686694

687695
std::optional<std::string> default_arg;
688696

689-
if (template_nontype_parameter->hasDefaultArgument())
690-
default_arg = common::to_string(
691-
template_nontype_parameter->getDefaultArgument());
692-
697+
if (template_nontype_parameter->hasDefaultArgument()) {
698+
default_arg =
699+
#if LLVM_VERSION_MAJOR > 18
700+
common::to_string(
701+
template_nontype_parameter->getDefaultArgument(),
702+
template_declaration.getASTContext());
703+
#else
704+
common::to_string(
705+
template_nontype_parameter->getDefaultArgument());
706+
#endif
707+
}
693708
auto ct = template_parameter::make_non_type_template(
694709
template_nontype_parameter->getType().getAsString(),
695710
template_nontype_parameter->getNameAsString(), default_arg,
@@ -1046,7 +1061,8 @@ void template_builder<VisitorT>::argument_process_dispatch(
10461061
argument.push_back(process_nullptr_argument(arg));
10471062
break;
10481063
case clang::TemplateArgument::Integral:
1049-
argument.push_back(process_integral_argument(arg));
1064+
argument.push_back(
1065+
process_integral_argument(arg, template_decl->getASTContext()));
10501066
break;
10511067
case clang::TemplateArgument::TemplateExpansion:
10521068
argument.push_back(process_template_expansion(arg));
@@ -1226,27 +1242,39 @@ bool template_builder<VisitorT>::
12261242

12271243
template <typename VisitorT>
12281244
template_parameter template_builder<VisitorT>::process_integral_argument(
1229-
const clang::TemplateArgument &arg)
1245+
const clang::TemplateArgument &arg, const clang::ASTContext &ast_context)
12301246
{
12311247
assert(arg.getKind() == clang::TemplateArgument::Integral);
12321248

12331249
std::string result;
12341250
llvm::raw_string_ostream ostream(result);
1251+
clang::PrintingPolicy policy(ast_context.getLangOpts());
1252+
1253+
#if LLVM_VERSION_MAJOR > 18
1254+
arg.print(policy, ostream, false);
1255+
#else
12351256
arg.dump(ostream);
1257+
#endif
12361258

12371259
return template_parameter::make_argument(result);
12381260
}
12391261

12401262
#if LLVM_VERSION_MAJOR > 17
12411263
template <typename VisitorT>
12421264
template_parameter template_builder<VisitorT>::process_structural_argument(
1243-
const clang::TemplateArgument &arg)
1265+
const clang::TemplateArgument &arg, const clang::ASTContext &ast_context)
12441266
{
12451267
assert(arg.getKind() == clang::TemplateArgument::StructuralValue);
12461268

12471269
std::string result;
12481270
llvm::raw_string_ostream ostream(result);
1271+
clang::PrintingPolicy policy(ast_context.getLangOpts());
1272+
1273+
#if LLVM_VERSION_MAJOR > 18
1274+
arg.print(policy, ostream, false);
1275+
#else
12491276
arg.dump(ostream);
1277+
#endif
12501278

12511279
return template_parameter::make_argument(result);
12521280
}

0 commit comments

Comments
 (0)