Skip to content

Commit 18cc523

Browse files
committed
Added compile support for Clang 18.
1 parent dce0a67 commit 18cc523

File tree

7 files changed

+100
-35
lines changed

7 files changed

+100
-35
lines changed

ASTHelpers.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,19 @@ CXXRecordDecl* Struct(std::string_view name)
473473
auto getRecord = [&] {
474474
auto& ctx = GetGlobalAST();
475475

476-
return CXXRecordDecl::Create(
477-
ctx, TTK_Struct, ctx.getTranslationUnitDecl(), {}, {}, &ctx.Idents.get(name), nullptr, false);
476+
return CXXRecordDecl::Create(ctx,
477+
#if IS_CLANG_NEWER_THAN(17)
478+
TagTypeKind::Struct
479+
#else
480+
TTK_Struct
481+
#endif
482+
,
483+
ctx.getTranslationUnitDecl(),
484+
{},
485+
{},
486+
&ctx.Idents.get(name),
487+
nullptr,
488+
false);
478489
};
479490

480491
auto* rd = getRecord();
@@ -649,7 +660,12 @@ CXXNewExpr* New(ArrayRef<Expr*> placementArgs, const Expr* expr, QualType t)
649660
placementArgs,
650661
SourceRange{},
651662
std::optional<Expr*>{},
652-
CXXNewExpr::CallInit,
663+
#if IS_CLANG_NEWER_THAN(17)
664+
CXXNewInitializationStyle::Parens
665+
#else
666+
CXXNewExpr::CallInit
667+
#endif
668+
,
653669
const_cast<Expr*>(expr),
654670
Ptr(t),
655671
ctx.getTrivialTypeSourceInfo(t),

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,15 @@ if (BUILD_INSIGHTS_OUTSIDE_LLVM)
383383
clangLex
384384
clangBasic
385385
clangRewrite
386+
clangSupport
386387
${LLVM_LIBS}
387388
${LLVM_SYSTEM_LIBS}
388389
)
389390

390-
if(${LLVM_PACKAGE_VERSION_PLAIN} VERSION_GREATER_EQUAL "15.0.0")
391+
if(${LLVM_PACKAGE_VERSION_PLAIN} VERSION_GREATER_EQUAL "18.0.0")
391392
set(ADDITIONAL_LIBS
392393
${ADDITIONAL_LIBS}
393-
clangSupport
394+
clangAPINotes
394395
)
395396
endif()
396397

CodeGenerator.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,12 @@ class TemporaryDeclFinder : public StmtVisitor<TemporaryDeclFinder>
947947
{},
948948
&ctx.Idents.get(mTempName),
949949
expr->getType(),
950-
ImplicitParamDecl::Other);
950+
#if IS_CLANG_NEWER_THAN(17)
951+
ImplicitParamKind::Other
952+
#else
953+
ImplicitParamDecl::Other
954+
#endif
955+
);
951956

952957
#endif
953958

