Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions ASTHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,12 @@ CXXRecordDecl* Struct(std::string_view name)
auto& ctx = GetGlobalAST();

return CXXRecordDecl::Create(
ctx, TagTypeKind::Struct, ctx.getTranslationUnitDecl(), {}, {}, &ctx.Idents.get(name), nullptr, false);
ctx, TagTypeKind::Struct, ctx.getTranslationUnitDecl(), {}, {}, &ctx.Idents.get(name), nullptr
#if IS_CLANG_NEWER_THAN(22)
#else
,false
#endif
);
};

auto* rd = getRecord();
Expand Down Expand Up @@ -549,7 +554,15 @@ FieldDecl* mkFieldDecl(DeclContext* dc, std::string_view name, QualType type)

InitListExpr* InitList(ArrayRef<Expr*> initExprs, QualType t)
{
auto* initList = new(GetGlobalAST()) InitListExpr(GetGlobalAST(), SourceLocation{}, initExprs, SourceLocation{});
auto* initList = new(GetGlobalAST()) InitListExpr(GetGlobalAST(),
SourceLocation{},
initExprs,
SourceLocation{}
#if IS_CLANG_NEWER_THAN(22)
,
false
#endif
);
initList->setType(t);

return initList;
Expand Down Expand Up @@ -676,19 +689,34 @@ QualType Typedef(std::string_view name, QualType underlayingType)
&ctx.Idents.get(name),
ctx.getTrivialTypeSourceInfo(underlayingType));

return ctx.getTypeDeclType(type);
return
#if IS_CLANG_NEWER_THAN(22)
ctx.getTypedefType(ElaboratedTypeKeyword::None, std::nullopt, type);
#else
ctx.getTypeDeclType(type);
#endif
}
//-----------------------------------------------------------------------------

QualType GetRecordDeclType(const CXXMethodDecl* md)
{
return QualType(md->getParent()->getTypeForDecl(), 0);
return
#if IS_CLANG_NEWER_THAN(22)
md->getParent()->getASTContext().getCanonicalTagType(md->getParent());
#else
QualType(md->getParent()->getTypeForDecl(), 0);
#endif
}
//-----------------------------------------------------------------------------

QualType GetRecordDeclType(const RecordDecl* rd)
{
return QualType(rd->getTypeForDecl(), 0);
return
#if IS_CLANG_NEWER_THAN(22)
rd->getASTContext().getCanonicalTagType(rd);
#else
QualType(rd->getTypeForDecl(), 0);
#endif
}
//-----------------------------------------------------------------------------

Expand Down
38 changes: 30 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ if (BUILD_INSIGHTS_OUTSIDE_LLVM)
endif()
endfunction(check_compiler)

check_compiler("GNU" 7.3)
check_compiler("Clang" 6.0)
check_compiler("GNU" 15.1)
check_compiler("Clang" 20.0)
check_compiler("MSVC" 19.25.0.0)

if(NOT HAVE_COMPILER)
Expand Down Expand Up @@ -392,6 +392,19 @@ if (BUILD_INSIGHTS_OUTSIDE_LLVM)
)
endif()

if(${LLVM_PACKAGE_VERSION_PLAIN} VERSION_GREATER_EQUAL "22.0.0")
set(ADDITIONAL_LIBS
${ADDITIONAL_LIBS}
clangScalableStaticAnalysisSourceTransformation
clangScalableStaticAnalysisAnalyses
clangScalableStaticAnalysisCore
clangUnifiedSymbolResolution
clangAnalysisLifetimeSafety
clangDependencyScanning
clangOptions
)
endif()

