Skip to content

Commit db81957

Browse files
committed
Support for Clang 21
This fixed #723 and #738.
1 parent 65fdc89 commit db81957

42 files changed

Lines changed: 628 additions & 197 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
name: "Linux Clang - Format check",
3333
os: ubuntu-22.04,
3434
build_type: Release,
35-
cformat_name: 'clang-format-20'
35+
cformat_name: 'clang-format-21'
3636
}
3737

3838
steps:
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
wget https://apt.llvm.org/llvm.sh
4747
chmod +x llvm.sh
48-
sudo ./llvm.sh 20
48+
sudo ./llvm.sh 21
4949
sudo apt-get install ${{ matrix.config.cformat_name }}
5050
5151
- name: clang-format check
@@ -68,7 +68,7 @@ jobs:
6868
config:
6969
# AppleClang
7070
- {
71-
name: "Clang 20 / LLVM 20 @ macOS Release",
71+
name: "Clang 21 / LLVM 21 @ macOS Release",
7272
os: macos-14,
7373
build_type: Release,
7474
cxx: "clang++",
@@ -87,7 +87,7 @@ jobs:
8787

8888
# AppleClang
8989
- {
90-
name: "Clang 20 / LLVM 20 @ macOS Debug",
90+
name: "Clang 21 / LLVM 21 @ macOS Debug",
9191
os: macos-14,
9292
build_type: Release,
9393
cxx: "clang++",
@@ -106,7 +106,7 @@ jobs:
106106

107107
# AppleClang
108108
- {
109-
name: "Clang 20 / LLVM 20 @ macOS Coverage & Debug",
109+
name: "Clang 21 / LLVM 21 @ macOS Coverage & Debug",
110110
os: macos-14,
111111
build_type: Release,
112112
cxx: "clang++",
@@ -124,7 +124,7 @@ jobs:
124124

125125
# # MSVC 2019
126126
# - {
127-
# name: "MSVC 2022 / LLVM 20 @ Windows Release",
127+
# name: "MSVC 2022 / LLVM 21 @ Windows Release",
128128
# os: windows-2022,
129129
# build_type: Release,
130130
# cxx: "cl",
@@ -143,7 +143,7 @@ jobs:
143143

144144
# # MSVC 2019
145145
# - {
146-
# name: "MSVC 2022 / LLVM 20 @ Windows Debug",
146+
# name: "MSVC 2022 / LLVM 21 @ Windows Debug",
147147
# os: windows-2022,
148148
# build_type: Release,
149149
# cxx: "cl",
@@ -161,7 +161,7 @@ jobs:
161161

162162
# # MSVC 2019
163163
# - {
164-
# name: "MSVC 2022 / LLVM 20 @ Windows Code Coverage & Debug",
164+
# name: "MSVC 2022 / LLVM 21 @ Windows Code Coverage & Debug",
165165
# os: windows-2022,
166166
# build_type: Release,
167167
# cxx: "clang-cl.exe",
@@ -462,13 +462,13 @@ jobs:
462462
- ubuntu-22.04-arm
463463

464464
config:
465-
# GCC 14 / LLVM 20
465+
# GCC 14 / LLVM 21
466466
- {
467-
name: "GCC 14 / LLVM 20 @ Ubuntu Release",
467+
name: "GCC 14 / LLVM 21 @ Ubuntu Release",
468468
build_type: Release,
469469
cxx: "g++-14",
470470
llvm_version: "20.1.0",
471-
llvm_config: "/usr/bin/llvm-config-20",
471+
llvm_config: "/usr/bin/llvm-config-21",
472472
coverage: "No",
473473
static: "Yes",
474474
debug: "No",
@@ -481,13 +481,13 @@ jobs:
481481
docs: "Yes",
482482
}
483483

484-
# GCC 14 / LLVM 20
484+
# GCC 14 / LLVM 21
485485
- {
486-
name: "GCC 14 / LLVM 20 @ Ubuntu Code Coverage & Debug",
486+
name: "GCC 14 / LLVM 21 @ Ubuntu Code Coverage & Debug",
487487
build_type: Release,
488488
cxx: "g++-14",
489489
llvm_version: "20.1.0",
490-
llvm_config: "/usr/bin/llvm-config-20",
490+
llvm_config: "/usr/bin/llvm-config-21",
491491
coverage: "Yes",
492492
static: "No",
493493
debug: "Yes",
@@ -498,13 +498,13 @@ jobs:
498498
archive_name: "insights-ubuntu",
499499
}
500500

501-
# GCC 14 / LLVM 20
501+
# GCC 14 / LLVM 21
502502
- {
503-
name: "GCC 14 / LLVM 20 @ Ubuntu Code Coverage (libc++)",
503+
name: "GCC 14 / LLVM 21 @ Ubuntu Code Coverage (libc++)",
504504
build_type: Release,
505505
cxx: "g++-14",
506506
llvm_version: "20.1.0",
507-
llvm_config: "/usr/bin/llvm-config-20",
507+
llvm_config: "/usr/bin/llvm-config-21",
508508
coverage: "Yes",
509509
static: "No",
510510
debug: "Yes",
@@ -630,13 +630,13 @@ jobs:
630630
- amd64
631631

632632
config:
633-
# GCC 14 / LLVM 20
633+
# GCC 14 / LLVM 21
634634
- {
635-
name: "GCC 14 / LLVM 20 @ Ubuntu Release",
635+
name: "GCC 14 / LLVM 21 @ Ubuntu Release",
636636
build_type: Release,
637637
cxx: "g++-14",
638638
llvm_version: "20.1.0",
639-
llvm_config: "/usr/bin/llvm-config-20",
639+
llvm_config: "/usr/bin/llvm-config-21",
640640
coverage: "No",
641641
static: "Yes",
642642
debug: "No",

ASTHelpers.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,12 @@ FunctionBase(std::string_view name, QualType returnType, const params_vector& pa
385385
false,
386386
false,
387387
ConstexprSpecKind::Unspecified,
388-
nullptr);
388+
#if IS_CLANG_NEWER_THAN(20)
389+
AssociatedConstraint {}
390+
#else
391+
nullptr
392+
#endif
393+
);
389394
fdd->setImplicit(true);
390395

391396
SmallVector<ParmVarDecl*, 8> paramVarDecls{};
@@ -695,7 +700,11 @@ CXXNewExpr* New(ArrayRef<Expr*> placementArgs, const Expr* expr, QualType t)
695700
false,
696701
nullptr,
697702
nullptr,
703+
#if IS_CLANG_NEWER_THAN(20)
704+
ImplicitAllocationParameters{AlignedAllocationMode::Yes},
705+
#else
698706
true,
707+
#endif
699708
false,
700709
placementArgs,
701710
SourceRange{},

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ option(INSIGHTS_STATIC "Use static linking" Off)
3232

3333
set(INSIGHTS_LLVM_CONFIG "llvm-config" CACHE STRING "LLVM config executable to use")
3434

35-
set(INSIGHTS_MIN_LLVM_MAJOR_VERSION 20)
35+
set(INSIGHTS_MIN_LLVM_MAJOR_VERSION 21)
3636
set(INSIGHTS_MIN_LLVM_VERSION ${INSIGHTS_MIN_LLVM_MAJOR_VERSION}.0)
3737

3838
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)

CodeGenerator.cpp

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ namespace ranges = std::ranges;
4242
//-----------------------------------------------------------------------------
4343
namespace clang::insights {
4444

45-
#define BUILD_OPT_AND(name, param) std::function name = [](param t) -> MyOptional<param>
46-
#define BUILD_OPT_AND_O(name, param, ret) std::function name = [](param t) -> MyOptional<ret>
45+
#define BUILD_OPT_AND(name, param) std::function name = [](param t)->MyOptional<param>
46+
#define BUILD_OPT_AND_O(name, param, ret) std::function name = [](param t)->MyOptional<ret>
4747

4848
BUILD_OPT_AND(IsPointer, QualType)
4949
{
@@ -1412,7 +1412,6 @@ void CodeGenerator::InsertArg(const VarDecl* stmt)
14121412
// }
14131413

14141414
} else {
1415-
mProcessingVarDecl = false;
14161415
BackupAndRestore _{mProcessingVarDecl, true};
14171416

14181417
if(MyOptional<const InitListExpr*> initList{dyn_cast_or_null<InitListExpr>(init)};
@@ -2398,18 +2397,20 @@ void CodeGenerator::InsertArg(const ImplicitCastExpr* stmt)
23982397
} else {
23992398
auto castName{GetCastName(castKind)};
24002399
const QualType castDestType{[&] {
2401-
const auto type{stmt->getType()};
2400+
auto type{stmt->getType()};
2401+
2402+
// In case of a dependent type the canonical type doesn't know the parameters name.
2403+
if(not type->isDependentType()) {
2404+
type = type.getCanonicalType();
2405+
}
24022406

24032407
// In at least the case a structured bindings the compiler adds xvalue casts but the && is missing to
24042408
// make it valid C++.
24052409
if(VK_XValue == stmt->getValueKind()) {
2406-
return GetGlobalAST().getRValueReferenceType(type.getCanonicalType());
2407-
} else if(type->isDependentType()) { // In case of a dependent type the canonical type doesn't know the
2408-
// parameters name.
2409-
return type;
2410+
return GetGlobalAST().getRValueReferenceType(type);
24102411
}
24112412

2412-
return type.getCanonicalType();
2413+
return type;
24132414
}()};
24142415

24152416
FormatCast(castName, castDestType, subExpr, castKind);
@@ -3178,16 +3179,21 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)
31783179
mOutputFormatHelper.Append(stream.str());
31793180

31803181
InsertTemplateArgs(*templateSpecializationType);
3181-
} else if(auto* dependentTemplateSpecializationType =
3182-
underlyingType->getAs<DependentTemplateSpecializationType>()) {
31833182

3184-
mOutputFormatHelper.Append(GetElaboratedTypeKeyword(dependentTemplateSpecializationType->getKeyword()));
3183+
} else if(auto* depSpecType = underlyingType->getAs<DependentTemplateSpecializationType>()) {
3184+
mOutputFormatHelper.Append(GetElaboratedTypeKeyword(depSpecType->getKeyword()));
31853185

3186-
InsertNamespace(dependentTemplateSpecializationType->getQualifier());
3186+
#if IS_CLANG_NEWER_THAN(20)
3187+
InsertNamespace(depSpecType->getDependentTemplateName().getQualifier());
31873188

3188-
mOutputFormatHelper.Append(kwTemplateSpace, dependentTemplateSpecializationType->getIdentifier()->getName());
3189+
mOutputFormatHelper.Append(kwTemplateSpace, GetName(depSpecType->getDependentTemplateName()));
3190+
#else
3191+
InsertNamespace(depSpecType->getQualifier());
3192+
3193+
mOutputFormatHelper.Append(kwTemplateSpace, depSpecType->getIdentifier()->getName());
3194+
#endif
31893195

3190-
InsertTemplateArgs(*dependentTemplateSpecializationType);
3196+
InsertTemplateArgs(*depSpecType);
31913197

31923198
} else {
31933199
mOutputFormatHelper.Append(GetName(underlyingType));
@@ -3802,6 +3808,11 @@ void CodeGenerator::InsertAttribute(const Attr& attr)
38023808
// skip this custom clang attribute
38033809
RETURN_IF(attr::NoInline == attr.getKind());
38043810

3811+
#if IS_CLANG_NEWER_THAN(20)
3812+
// skip this custom clang attribute
3813+
RETURN_IF(attr::InferredNoReturn == attr.getKind());
3814+
#endif
3815+
38053816
// Clang's printPretty misses the parameter pack ellipsis. Hence treat this special case here.
38063817
if(const auto* alignedAttr = dyn_cast_or_null<AlignedAttr>(&attr)) {
38073818
auto insert = [&](const QualType type, const TemplateTypeParmType* tmplTypeParam) {
@@ -4460,7 +4471,7 @@ void CodeGenerator::InsertArg(const CXXStdInitializerListExpr* stmt)
44604471
auto internalListName =
44614472
MakeLineColumnName(GetGlobalAST().getSourceManager(), stmt->getBeginLoc(), BuildInternalVarName("list"sv));
44624473

4463-
ofm.Append(modifiers, GetTypeNameAsParameter(subExpr->getType(), internalListName));
4474+
ofm.Append(modifiers, GetTypeNameAsParameter(subExpr->getType().getCanonicalType(), internalListName));
44644475
CodeGeneratorVariant codeGenerator{ofm};
44654476
codeGenerator->InsertArg(subExpr);
44664477
ofm.AppendSemiNewLine();
@@ -4637,11 +4648,19 @@ void CodeGenerator::InsertTemplateArg(const TemplateArgument& arg)
46374648
if(const auto* tmplDecl = arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl()) {
46384649
mOutputFormatHelper.Append(GetName(*tmplDecl, QualifiedName::Yes));
46394650

4651+
#if IS_CLANG_NEWER_THAN(20)
4652+
} else if(const auto* depName = arg.getAsTemplateOrTemplatePattern().getAsDependentTemplateName();
4653+
depName->getName().getIdentifier()) {
4654+
InsertNamespace(depName->getQualifier());
4655+
4656+
mOutputFormatHelper.Append(kwTemplateSpace, GetName(*depName));
4657+
#else
46404658
} else if(const auto* depName = arg.getAsTemplateOrTemplatePattern().getAsDependentTemplateName();
46414659
depName->isIdentifier()) {
46424660
InsertNamespace(depName->getQualifier());
46434661

46444662
mOutputFormatHelper.Append(kwTemplateSpace, depName->getIdentifier()->getName());
4663+
#endif
46454664
} else {
46464665
ToDo(arg, mOutputFormatHelper);
46474666
}
@@ -4834,7 +4853,17 @@ void CodeGenerator::InsertConceptConstraint(const TemplateParameterList& tmplDec
48344853
void CodeGenerator::InsertConceptConstraint(const FunctionDecl* tmplDecl)
48354854
{
48364855
SmallVector<const Expr*, 5> constraints{};
4856+
4857+
#if IS_CLANG_NEWER_THAN(20)
4858+
SmallVector<AssociatedConstraint, 5> assocConstraints{};
4859+
tmplDecl->getAssociatedConstraints(assocConstraints);
4860+
4861+
for(auto& e : assocConstraints) {
4862+
constraints.push_back(e.ConstraintExpr);
4863+
}
4864+
#else
48374865
tmplDecl->getAssociatedConstraints(constraints);
4866+
#endif
48384867

48394868
InsertConceptConstraint(constraints, InsertInline::Yes);
48404869
}

0 commit comments

Comments
 (0)