2015-12-09 00:01:47 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2016-06-28 18:54:31 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
2017-12-15 14:20:38 +01:00
|
|
|
#include <clang/AST/DeclCXX.h>
|
2019-10-14 11:42:20 +02:00
|
|
|
#include <clang/AST/DeclTemplate.h>
|
2017-12-15 14:20:38 +01:00
|
|
|
|
2016-06-28 18:54:31 +02:00
|
|
|
#include "check.hxx"
|
2025-03-23 22:06:42 +01:00
|
|
|
#include "compat.hxx"
|
2015-12-09 00:01:47 +01:00
|
|
|
|
|
|
|
namespace loplugin {
|
|
|
|
|
2017-07-14 09:02:11 +02:00
|
|
|
TypeCheck TypeCheck::NonConst() const {
|
|
|
|
return !type_.isNull() && !type_.isConstQualified()
|
|
|
|
? *this : TypeCheck();
|
|
|
|
// returning TypeCheck(type_.getUnqualifiedType()) instead of *this
|
|
|
|
// may look tempting, but could remove sugar we might be interested in
|
|
|
|
// checking for
|
|
|
|
}
|
|
|
|
|
2016-12-18 13:52:04 +01:00
|
|
|
TypeCheck TypeCheck::NonConstVolatile() const {
|
|
|
|
return
|
|
|
|
(!type_.isNull() && !type_.isConstQualified()
|
|
|
|
&& !type_.isVolatileQualified())
|
|
|
|
? *this : TypeCheck();
|
|
|
|
// returning TypeCheck(type_.getUnqualifiedType()) instead of *this
|
|
|
|
// may look tempting, but could remove sugar we might be interested in
|
|
|
|
// checking for
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:01:47 +01:00
|
|
|
TypeCheck TypeCheck::Const() const {
|
|
|
|
return
|
|
|
|
(!type_.isNull() && type_.isConstQualified()
|
|
|
|
&& !type_.isVolatileQualified())
|
|
|
|
? *this : TypeCheck();
|
|
|
|
// returning TypeCheck(type_.getUnqualifiedType()) instead of *this
|
|
|
|
// may look tempting, but could remove sugar we might be interested in
|
|
|
|
// checking for
|
|
|
|
}
|
|
|
|
|
2016-12-18 13:52:04 +01:00
|
|
|
TypeCheck TypeCheck::Volatile() const {
|
|
|
|
return
|
|
|
|
(!type_.isNull() && !type_.isConstQualified()
|
|
|
|
&& type_.isVolatileQualified())
|
|
|
|
? *this : TypeCheck();
|
|
|
|
// returning TypeCheck(type_.getUnqualifiedType()) instead of *this
|
|
|
|
// may look tempting, but could remove sugar we might be interested in
|
|
|
|
// checking for
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeCheck TypeCheck::ConstVolatile() const {
|
|
|
|
return
|
|
|
|
(!type_.isNull() && type_.isConstQualified()
|
|
|
|
&& type_.isVolatileQualified())
|
|
|
|
? *this : TypeCheck();
|
|
|
|
// returning TypeCheck(type_.getUnqualifiedType()) instead of *this
|
|
|
|
// may look tempting, but could remove sugar we might be interested in
|
|
|
|
// checking for
|
|
|
|
}
|
|
|
|
|
Improved loplugin:staticanonymous -> redundantstatic
...now also covering variables with internal linkage that don't need a redundant
"static". (Unlike with functions, with variables there are also cases that are
not in an unnamed namespace, hence the rename of the plugin.)
All the relevant changes across the code base have been done in the preceding
"Upcoming improved loplugin:staticanonymous -> redundantstatic" commits.
Ideally the changes would have been done with a rewriting plugin, but it can be
quite tedious in general to identify the correct occurrence of "static" that
must be removed, consider e.g.
struct { int init() { static int n; return n++; } int x = init(); } static
const a[10] = {};
However, it turned out that in all cases across the code base, the relevant
"static" was either at the start of the declaration or came after an initial
"const". So I temporarily changed the plugin with
> --- a/compilerplugins/clang/redundantstatic.cxx
> +++ b/compilerplugins/clang/redundantstatic.cxx
> @@ -59,7 +59,7 @@ class RedundantStatic
> }
> report(
> DiagnosticsEngine::Warning, "redundant 'static' keyword in unnamed namespace",
> - decl->getLocation())
> + decl->getBeginLoc())
> << decl->getSourceRange();
> return true;
> }
> @@ -73,7 +73,7 @@ class RedundantStatic
> DiagnosticsEngine::Warning,
> "non-inline variable of non-volatile const-qualified type is redundantly marked as"
> " 'static'",
> - decl->getLocation())
> + decl->getBeginLoc())
> << decl->getSourceRange();
> return true;
> }
to report the diagnostics at the start of the declarations (instead of at a more
natural place which is typically somewhere in the middle of the declaration),
compiled LO from within Emacs and then ran a function
> (defun doit ()
> (interactive)
> (while t
> (next-error)
> (with-current-buffer (window-buffer)
> (when (re-search-forward
> "\\=\\(\\<static\\>\\s *\\|\\(\\<const\\>\\)\\s +\\<static\\>\\)"
> nil t)
> (replace-match "\\2")))))
to do all the replacements. (Plus solenv/clang-format/reformat-formatted-files
where necessary.)
Change-Id: Ie7efc8e0593a407c390a6a7a08c81e547410f18a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97779
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-07-02 21:12:04 +02:00
|
|
|
TypeCheck TypeCheck::ConstNonVolatile() const {
|
|
|
|
return
|
|
|
|
(!type_.isNull() && type_.isConstQualified()
|
|
|
|
&& !type_.isVolatileQualified())
|
|
|
|
? *this : TypeCheck();
|
|
|
|
// returning TypeCheck(type_.getUnqualifiedType()) instead of *this
|
|
|
|
// may look tempting, but could remove sugar we might be interested in
|
|
|
|
// checking for
|
|
|
|
}
|
|
|
|
|
2016-12-18 13:52:04 +01:00
|
|
|
TerminalCheck TypeCheck::Void() const {
|
|
|
|
return TerminalCheck(
|
|
|
|
!type_.isNull()
|
|
|
|
&& type_->isSpecificBuiltinType(clang::BuiltinType::Void));
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:01:47 +01:00
|
|
|
TerminalCheck TypeCheck::Char() const {
|
|
|
|
return TerminalCheck(
|
|
|
|
!type_.isNull()
|
|
|
|
&& (type_->isSpecificBuiltinType(clang::BuiltinType::Char_S)
|
|
|
|
|| type_->isSpecificBuiltinType(clang::BuiltinType::Char_U)));
|
|
|
|
}
|
|
|
|
|
2016-06-19 21:29:43 +02:00
|
|
|
TerminalCheck TypeCheck::AnyBoolean() const {
|
|
|
|
if (type_->isBooleanType()) {
|
|
|
|
return TerminalCheck(true);
|
|
|
|
}
|
|
|
|
auto t = type_->getAs<clang::TypedefType>();
|
|
|
|
if (t == nullptr) {
|
|
|
|
return TerminalCheck(false);
|
|
|
|
}
|
|
|
|
auto n =t->getDecl()->getName();
|
|
|
|
return TerminalCheck(
|
|
|
|
n == "sal_Bool" || n == "BOOL" || n == "Boolean" || n == "FT_Bool"
|
2016-12-22 09:19:00 +01:00
|
|
|
|| n == "FcBool" || n == "GLboolean" || n == "NPBool" || n == "TW_BOOL"
|
|
|
|
|| n == "UBool" || n == "boolean" || n == "dbus_bool_t"
|
2018-08-13 09:05:19 +02:00
|
|
|
|| n == "gboolean" || n == "hb_bool_t" || n == "jboolean" || n == "my_bool");
|
2016-06-19 21:29:43 +02:00
|
|
|
}
|
|
|
|
|
2015-12-09 00:01:47 +01:00
|
|
|
TypeCheck TypeCheck::LvalueReference() const {
|
|
|
|
if (!type_.isNull()) {
|
|
|
|
auto const t = type_->getAs<clang::LValueReferenceType>();
|
|
|
|
if (t != nullptr) {
|
|
|
|
return TypeCheck(t->getPointeeType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TypeCheck();
|
|
|
|
}
|
|
|
|
|
2020-12-04 16:24:56 +01:00
|
|
|
TypeCheck TypeCheck::RvalueReference() const {
|
|
|
|
if (!type_.isNull()) {
|
|
|
|
auto const t = type_->getAs<clang::RValueReferenceType>();
|
|
|
|
if (t != nullptr) {
|
|
|
|
return TypeCheck(t->getPointeeType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TypeCheck();
|
|
|
|
}
|
|
|
|
|
2016-06-03 10:58:26 +02:00
|
|
|
TypeCheck TypeCheck::Pointer() const {
|
|
|
|
if (!type_.isNull()) {
|
|
|
|
auto const t = type_->getAs<clang::PointerType>();
|
|
|
|
if (t != nullptr) {
|
|
|
|
return TypeCheck(t->getPointeeType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TypeCheck();
|
|
|
|
}
|
|
|
|
|
2024-02-07 09:39:27 +01:00
|
|
|
TypeCheck TypeCheck::MemberPointerOf() const {
|
|
|
|
if (!type_.isNull()) {
|
|
|
|
auto const t = type_->getAs<clang::MemberPointerType>();
|
|
|
|
if (t != nullptr) {
|
2025-03-23 22:06:42 +01:00
|
|
|
return TypeCheck(compat::getClass(t));
|
2024-02-07 09:39:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TypeCheck();
|
|
|
|
}
|
|
|
|
|
2017-03-20 09:01:33 +02:00
|
|
|
TerminalCheck TypeCheck::Enum() const {
|
|
|
|
if (!type_.isNull()) {
|
|
|
|
auto const t = type_->getAs<clang::EnumType>();
|
|
|
|
if (t != nullptr) {
|
|
|
|
return TerminalCheck(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TerminalCheck(false);
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:46:57 +02:00
|
|
|
TypeCheck TypeCheck::Typedef() const {
|
|
|
|
if (!type_.isNull()) {
|
|
|
|
if (auto const t = type_->getAs<clang::TypedefType>()) {
|
|
|
|
return TypeCheck(t->desugar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TypeCheck();
|
|
|
|
}
|
|
|
|
|
2019-10-14 11:42:20 +02:00
|
|
|
DeclCheck TypeCheck::TemplateSpecializationClass() const {
|
|
|
|
if (!type_.isNull()) {
|
|
|
|
if (auto const t = type_->getAs<clang::TemplateSpecializationType>()) {
|
|
|
|
if (!t->isTypeAlias()) {
|
|
|
|
if (auto const d = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(
|
|
|
|
t->getTemplateName().getAsTemplateDecl()))
|
|
|
|
{
|
|
|
|
return DeclCheck(d->getTemplatedDecl());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DeclCheck();
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:01:47 +01:00
|
|
|
TypeCheck TypeCheck::NotSubstTemplateTypeParmType() const {
|
|
|
|
return
|
|
|
|
(!type_.isNull()
|
|
|
|
&& type_->getAs<clang::SubstTemplateTypeParmType>() == nullptr)
|
|
|
|
? *this : TypeCheck();
|
|
|
|
}
|
|
|
|
|
2016-06-28 18:54:31 +02:00
|
|
|
ContextCheck DeclCheck::Operator(clang::OverloadedOperatorKind op) const {
|
|
|
|
assert(op != clang::OO_None);
|
|
|
|
auto f = llvm::dyn_cast_or_null<clang::FunctionDecl>(decl_);
|
|
|
|
return ContextCheck(
|
|
|
|
f != nullptr && f->getOverloadedOperator() == op
|
|
|
|
? f->getDeclContext() : nullptr);
|
|
|
|
}
|
|
|
|
|
2016-06-29 11:31:13 +02:00
|
|
|
ContextCheck DeclCheck::MemberFunction() const {
|
|
|
|
auto m = llvm::dyn_cast_or_null<clang::CXXMethodDecl>(decl_);
|
|
|
|
return ContextCheck(m == nullptr ? nullptr : m->getParent());
|
|
|
|
}
|
|
|
|
|
2019-08-28 11:17:20 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool isGlobalNamespace(clang::DeclContext const * context) {
|
|
|
|
assert(context != nullptr);
|
2022-04-05 11:53:16 +02:00
|
|
|
return context->getEnclosingNamespaceContext()->isTranslationUnit();
|
2019-08-28 11:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-28 18:54:31 +02:00
|
|
|
TerminalCheck ContextCheck::GlobalNamespace() const {
|
2019-08-28 11:17:20 +02:00
|
|
|
return TerminalCheck(context_ != nullptr && isGlobalNamespace(context_));
|
2015-12-09 00:01:47 +01:00
|
|
|
}
|
|
|
|
|
2016-06-28 18:54:31 +02:00
|
|
|
TerminalCheck ContextCheck::StdNamespace() const {
|
2016-06-28 16:25:55 +02:00
|
|
|
return TerminalCheck(
|
2022-12-22 09:33:05 +01:00
|
|
|
context_ != nullptr && lookThroughLinkageSpec()->isStdNamespace());
|
2015-12-09 00:01:47 +01:00
|
|
|
}
|
|
|
|
|
2019-08-28 11:17:20 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool isStdOrNestedNamespace(clang::DeclContext const * context) {
|
|
|
|
assert(context != nullptr);
|
|
|
|
if (!context->isNamespace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isGlobalNamespace(context)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (context->isStdNamespace()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isStdOrNestedNamespace(context->getParent());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TerminalCheck ContextCheck::StdOrNestedNamespace() const {
|
2022-12-22 09:33:05 +01:00
|
|
|
return TerminalCheck(context_ != nullptr && isStdOrNestedNamespace(lookThroughLinkageSpec()));
|
2019-08-28 11:17:20 +02:00
|
|
|
}
|
|
|
|
|
2016-06-28 18:54:31 +02:00
|
|
|
ContextCheck ContextCheck::AnonymousNamespace() const {
|
2022-12-22 09:33:05 +01:00
|
|
|
auto n = llvm::dyn_cast_or_null<clang::NamespaceDecl>(lookThroughLinkageSpec());
|
2016-06-28 18:54:31 +02:00
|
|
|
return ContextCheck(
|
2016-06-28 17:48:22 +02:00
|
|
|
n != nullptr && n->isAnonymousNamespace() ? n->getParent() : nullptr);
|
|
|
|
}
|
|
|
|
|
2022-12-22 09:33:05 +01:00
|
|
|
clang::DeclContext const * ContextCheck::lookThroughLinkageSpec() const {
|
|
|
|
if (context_ != nullptr && context_->getDeclKind() == clang::Decl::LinkageSpec) {
|
|
|
|
return context_->getParent();
|
|
|
|
}
|
|
|
|
return context_;
|
|
|
|
}
|
|
|
|
|
2017-07-03 12:34:38 +02:00
|
|
|
namespace {
|
|
|
|
|
2017-12-15 14:20:38 +01:00
|
|
|
bool BaseCheckNotSomethingInterestingSubclass(const clang::CXXRecordDecl *BaseDefinition) {
|
2017-07-03 12:34:38 +02:00
|
|
|
if (BaseDefinition) {
|
|
|
|
auto tc = TypeCheck(BaseDefinition);
|
|
|
|
if (tc.Class("Dialog").GlobalNamespace() || tc.Class("SfxPoolItem").GlobalNamespace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDerivedFromSomethingInteresting(const clang::CXXRecordDecl *decl) {
|
|
|
|
if (!decl)
|
|
|
|
return false;
|
|
|
|
auto tc = TypeCheck(decl);
|
|
|
|
if (tc.Class("Dialog"))
|
|
|
|
return true;
|
|
|
|
if (tc.Class("SfxPoolItem"))
|
|
|
|
return true;
|
|
|
|
if (!decl->hasDefinition()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (// not sure what hasAnyDependentBases() does,
|
|
|
|
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
|
|
|
|
!decl->hasAnyDependentBases() &&
|
2020-03-01 20:09:44 +01:00
|
|
|
!decl->forallBases(BaseCheckNotSomethingInterestingSubclass)) {
|
2017-07-03 12:34:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isExtraWarnUnusedType(clang::QualType type) {
|
|
|
|
auto const rec = type->getAsCXXRecordDecl();
|
|
|
|
if (rec == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto const tc = TypeCheck(rec);
|
|
|
|
// Check some common non-LO types:
|
2017-11-08 15:23:24 +01:00
|
|
|
if (tc.Class("basic_string").StdNamespace()
|
2017-11-09 12:59:44 +02:00
|
|
|
|| tc.Class("deque").StdNamespace()
|
2017-11-08 15:23:24 +01:00
|
|
|
|| tc.Class("list").StdNamespace()
|
2017-11-09 12:59:44 +02:00
|
|
|
|| tc.Class("map").StdNamespace()
|
|
|
|
|| tc.Class("pair").StdNamespace()
|
|
|
|
|| tc.Class("queue").StdNamespace()
|
|
|
|
|| tc.Class("set").StdNamespace()
|
|
|
|
|| tc.Class("stack").StdNamespace()
|
|
|
|
|| tc.Class("unordered_map").StdNamespace()
|
|
|
|
|| tc.Class("unordered_set").StdNamespace()
|
2017-11-08 15:23:24 +01:00
|
|
|
|| tc.Class("vector").StdNamespace())
|
2017-07-03 12:34:38 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isDerivedFromSomethingInteresting(rec);
|
|
|
|
}
|
|
|
|
|
2018-03-23 13:18:34 +01:00
|
|
|
namespace {
|
|
|
|
|
2020-01-09 19:38:32 +01:00
|
|
|
// Make sure Foo and ::Foo are considered equal:
|
|
|
|
bool areSameSugaredType(clang::QualType type1, clang::QualType type2) {
|
|
|
|
auto t1 = type1.getLocalUnqualifiedType();
|
|
|
|
if (auto const et = llvm::dyn_cast<clang::ElaboratedType>(t1)) {
|
|
|
|
t1 = et->getNamedType();
|
|
|
|
}
|
|
|
|
auto t2 = type2.getLocalUnqualifiedType();
|
|
|
|
if (auto const et = llvm::dyn_cast<clang::ElaboratedType>(t2)) {
|
|
|
|
t2 = et->getNamedType();
|
|
|
|
}
|
|
|
|
return t1 == t2;
|
|
|
|
}
|
|
|
|
|
2018-03-23 13:18:34 +01:00
|
|
|
bool isArithmeticOp(clang::Expr const * expr) {
|
|
|
|
expr = expr->IgnoreParenImpCasts();
|
|
|
|
if (auto const e = llvm::dyn_cast<clang::BinaryOperator>(expr)) {
|
|
|
|
switch (e->getOpcode()) {
|
|
|
|
case clang::BO_Mul:
|
|
|
|
case clang::BO_Div:
|
|
|
|
case clang::BO_Rem:
|
|
|
|
case clang::BO_Add:
|
|
|
|
case clang::BO_Sub:
|
|
|
|
case clang::BO_Shl:
|
|
|
|
case clang::BO_Shr:
|
|
|
|
case clang::BO_And:
|
|
|
|
case clang::BO_Xor:
|
|
|
|
case clang::BO_Or:
|
|
|
|
return true;
|
|
|
|
case clang::BO_Comma:
|
|
|
|
return isArithmeticOp(e->getRHS());
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return llvm::isa<clang::UnaryOperator>(expr)
|
|
|
|
|| llvm::isa<clang::AbstractConditionalOperator>(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isOkToRemoveArithmeticCast(
|
|
|
|
clang::ASTContext & context, clang::QualType t1, clang::QualType t2, const clang::Expr* subExpr)
|
|
|
|
{
|
|
|
|
// Don't warn if the types are arithmetic (in the C++ meaning), and: either
|
2018-08-16 22:15:05 +02:00
|
|
|
// at least one is a typedef or decltype (and if both are, they're different),
|
2018-03-23 13:18:34 +01:00
|
|
|
// or the sub-expression involves some operation that is likely to change
|
|
|
|
// types through promotion, or the sub-expression is an integer literal (so
|
|
|
|
// its type generally depends on its value and suffix if any---even with a
|
|
|
|
// suffix like L it could still be either long or long long):
|
|
|
|
if ((t1->isIntegralType(context)
|
|
|
|
|| t1->isRealFloatingType())
|
2020-01-09 19:38:32 +01:00
|
|
|
&& ((!areSameSugaredType(t1, t2)
|
2018-03-23 13:18:34 +01:00
|
|
|
&& (loplugin::TypeCheck(t1).Typedef()
|
2018-08-16 22:15:05 +02:00
|
|
|
|| loplugin::TypeCheck(t2).Typedef()
|
|
|
|
|| llvm::isa<clang::DecltypeType>(t1) || llvm::isa<clang::DecltypeType>(t2)))
|
2018-03-23 13:18:34 +01:00
|
|
|
|| isArithmeticOp(subExpr)
|
|
|
|
|| llvm::isa<clang::IntegerLiteral>(subExpr->IgnoreParenImpCasts())))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-06 14:39:13 +01:00
|
|
|
|
Fix implementation of loplugin::isDerivedFrom
...where clang::CXXRecordDecl::forallBases is documented as: "This routine
returns false if the class has non-computable base classes." So, presumably
since
<https://github.com/llvm/llvm-project/commit/bf099f4682bf088aaa49b2c72fb1ef3250213fbb>
"[llvm][ADT] Structured bindings for move-only types in `StringMap` (#114676)"
changed
> -template <std::size_t I, typename ValueTy>
> -struct tuple_element<I, llvm::StringMapEntry<ValueTy>>
> - : std::conditional<I == 0, llvm::StringRef, ValueTy> {};
> +template <std::size_t Index, typename ValueTy>
> +struct std::tuple_element<Index, llvm::StringMapEntry<ValueTy>>
> + : std::tuple_element<Index, std::pair<llvm::StringRef, ValueTy>> {};
in LLVM's llvm/include/llvm/ADT/StringMapEntry.h, our !forallBases check here
started to trivially always be true for that struct tuple_element
specialization, so the isDerivedFrom check in
CheckFileVisitor::VisitCXXRecordDecl in
compilerplugins/clang/sharedvisitor/analyzer.cxx started to erroneously be true
for that struct, so it started to generate
compilerplugins/clang/sharedvisitor/*.plugininfo files with bogus extra
> InfoVersion:1
> ClassName:tuple_element
> InfoEnd
content, which in turn caused the generated
compilerplugins/clang/sharedvisitor/sharedvisitor.cxx to contain lots of
> #include "tuple_element.cxx"
and other nonsense, which caused the build to break with
> [CXX] compilerplugins/clang/sharedvisitor/sharedvisitor.cxx
> lo/core/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx:20:10: fatal error: 'tuple_element.cxx' file not found
> 20 | #include "tuple_element.cxx"
> | ^~~~~~~~~~~~~~~~~~~
etc.
(And now spelling out the implementation of forAnyBase here also reveals that
BaseCheckSubclass will never be called with a null BaseDefinition, so the code
handling that has been removed.)
Change-Id: I8a6e42260eae86852ec37a80d058777653fac394
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176042
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-11-05 08:37:12 +01:00
|
|
|
static bool BaseCheckSubclass(const clang::CXXRecordDecl *BaseDefinition, void *p) {
|
|
|
|
assert(BaseDefinition != nullptr);
|
2019-03-06 14:39:13 +01:00
|
|
|
auto const & base = *static_cast<const DeclChecker *>(p);
|
|
|
|
if (base(BaseDefinition)) {
|
Fix implementation of loplugin::isDerivedFrom
...where clang::CXXRecordDecl::forallBases is documented as: "This routine
returns false if the class has non-computable base classes." So, presumably
since
<https://github.com/llvm/llvm-project/commit/bf099f4682bf088aaa49b2c72fb1ef3250213fbb>
"[llvm][ADT] Structured bindings for move-only types in `StringMap` (#114676)"
changed
> -template <std::size_t I, typename ValueTy>
> -struct tuple_element<I, llvm::StringMapEntry<ValueTy>>
> - : std::conditional<I == 0, llvm::StringRef, ValueTy> {};
> +template <std::size_t Index, typename ValueTy>
> +struct std::tuple_element<Index, llvm::StringMapEntry<ValueTy>>
> + : std::tuple_element<Index, std::pair<llvm::StringRef, ValueTy>> {};
in LLVM's llvm/include/llvm/ADT/StringMapEntry.h, our !forallBases check here
started to trivially always be true for that struct tuple_element
specialization, so the isDerivedFrom check in
CheckFileVisitor::VisitCXXRecordDecl in
compilerplugins/clang/sharedvisitor/analyzer.cxx started to erroneously be true
for that struct, so it started to generate
compilerplugins/clang/sharedvisitor/*.plugininfo files with bogus extra
> InfoVersion:1
> ClassName:tuple_element
> InfoEnd
content, which in turn caused the generated
compilerplugins/clang/sharedvisitor/sharedvisitor.cxx to contain lots of
> #include "tuple_element.cxx"
and other nonsense, which caused the build to break with
> [CXX] compilerplugins/clang/sharedvisitor/sharedvisitor.cxx
> lo/core/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx:20:10: fatal error: 'tuple_element.cxx' file not found
> 20 | #include "tuple_element.cxx"
> | ^~~~~~~~~~~~~~~~~~~
etc.
(And now spelling out the implementation of forAnyBase here also reveals that
BaseCheckSubclass will never be called with a null BaseDefinition, so the code
handling that has been removed.)
Change-Id: I8a6e42260eae86852ec37a80d058777653fac394
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176042
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-11-05 08:37:12 +01:00
|
|
|
return true;
|
2019-03-06 14:39:13 +01:00
|
|
|
}
|
Fix implementation of loplugin::isDerivedFrom
...where clang::CXXRecordDecl::forallBases is documented as: "This routine
returns false if the class has non-computable base classes." So, presumably
since
<https://github.com/llvm/llvm-project/commit/bf099f4682bf088aaa49b2c72fb1ef3250213fbb>
"[llvm][ADT] Structured bindings for move-only types in `StringMap` (#114676)"
changed
> -template <std::size_t I, typename ValueTy>
> -struct tuple_element<I, llvm::StringMapEntry<ValueTy>>
> - : std::conditional<I == 0, llvm::StringRef, ValueTy> {};
> +template <std::size_t Index, typename ValueTy>
> +struct std::tuple_element<Index, llvm::StringMapEntry<ValueTy>>
> + : std::tuple_element<Index, std::pair<llvm::StringRef, ValueTy>> {};
in LLVM's llvm/include/llvm/ADT/StringMapEntry.h, our !forallBases check here
started to trivially always be true for that struct tuple_element
specialization, so the isDerivedFrom check in
CheckFileVisitor::VisitCXXRecordDecl in
compilerplugins/clang/sharedvisitor/analyzer.cxx started to erroneously be true
for that struct, so it started to generate
compilerplugins/clang/sharedvisitor/*.plugininfo files with bogus extra
> InfoVersion:1
> ClassName:tuple_element
> InfoEnd
content, which in turn caused the generated
compilerplugins/clang/sharedvisitor/sharedvisitor.cxx to contain lots of
> #include "tuple_element.cxx"
and other nonsense, which caused the build to break with
> [CXX] compilerplugins/clang/sharedvisitor/sharedvisitor.cxx
> lo/core/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx:20:10: fatal error: 'tuple_element.cxx' file not found
> 20 | #include "tuple_element.cxx"
> | ^~~~~~~~~~~~~~~~~~~
etc.
(And now spelling out the implementation of forAnyBase here also reveals that
BaseCheckSubclass will never be called with a null BaseDefinition, so the code
handling that has been removed.)
Change-Id: I8a6e42260eae86852ec37a80d058777653fac394
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176042
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-11-05 08:37:12 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool forAnyBase(
|
|
|
|
clang::CXXRecordDecl const * decl, clang::CXXRecordDecl::ForallBasesCallback matches)
|
|
|
|
{
|
|
|
|
// Based on the implementation of clang::CXXRecordDecl::forallBases in LLVM's
|
|
|
|
// clang/lib/AST/CXXInheritance.cpp:
|
|
|
|
for (auto const & i: decl->bases()) {
|
|
|
|
auto const t = i.getType()->getAs<clang::RecordType>();
|
|
|
|
if (t == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto const b = llvm::cast_or_null<clang::CXXRecordDecl>(t->getDecl()->getDefinition());
|
|
|
|
if (b == nullptr || (b->isDependentContext() && !b->isCurrentInstantiation(decl))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (matches(b) || forAnyBase(b, matches)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2019-03-06 14:39:13 +01:00
|
|
|
}
|
|
|
|
|
2023-01-20 15:21:15 +01:00
|
|
|
bool isDerivedFrom(const clang::CXXRecordDecl *decl, DeclChecker base, bool checkSelf) {
|
2019-03-06 14:39:13 +01:00
|
|
|
if (!decl)
|
|
|
|
return false;
|
2023-01-20 15:21:15 +01:00
|
|
|
if (checkSelf && base(decl))
|
2019-03-06 14:39:13 +01:00
|
|
|
return true;
|
|
|
|
if (!decl->hasDefinition()) {
|
|
|
|
return false;
|
|
|
|
}
|
Fix implementation of loplugin::isDerivedFrom
...where clang::CXXRecordDecl::forallBases is documented as: "This routine
returns false if the class has non-computable base classes." So, presumably
since
<https://github.com/llvm/llvm-project/commit/bf099f4682bf088aaa49b2c72fb1ef3250213fbb>
"[llvm][ADT] Structured bindings for move-only types in `StringMap` (#114676)"
changed
> -template <std::size_t I, typename ValueTy>
> -struct tuple_element<I, llvm::StringMapEntry<ValueTy>>
> - : std::conditional<I == 0, llvm::StringRef, ValueTy> {};
> +template <std::size_t Index, typename ValueTy>
> +struct std::tuple_element<Index, llvm::StringMapEntry<ValueTy>>
> + : std::tuple_element<Index, std::pair<llvm::StringRef, ValueTy>> {};
in LLVM's llvm/include/llvm/ADT/StringMapEntry.h, our !forallBases check here
started to trivially always be true for that struct tuple_element
specialization, so the isDerivedFrom check in
CheckFileVisitor::VisitCXXRecordDecl in
compilerplugins/clang/sharedvisitor/analyzer.cxx started to erroneously be true
for that struct, so it started to generate
compilerplugins/clang/sharedvisitor/*.plugininfo files with bogus extra
> InfoVersion:1
> ClassName:tuple_element
> InfoEnd
content, which in turn caused the generated
compilerplugins/clang/sharedvisitor/sharedvisitor.cxx to contain lots of
> #include "tuple_element.cxx"
and other nonsense, which caused the build to break with
> [CXX] compilerplugins/clang/sharedvisitor/sharedvisitor.cxx
> lo/core/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx:20:10: fatal error: 'tuple_element.cxx' file not found
> 20 | #include "tuple_element.cxx"
> | ^~~~~~~~~~~~~~~~~~~
etc.
(And now spelling out the implementation of forAnyBase here also reveals that
BaseCheckSubclass will never be called with a null BaseDefinition, so the code
handling that has been removed.)
Change-Id: I8a6e42260eae86852ec37a80d058777653fac394
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176042
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-11-05 08:37:12 +01:00
|
|
|
if (forAnyBase(decl,
|
2019-03-06 14:39:13 +01:00
|
|
|
[&base](const clang::CXXRecordDecl *BaseDefinition) -> bool
|
Fix implementation of loplugin::isDerivedFrom
...where clang::CXXRecordDecl::forallBases is documented as: "This routine
returns false if the class has non-computable base classes." So, presumably
since
<https://github.com/llvm/llvm-project/commit/bf099f4682bf088aaa49b2c72fb1ef3250213fbb>
"[llvm][ADT] Structured bindings for move-only types in `StringMap` (#114676)"
changed
> -template <std::size_t I, typename ValueTy>
> -struct tuple_element<I, llvm::StringMapEntry<ValueTy>>
> - : std::conditional<I == 0, llvm::StringRef, ValueTy> {};
> +template <std::size_t Index, typename ValueTy>
> +struct std::tuple_element<Index, llvm::StringMapEntry<ValueTy>>
> + : std::tuple_element<Index, std::pair<llvm::StringRef, ValueTy>> {};
in LLVM's llvm/include/llvm/ADT/StringMapEntry.h, our !forallBases check here
started to trivially always be true for that struct tuple_element
specialization, so the isDerivedFrom check in
CheckFileVisitor::VisitCXXRecordDecl in
compilerplugins/clang/sharedvisitor/analyzer.cxx started to erroneously be true
for that struct, so it started to generate
compilerplugins/clang/sharedvisitor/*.plugininfo files with bogus extra
> InfoVersion:1
> ClassName:tuple_element
> InfoEnd
content, which in turn caused the generated
compilerplugins/clang/sharedvisitor/sharedvisitor.cxx to contain lots of
> #include "tuple_element.cxx"
and other nonsense, which caused the build to break with
> [CXX] compilerplugins/clang/sharedvisitor/sharedvisitor.cxx
> lo/core/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx:20:10: fatal error: 'tuple_element.cxx' file not found
> 20 | #include "tuple_element.cxx"
> | ^~~~~~~~~~~~~~~~~~~
etc.
(And now spelling out the implementation of forAnyBase here also reveals that
BaseCheckSubclass will never be called with a null BaseDefinition, so the code
handling that has been removed.)
Change-Id: I8a6e42260eae86852ec37a80d058777653fac394
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176042
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-11-05 08:37:12 +01:00
|
|
|
{ return BaseCheckSubclass(BaseDefinition, &base); }))
|
2019-03-06 14:39:13 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|