set(ADDITIONAL_LIBS
${ADDITIONAL_LIBS}
clangFrontend
Expand All @@ -406,6 +419,7 @@ if (BUILD_INSIGHTS_OUTSIDE_LLVM)
clangBasic
clangRewrite
clangSupport
${CLANG23_LIBS}
${LLVM_LIBS}
${LLVM_SYSTEM_LIBS}
)
Expand Down Expand Up @@ -548,12 +562,20 @@ if(CLANG_LINK_CLANG_DYLIB)
target_link_libraries(insights PRIVATE clang-cpp)
else()
# general include also provided by clang-build
target_link_libraries(insights
PRIVATE
${ADDITIONAL_LIBS}
clangTooling
clangASTMatchers
)
#if(CMAKE_CXX_LINK_GROUP_USING_RESCAN_SUPPORTED)
if(NOT APPLE)
target_link_libraries(insights
PRIVATE
"$<LINK_GROUP:RESCAN,${ADDITIONAL_LIBS};clangTooling;clangASTMatchers>"
)
else()
target_link_libraries(insights
PRIVATE
${ADDITIONAL_LIBS}
clangTooling
clangASTMatchers
)
endif()
endif()

if(LLVM_LINK_LLVM_DYLIB)
Expand Down
7 changes: 6 additions & 1 deletion CfrontCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ CfrontCodeGenerator::CfrontVtableData::CfrontVtableData()

vtableRecorDecl->completeDefinition();

vtableRecordType = QualType{vtableRecorDecl->getTypeForDecl(), 0u};
vtableRecordType =
#if IS_CLANG_NEWER_THAN(22)
vtableRecorDecl->getASTContext().getCanonicalTagType(vtableRecorDecl);
#else
QualType{vtableRecorDecl->getTypeForDecl(), 0u};
#endif
}
//-----------------------------------------------------------------------------