@@ -1385,7 +1390,7 @@ void CodeGenerator::InsertInstantiationPoint(const SourceManager& sm,
13851390
{
13861391
const auto lineNo = sm.getSpellingLineNumber(instLoc);
13871392
const auto& fileId = sm.getFileID(instLoc);
1388-
if(const auto* file = sm.getFileEntryForID(fileId)) {
1393+
if(const auto file = sm.getFileEntryRefForID(fileId)) {
13891394
const auto fileWithDirName = file->getName();
13901395
const auto fileName = llvm::sys::path::filename(fileWithDirName);
13911396

@@ -2752,12 +2757,16 @@ void CodeGenerator::InsertArg(const GNUNullExpr* /*stmt*/)
27522757

27532758
void CodeGenerator::InsertArg(const CharacterLiteral* stmt)
27542759
{
2760+
#if IS_CLANG_NEWER_THAN(17)
2761+
#else
2762+
#define CharacterLiteralKind CharacterLiteral
2763+
#endif
27552764
switch(stmt->getKind()) {
2756-
case CharacterLiteral::Ascii: break;
2757-
case CharacterLiteral::Wide: mOutputFormatHelper.Append('L'); break;
2758-
case CharacterLiteral::UTF8: mOutputFormatHelper.Append("u8"sv); break;
2759-
case CharacterLiteral::UTF16: mOutputFormatHelper.Append('u'); break;
2760-
case CharacterLiteral::UTF32: mOutputFormatHelper.Append('U'); break;
2765+
case CharacterLiteralKind::Ascii: break;
2766+
case CharacterLiteralKind::Wide: mOutputFormatHelper.Append('L'); break;
2767+
case CharacterLiteralKind::UTF8: mOutputFormatHelper.Append("u8"sv); break;
2768+
case CharacterLiteralKind::UTF16: mOutputFormatHelper.Append('u'); break;
2769+
case CharacterLiteralKind::UTF32: mOutputFormatHelper.Append('U'); break;
27612770
}
27622771

27632772
switch(unsigned value = stmt->getValue()) {
@@ -2774,7 +2783,7 @@ void CodeGenerator::InsertArg(const CharacterLiteral* stmt)
27742783
case '\t': mOutputFormatHelper.Append("'\\t'"sv); break;
27752784
case '\v': mOutputFormatHelper.Append("'\\v'"sv); break;
27762785
default:
2777-
if(((value & ~0xFFu) == ~0xFFu) and (stmt->getKind() == CharacterLiteral::Ascii)) {
2786+
if(((value & ~0xFFu) == ~0xFFu) and (stmt->getKind() == CharacterLiteralKind::Ascii)) {
27782787
value &= 0xFFu;
27792788
}
27802789

@@ -3563,6 +3572,11 @@ void CodeGenerator::InsertAttribute(const Attr& attr)
35633572
// skip this attribute. Clang seems to tag final methods or classes with final
35643573
RETURN_IF(attr::Final == attr.getKind());
35653574

3575+
#if IS_CLANG_NEWER_THAN(17)
3576+
// skip this custom clang attribute
3577+
RETURN_IF(attr::NoInline == attr.getKind());
3578+
#endif
3579+
35663580
// Clang's printPretty misses the parameter pack ellipsis. Hence treat this special case here.
35673581
if(const auto* alignedAttr = dyn_cast_or_null<AlignedAttr>(&attr)) {
35683582
auto insert = [&](const QualType type, const TemplateTypeParmType* tmplTypeParam) {
@@ -4264,7 +4278,7 @@ void CodeGenerator::InsertArg(const Decl* stmt)
42644278

42654279
#include "CodeGeneratorTypes.h"
42664280

4267-
TODO(stmt, mOutputFormatHelper);
4281+
ToDo(stmt, mOutputFormatHelper);
42684282
}
42694283
//-----------------------------------------------------------------------------
42704284

@@ -4287,7 +4301,7 @@ void CodeGenerator::InsertArg(const Stmt* stmt)
42874301

42884302
#include "CodeGeneratorTypes.h"
42894303

4290-
TODO(stmt, mOutputFormatHelper);
4304+
ToDo(stmt, mOutputFormatHelper);
42914305
}
42924306
//-----------------------------------------------------------------------------
42934307

@@ -4383,6 +4397,9 @@ void CodeGenerator::InsertTemplateArg(const TemplateArgument& arg)
43834397
mOutputFormatHelper.Append(GetName(*arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl()));
43844398
break;
43854399
case TemplateArgument::Null: mOutputFormatHelper.Append("null"sv); break;
4400+
#if IS_CLANG_NEWER_THAN(17)
4401+
case TemplateArgument::StructuralValue: ToDo(arg, mOutputFormatHelper); break;
4402+
#endif
43864403
}
43874404
}
43884405
//-----------------------------------------------------------------------------
@@ -4411,7 +4428,11 @@ void CodeGenerator::HandleLocalStaticNonTrivialClass(const VarDecl* stmt)
44114428
ctx.getConstantArrayType(ctx.CharTy,
44124429
llvm::APInt(ctx.getTypeSize(ctx.getSizeType()), 0),
44134430
Sizeof(stmt->getType()),
4414-
ArrayType::ArraySizeModifier::Normal,
4431+
#if IS_CLANG_NEWER_THAN(17)
4432+
#else
4433+
ArrayType::
4434+
#endif
4435+
ArraySizeModifier::Normal,
44154436
0));
44164437

44174438
compilerStorageVar->setStorageClass(StorageClass::SC_Static);
@@ -4815,7 +4836,11 @@ void CodeGenerator::InsertFunctionNameWithReturnType(const FunctionDecl& d
48154836
// template requires-clause during creation of the template head.
48164837
InsertConceptConstraint(&decl);
48174838

4839+
#if IS_CLANG_NEWER_THAN(17)
4840+
if(decl.isPureVirtual()) {
4841+
#else
48184842
if(decl.isPure()) {
4843+
#endif
48194844
mOutputFormatHelper.Append(" = 0"sv);
48204845
}
48214846
}

CoroutinesCodeGenerator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,13 @@ void CoroutinesCodeGenerator::InsertCoroutine(const FunctionDecl& fd, const Coro
548548
if(const auto* cxxMethodDecl = dyn_cast_or_null<CXXMethodDecl>(&fd)) {
549549
funParamStorage.reserve(funParams.size() + 1);
550550

551-
cxxMethodType = cxxMethodDecl->getThisObjectType();
551+
cxxMethodType = cxxMethodDecl->
552+
#if IS_CLANG_NEWER_THAN(17)
553+
getFunctionObjectParameterType()
554+
#else
555+
getThisObjectType()
556+
#endif
557+
;
552558

553559
// In case we have a member function the first parameter is a reference to this. The following code injects
554560
// this parameter.

DPrint.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@
1616

1717
namespace clang::insights {
1818

19-
static void ToDo(const char* name, OutputFormatHelper& outputFormatHelper, std::string_view file, const int line)
19+
static void ToDo(std::string_view name, OutputFormatHelper& outputFormatHelper, std::source_location loc)
2020
{
21-
const auto fileName = [&]() {
22-
if(llvm::sys::path::is_separator(file[0])) {
23-
return std::string_view{llvm::sys::path::filename(file)};
21+
const auto fileName = [&]() -> std::string_view {
22+
if(llvm::sys::path::is_separator(loc.file_name()[0])) {
23+
return llvm::sys::path::filename(loc.file_name());
2424
}
2525

26-
return file;
26+
return loc.file_name();
2727
}();
2828

29-
outputFormatHelper.Append("/* INSIGHTS-TODO: "sv, fileName, ":"sv, line, " stmt: "sv, name, kwSpaceCCommentEnd);
29+
outputFormatHelper.Append(
30+
"/* INSIGHTS-TODO: "sv, fileName, ":"sv, loc.line(), " stmt: "sv, name, kwSpaceCCommentEnd);
3031
}
3132
//-----------------------------------------------------------------------------
3233

33-
void ToDo(const Stmt* stmt, OutputFormatHelper& outputFormatHelper, std::string_view file, const int line)
34+
void ToDo(const Stmt* stmt, OutputFormatHelper& outputFormatHelper, std::source_location loc)
3435
{
35-
const char* name = [&]() {
36+
const std::string_view name = [&]() {
3637
if(stmt and stmt->getStmtClassName()) {
3738
Dump(stmt);
3839

@@ -44,13 +45,13 @@ void ToDo(const Stmt* stmt, OutputFormatHelper& outputFormatHelper, std::string_
4445
return "";
4546
}();
4647

47-
ToDo(name, outputFormatHelper, file, line);
48+
ToDo(name, outputFormatHelper, loc);
4849
}
4950
//-----------------------------------------------------------------------------
5051

51-
void ToDo(const Decl* stmt, OutputFormatHelper& outputFormatHelper, std::string_view file, const int line)
52+
void ToDo(const Decl* stmt, OutputFormatHelper& outputFormatHelper, std::source_location loc)
5253
{
53-
const char* name = [&]() {
54+
const std::string_view name = [&]() {
5455
if(stmt and stmt->getDeclKindName()) {
5556
Dump(stmt);
5657
return stmt->getDeclKindName();
@@ -61,7 +62,15 @@ void ToDo(const Decl* stmt, OutputFormatHelper& outputFormatHelper, std::string_
6162
return "";
6263
}();
6364

64-
ToDo(name, outputFormatHelper, file, line);
65+
ToDo(name, outputFormatHelper, loc);
66+
}
67+
//-----------------------------------------------------------------------------
68+
69+
void ToDo(const class TemplateArgument& stmt, class OutputFormatHelper& outputFormatHelper, std::source_location loc)
70+
{
71+
const std::string_view name{StrCat("tmplArgKind: ", stmt.getKind())};
72+
73+
ToDo(name, outputFormatHelper, loc);
6574
}
6675
//-----------------------------------------------------------------------------
6776

DPrint.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef INSIGHTS_DPRINT_H
99
#define INSIGHTS_DPRINT_H
1010

11+
#include <source_location>
12+
1113
#include "InsightsStrCat.h"
1214
//-----------------------------------------------------------------------------
1315

@@ -118,13 +120,19 @@ inline void Error(const Stmt* stmt, const char* fmt, const auto&... args)
118120
//-----------------------------------------------------------------------------
119121

120122
/// \brief Helper function to generate TODO comments for an unsupported \ref Stmt.
121-
void ToDo(const class Stmt* stmt, class OutputFormatHelper& outputFormatHelper, std::string_view file, const int line);
123+
void ToDo(const class Stmt* stmt,
124+
class OutputFormatHelper& outputFormatHelper,
125+
std::source_location loc = std::source_location::current());
122126
/// \brief Helper function to generate TODO comments for an unsupported \ref Decl.
123-
void ToDo(const class Decl* stmt, class OutputFormatHelper& outputFormatHelper, std::string_view file, const int line);
127+
void ToDo(const class Decl* stmt,
128+
class OutputFormatHelper& outputFormatHelper,
129+
std::source_location loc = std::source_location::current());
130+
//-----------------------------------------------------------------------------
131+
/// \brief Helper function to generate TODO comments for an unsupported \ref TemplateArgument.
132+
void ToDo(const class TemplateArgument& stmt,
133+
class OutputFormatHelper& outputFormatHelper,
134+
std::source_location loc = std::source_location::current());
124135
//-----------------------------------------------------------------------------
125-
126-
/// \brief Convenience marco to get file-name and line-number for better analysis.
127-
#define TODO(stmt, outputFormatHelper) ToDo(stmt, outputFormatHelper, __FILE__, __LINE__)
128136

129137
} // namespace clang::insights
130138

docs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(CMAKE_CXX_STANDARD 17)
1+
set(CMAKE_CXX_STANDARD 20)
22
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33

44
add_executable(OptionDocumentationGenerator OptionDocumentationGenerator.cpp)

0 commit comments

Comments
 (0)