From c9cedde7c0ba396dadfabbf644c6329e65afebf9 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 6 Nov 2023 10:51:31 +0100 Subject: Adapt to various Clang 18 trunk enum rework "[clang][NFC] Refactor `CXXConstructExpr::ConstructionKind`", "[clang][NFC] Refactor `CharacterLiteral::CharacterKind`", "[clang][NFC] Refactor `StringLiteral::StringKind`", "[clang][NFC] Refactor `TagTypeKind` (#71160)" Change-Id: Ice802f6d662494781ad22fcf11ea5006de918254 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158983 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- compilerplugins/clang/check.hxx | 16 +++++++----- compilerplugins/clang/compat.hxx | 40 +++++++++++++++++++++++++++++ compilerplugins/clang/mergeclasses.cxx | 3 ++- compilerplugins/clang/privatebase.cxx | 3 ++- compilerplugins/clang/redundantcast.cxx | 2 +- compilerplugins/clang/salunicodeliteral.cxx | 3 ++- compilerplugins/clang/vclwidgets.cxx | 3 ++- 7 files changed, 58 insertions(+), 12 deletions(-) diff --git a/compilerplugins/clang/check.hxx b/compilerplugins/clang/check.hxx index a7b7ba820d09..af6cd355a416 100644 --- a/compilerplugins/clang/check.hxx +++ b/compilerplugins/clang/check.hxx @@ -16,6 +16,8 @@ #include #include +#include "compat.hxx" + namespace loplugin { class ContextCheck; @@ -188,7 +190,7 @@ ContextCheck TypeCheck::Class(llvm::StringRef id) if (!type_.isNull()) { auto const t = type_->getAs(); if (t != nullptr) { - return detail::checkRecordDecl(t->getDecl(), clang::TTK_Class, id); + return detail::checkRecordDecl(t->getDecl(), compat::TagTypeKind::Class, id); } } return ContextCheck(); @@ -199,7 +201,7 @@ ContextCheck TypeCheck::Struct(llvm::StringRef id) const if (!type_.isNull()) { auto const t = type_->getAs(); if (t != nullptr) { - return detail::checkRecordDecl(t->getDecl(), clang::TTK_Struct, id); + return detail::checkRecordDecl(t->getDecl(), compat::TagTypeKind::Struct, id); } } return ContextCheck(); @@ -231,12 +233,12 @@ ContextCheck TypeCheck::Typedef(llvm::StringRef id) const ContextCheck DeclCheck::Class(llvm::StringRef id) const { - return detail::checkRecordDecl(decl_, clang::TTK_Class, id); + return detail::checkRecordDecl(decl_, compat::TagTypeKind::Class, id); } ContextCheck DeclCheck::Struct(llvm::StringRef id) const { - return detail::checkRecordDecl(decl_, clang::TTK_Struct, id); + return detail::checkRecordDecl(decl_, compat::TagTypeKind::Struct, id); } ContextCheck DeclCheck::ClassOrStruct(llvm::StringRef id) const @@ -250,7 +252,7 @@ ContextCheck DeclCheck::ClassOrStruct(llvm::StringRef id) const ContextCheck DeclCheck::Union(llvm::StringRef id) const { - return detail::checkRecordDecl(decl_, clang::TTK_Union, id); + return detail::checkRecordDecl(decl_, compat::TagTypeKind::Union, id); } ContextCheck DeclCheck::Function(llvm::StringRef id) const @@ -294,13 +296,13 @@ ContextCheck ContextCheck::Namespace(llvm::StringRef id) const ContextCheck ContextCheck::Class(llvm::StringRef id) const { return detail::checkRecordDecl( - llvm::dyn_cast_or_null(context_), clang::TTK_Class, id); + llvm::dyn_cast_or_null(context_), compat::TagTypeKind::Class, id); } ContextCheck ContextCheck::Struct(llvm::StringRef id) const { return detail::checkRecordDecl( - llvm::dyn_cast_or_null(context_), clang::TTK_Struct, id); + llvm::dyn_cast_or_null(context_), compat::TagTypeKind::Struct, id); } bool isExtraWarnUnusedType(clang::QualType type); diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index df4052ef108a..d122933eeaaf 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -82,6 +82,24 @@ constexpr clang::ExprValueKind VK_PRValue = clang::VK_PRValue; constexpr clang::ExprValueKind VK_PRValue = clang::VK_RValue; #endif +namespace CXXConstructionKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::CXXConstructionKind Complete = clang::CXXConstructionKind::Complete; +#else +constexpr clang::CXXConstructExpr::ConstructionKind Complete = clang::CXXConstructExpr::CK_Complete; +#endif +} + +namespace CharacterLiteralKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::CharacterLiteralKind Ascii = clang::CharacterLiteralKind::Ascii; +#else +constexpr clang::CharacterLiteral::CharacterKind Ascii = clang::CharacterLiteral::Ascii; +#endif +} + namespace ElaboratedTypeKeyword { #if CLANG_VERSION >= 180000 @@ -102,6 +120,28 @@ constexpr clang::Linkage Module = clang::ModuleLinkage; #endif } +namespace StringLiteralKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::StringLiteralKind UTF8 = clang::StringLiteralKind::UTF8; +#else +constexpr clang::StringLiteral::StringKind UTF8 = clang::StringLiteral::UTF8; +#endif +} + +namespace TagTypeKind +{ +#if CLANG_VERSION >= 180000 +constexpr clang::TagTypeKind Class = clang::TagTypeKind::Class; +constexpr clang::TagTypeKind Struct = clang::TagTypeKind::Struct; +constexpr clang::TagTypeKind Union = clang::TagTypeKind::Union; +#else +constexpr clang::TagTypeKind Class = clang::TTK_Class; +constexpr clang::TagTypeKind Struct = clang::TTK_Struct; +constexpr clang::TagTypeKind Union = clang::TTK_Union; +#endif +} + inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) { clang::Expr::EvalResult res; bool b = expr->EvaluateAsInt(res, ctx); diff --git a/compilerplugins/clang/mergeclasses.cxx b/compilerplugins/clang/mergeclasses.cxx index dae8724bd3bf..5ac69bc52397 100644 --- a/compilerplugins/clang/mergeclasses.cxx +++ b/compilerplugins/clang/mergeclasses.cxx @@ -12,6 +12,7 @@ #include #include #include "config_clang.h" +#include "compat.hxx" #include "plugin.hxx" #include @@ -129,7 +130,7 @@ bool MergeClasses::VisitCXXConstructExpr( const CXXConstructExpr* pCXXConstructE return true; } // ignore calls when a sub-class is constructing its superclass - if (pCXXConstructExpr->getConstructionKind() != CXXConstructExpr::ConstructionKind::CK_Complete) { + if (pCXXConstructExpr->getConstructionKind() != compat::CXXConstructionKind::Complete) { return true; } const CXXConstructorDecl* pCXXConstructorDecl = pCXXConstructExpr->getConstructor(); diff --git a/compilerplugins/clang/privatebase.cxx b/compilerplugins/clang/privatebase.cxx index 210ce6376d66..677461302b15 100644 --- a/compilerplugins/clang/privatebase.cxx +++ b/compilerplugins/clang/privatebase.cxx @@ -9,6 +9,7 @@ #ifndef LO_CLANG_SHARED_PLUGINS +#include "compat.hxx" #include "plugin.hxx" namespace { @@ -33,7 +34,7 @@ void PrivateBase::run() { bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) { if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition() - || decl->getTagKind() != TTK_Class) + || decl->getTagKind() != compat::TagTypeKind::Class) { return true; } diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index eea609005228..6bace5282275 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -609,7 +609,7 @@ bool RedundantCast::VisitCXXReinterpretCastExpr( { if (loplugin::TypeCheck(sub->getType()).Pointer().Const().Char()) { if (auto const lit = dyn_cast(expr->getSubExprAsWritten())) { - if (lit->getKind() == clang::StringLiteral::UTF8) { + if (lit->getKind() == compat::StringLiteralKind::UTF8) { // Don't warn about // // redundant_cast(u8"...") diff --git a/compilerplugins/clang/salunicodeliteral.cxx b/compilerplugins/clang/salunicodeliteral.cxx index aa0a3950c8fa..0a8eeea4885b 100644 --- a/compilerplugins/clang/salunicodeliteral.cxx +++ b/compilerplugins/clang/salunicodeliteral.cxx @@ -9,13 +9,14 @@ #ifndef LO_CLANG_SHARED_PLUGINS #include "check.hxx" +#include "compat.hxx" #include "plugin.hxx" namespace { bool isAsciiCharacterLiteral(Expr const * expr) { if (auto const e = dyn_cast(expr)) { - return e->getKind() == CharacterLiteral::Ascii; + return e->getKind() == compat::CharacterLiteralKind::Ascii; } return false; } diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx index 2f5d6c57ab59..422041688a78 100644 --- a/compilerplugins/clang/vclwidgets.cxx +++ b/compilerplugins/clang/vclwidgets.cxx @@ -13,6 +13,7 @@ #include "plugin.hxx" #include "check.hxx" +#include "compat.hxx" #include "config_clang.h" #include "clang/AST/CXXInheritance.h" @@ -849,7 +850,7 @@ bool VCLWidgets::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr ) if (ignoreLocation(constructExpr)) { return true; } - if (constructExpr->getConstructionKind() != CXXConstructExpr::CK_Complete) { + if (constructExpr->getConstructionKind() != compat::CXXConstructionKind::Complete) { return true; } const CXXConstructorDecl* pConstructorDecl = constructExpr->getConstructor(); -- cgit