Expand Down
83 changes: 64 additions & 19 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,25 @@ void CodeGenerator::InsertArg(const CXXForRangeStmt* rangeForStmt)
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertQualifierAndName(const DeclarationName& declName,
const NestedNameSpecifier* qualifier,
const bool hasTemplateKeyword)
void CodeGenerator::InsertQualifierAndName(const DeclarationName& declName,
const NestedNameSpecifier
#if not IS_CLANG_NEWER_THAN(22)
*
#endif
qualifier,
const bool hasTemplateKeyword)
{
mOutputFormatHelper.Append(ScopeHandler::RemoveCurrentScope(GetNestedName(qualifier)),
ValueOrDefault(hasTemplateKeyword, kwTemplateSpace),
declName.getAsString());
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertNamespace(const NestedNameSpecifier* stmt)
void CodeGenerator::InsertNamespace(const NestedNameSpecifier
#if not IS_CLANG_NEWER_THAN(22)
*
#endif
stmt)
{
mOutputFormatHelper.Append(ScopeHandler::RemoveCurrentScope(GetNestedName(stmt)));
}
Expand Down Expand Up @@ -2406,8 +2414,14 @@ void CodeGenerator::InsertArg(const DeclRefExpr* stmt)
if(const auto* ctx = stmt->getDecl()->getDeclContext(); not ctx->isFunctionOrMethod() and
not isa<NonTypeTemplateParmDecl>(stmt->getDecl()) and
not GetInsightsOptions().UseShow2C) {
if(const auto* qualifier = stmt->getQualifier();
qualifier and (qualifier->getKind() == NestedNameSpecifier::SpecifierKind::Global)) {
if(const auto qualifier = stmt->getQualifier();
qualifier and (
#if IS_CLANG_NEWER_THAN(22)
qualifier.getKind() == NestedNameSpecifier::Kind::Global
#else
qualifier->getKind() == NestedNameSpecifier::SpecifierKind::Global
#endif
)) {
// According to
// https://clang.llvm.org/doxygen/classclang_1_1NestedNameSpecifier.html#ac707a113605ed4283684b8c05664eb6f
// the global specifier is not stored.
Expand Down Expand Up @@ -3107,20 +3121,33 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)
const bool carriesNamespace{[&] {
if(const auto tn = templateSpecializationType->getTemplateName();
(TemplateName::QualifiedTemplate == tn.getKind()) or (TemplateName::DependentTemplate == tn.getKind())) {
const auto* qtn = tn.getAsQualifiedTemplateName();

return qtn->getQualifier() != nullptr;
if(const auto* qtn = tn.getAsQualifiedTemplateName()) {
return static_cast<bool>(qtn->getQualifier());
}
}

return false;
}()};

#if not IS_CLANG_NEWER_THAN(22)
if(const auto* elaboratedType = underlyingType->getAs<ElaboratedType>()) {
if(templateSpecializationType->isSugared() and not carriesNamespace) {
// do this only if the templateSpecializationType does not carry a nestedns
InsertNamespace(elaboratedType->getQualifier());
}
}
#else
if(TemplateName::DependentTemplate == templateSpecializationType->getTemplateName().getKind()) {
mOutputFormatHelper.Append(GetElaboratedTypeKeyword(templateSpecializationType->getKeyword()));
}

if(templateSpecializationType->isSugared() and not carriesNamespace) {
// The scope was written in front of the typedef, for example std::chrono::nanoseconds.
if(const auto* typedefType = dyn_cast_or_null<TypedefType>(underlyingType.getTypePtrOrNull())) {
InsertNamespace(typedefType->getQualifier());
}
}
#endif

StringStream stream{};
stream.Print(*templateSpecializationType);
Expand All @@ -3129,21 +3156,16 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)

InsertTemplateArgs(*templateSpecializationType);

#if not IS_CLANG_NEWER_THAN(22)
} else if(auto* depSpecType = underlyingType->getAs<DependentTemplateSpecializationType>()) {
mOutputFormatHelper.Append(GetElaboratedTypeKeyword(depSpecType->getKeyword()));

#if IS_CLANG_NEWER_THAN(20)
InsertNamespace(depSpecType->getDependentTemplateName().getQualifier());

mOutputFormatHelper.Append(kwTemplateSpace, GetName(depSpecType->getDependentTemplateName()));
#else
InsertNamespace(depSpecType->getQualifier());

mOutputFormatHelper.Append(kwTemplateSpace, depSpecType->getIdentifier()->getName());
#endif

InsertTemplateArgs(*depSpecType);

#endif
} else {
mOutputFormatHelper.Append(GetName(underlyingType));
}
Expand Down Expand Up @@ -4313,7 +4335,7 @@ void CodeGenerator::InsertArgWithParensIfNeeded(const Stmt* stmt)
void CodeGenerator::InsertSuffix(const QualType& type)
{
if(const auto* typePtr = type.getTypePtrOrNull(); typePtr and typePtr->isBuiltinType()) {
if(const auto* bt = dyn_cast_or_null<BuiltinType>(typePtr)) {
if(const auto* bt = type->getAs<clang::BuiltinType>()) {
const auto kind = bt->getKind();

mOutputFormatHelper.Append(GetBuiltinTypeSuffix(kind));
Expand Down Expand Up @@ -4929,7 +4951,13 @@ void CodeGenerator::InsertFunctionNameWithReturnType(const FunctionDecl& d

if(decl.isDeleted()) {
mOutputFormatHelper.Append(kwSpaceEqualsDelete);
if(auto* delInfo = decl.getDefalutedOrDeletedInfo()) {
if(auto* delInfo =
#if IS_CLANG_NEWER_THAN(22)
decl.getDefaultedOrDeletedInfo()
#else
decl.getDefalutedOrDeletedInfo()
#endif
) {
WrapInParens([&]() { InsertArg(delInfo->getDeletedMessage()); }, AddSpaceAtTheEnd::No);
} else {
mOutputFormatHelper.AppendSemiNewLine();
Expand Down Expand Up @@ -5070,6 +5098,7 @@ void StructuredBindingsCodeGenerator::InsertArg(const BindingDecl* stmt)

// Assume that we are looking at a builtin type. We have to construct the variable declaration information.
auto type = stmt->getType();
bool addConstCast{};

// If we have a holding var we are looking at a user defined type like tuple and those the defaults from above
// are wrong. This type contains the variable declaration so we insert this.
Expand All @@ -5083,8 +5112,18 @@ void StructuredBindingsCodeGenerator::InsertArg(const BindingDecl* stmt)
// rvalue reference because then the call is get(std::move(e))
type = holdingVar->getType().getCanonicalType();

// The holding variable's type is always a reference. Make sure we do not lose it.
if(not type->isReferenceType()) {
type = stmt->getASTContext().getRValueReferenceType(type);
}

bindingStmt = holdingVar->getAnyInitializer();

// Newer Clang versions no longer add a NoOp cast to bind a `T&&` with const to a prvalue of a non-class type.
addConstCast = type->isRValueReferenceType() and type->getPointeeType().isConstQualified() and
not type->getPointeeType()->isRecordType() and bindingStmt and bindingStmt->isPRValue() and
not isa<CastExpr>(bindingStmt->IgnoreParens());

} else if(not type->isLValueReferenceType()) {
type = stmt->getASTContext().getLValueReferenceType(type);
}
Expand All @@ -5095,7 +5134,13 @@ void StructuredBindingsCodeGenerator::InsertArg(const BindingDecl* stmt)
GetTypeNameAsParameter(type, GetName(*stmt)),
hlpAssing);

InsertArg(bindingStmt);
if(addConstCast) {
mOutputFormatHelper.Append(kwStaticCast, "<"sv, GetName(type->getPointeeType()), ">"sv);
WrapInParens([&] { InsertArg(bindingStmt); });

} else {
InsertArg(bindingStmt);
}

mOutputFormatHelper.AppendSemiNewLine();
}
Expand Down
26 changes: 21 additions & 5 deletions CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,13 @@ class CodeGenerator
}
}

void InsertQualifierAndName(const DeclarationName& declName,
const NestedNameSpecifier* qualifier,
const bool hasTemplateKeyword);
void InsertQualifierAndName(const DeclarationName& declName,
const NestedNameSpecifier
#if not IS_CLANG_NEWER_THAN(22)
*
#endif
qualifier,
const bool hasTemplateKeyword);

/// For a special case, when a LambdaExpr occurs in a Constructor from an
/// in class initializer, there is a need for a more narrow scope for the \c LAMBDA_SCOPE_HELPER.
Expand All @@ -326,7 +330,11 @@ class CodeGenerator
void InsertTemplateArgsObjectParam(const ArrayRef<TemplateArgument>& array);
void InsertTemplateArgsObjectParam(const TemplateParamObjectDecl& param);

void InsertNamespace(const NestedNameSpecifier* namespaceSpecifier);
void InsertNamespace(const NestedNameSpecifier
#if not IS_CLANG_NEWER_THAN(22)
*
#endif
namespaceSpecifier);
void ParseDeclContext(const DeclContext* Ctx);

STRONG_BOOL(SkipBody);
Expand Down Expand Up @@ -552,7 +560,15 @@ class CoroutinesCodeGenerator final : public CodeGenerator
static inline llvm::DenseMap<const Expr*, std::pair<const DeclRefExpr*, std::string>>
mOpaqueValues{}; ///! Keeps track of the current set of opaque value

QualType GetFrameType() const { return QualType(mASTData.mFrameType->getTypeForDecl(), 0); }
QualType GetFrameType() const
{
return
#if IS_CLANG_NEWER_THAN(22)
mASTData.mFrameType->getASTContext().getCanonicalTagType(mASTData.mFrameType);
#else
QualType(mASTData.mFrameType->getTypeForDecl(), 0);
#endif
}
QualType GetFramePointerType() const;

std::string BuildResumeLabelName(int) const;
Expand Down
3 changes: 3 additions & 0 deletions CodeGeneratorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ IGNORED_STMT(OMPParallelForDirective)
IGNORED_DECL(UsingShadowDecl)
IGNORED_DECL(UsingPackDecl)
IGNORED_DECL(EmptyDecl) // stray semicolon?
#if IS_CLANG_NEWER_THAN(22)
IGNORED_DECL(ExplicitInstantiationDecl)
#endif

SUPPORTED_DECL(BindingDecl)
SUPPORTED_DECL(CXXDeductionGuideDecl)
Expand Down
Loading
Loading