diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-09 15:22:23 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-10 08:07:03 +0200 |
commit | 4c909d1466bf940f653984b61772cf19c320439d (patch) | |
tree | c29129af77615725b3cee5cf5e18796821b426e6 /compilerplugins | |
parent | 91d77d65190e7cf11dd7cd0b29d5de6b66061faf (diff) |
loplugin:passstuffbyref
Change-Id: Ib2b2650da7abc9260897f9b5aad619a0ea6ae941
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138052
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/passstuffbyref.cxx | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/compilerplugins/clang/passstuffbyref.cxx b/compilerplugins/clang/passstuffbyref.cxx index d6ab91fc82a1..549987e43b53 100644 --- a/compilerplugins/clang/passstuffbyref.cxx +++ b/compilerplugins/clang/passstuffbyref.cxx @@ -280,7 +280,9 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C if (dc.Function("convertItems").Class("ValueParser").Namespace("configmgr").GlobalNamespace() || dc.Function("parseListValue").AnonymousNamespace().Namespace("configmgr").GlobalNamespace() || dc.Function("parseSingleValue").AnonymousNamespace().Namespace("configmgr").GlobalNamespace() - || dc.Function("Create").Class("HandlerComponentBase").Namespace("pcr").GlobalNamespace()) { + || dc.Function("Create").Class("HandlerComponentBase").Namespace("pcr").GlobalNamespace() + || dc.Function("toAny").Struct("Convert").Namespace("detail").Namespace("comphelper").GlobalNamespace() + || dc.Function("makeAny").Namespace("utl").GlobalNamespace()) { return; } if (startswith(type.getAsString(), "struct o3tl::strong_int")) { @@ -299,6 +301,9 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C if (tc.Struct("TranslateId")) { return; } + if (tc.Class("span").Namespace("o3tl")) { + return; + } // functionDecl->dump(); @@ -332,7 +337,7 @@ bool PassStuffByRef::VisitReturnStmt(const ReturnStmt * returnStmt) { if (!mbInsideFunctionDecl) return true; - const Expr* expr = dyn_cast<Expr>(*returnStmt->child_begin())->IgnoreParenCasts(); + const Expr* expr = dyn_cast<Expr>(*returnStmt->child_begin())->IgnoreParenImpCasts(); if (isReturnExprDisqualified(expr)) mbFoundReturnValueDisqualifier = true; @@ -348,6 +353,7 @@ bool PassStuffByRef::isReturnExprDisqualified(const Expr* expr) while (true) { expr = expr->IgnoreParens(); +// expr->dump(); if (auto implicitCast = dyn_cast<ImplicitCastExpr>(expr)) { expr = implicitCast->getSubExpr(); continue; @@ -427,6 +433,9 @@ bool PassStuffByRef::isReturnExprDisqualified(const Expr* expr) return true; // otherwise fall through to the checking below } + if (Opc == OO_Arrow) + if (isReturnExprDisqualified(operatorCallExpr->getArg(0))) + return true; } if (auto memberCallExpr = dyn_cast<CXXMemberCallExpr>(expr)) { if (isReturnExprDisqualified(memberCallExpr->getImplicitObjectArgument())) @@ -455,21 +464,19 @@ bool PassStuffByRef::isReturnExprDisqualified(const Expr* expr) bool PassStuffByRef::VisitVarDecl(const VarDecl * varDecl) { - if (!mbInsideFunctionDecl) + if (!mbInsideFunctionDecl || mbFoundReturnValueDisqualifier) return true; // things guarded by locking are probably best left alone loplugin::TypeCheck dc(varDecl->getType()); - if (dc.Class("Guard").Namespace("osl").GlobalNamespace()) - mbFoundReturnValueDisqualifier = true; - if (dc.Class("ClearableGuard").Namespace("osl").GlobalNamespace()) - mbFoundReturnValueDisqualifier = true; - if (dc.Class("ResettableGuard").Namespace("osl").GlobalNamespace()) - mbFoundReturnValueDisqualifier = true; - else if (dc.Class("SolarMutexGuard").GlobalNamespace()) - mbFoundReturnValueDisqualifier = true; - else if (dc.Class("SfxModelGuard").GlobalNamespace()) - mbFoundReturnValueDisqualifier = true; - else if (dc.Class("ReadWriteGuard").Namespace("utl").GlobalNamespace()) + if (dc.Class("Guard").Namespace("osl").GlobalNamespace() || + dc.Class("ClearableGuard").Namespace("osl").GlobalNamespace() || + dc.Class("ResettableGuard").Namespace("osl").GlobalNamespace() || + dc.Class("SolarMutexGuard").GlobalNamespace() || + dc.Class("SfxModelGuard").GlobalNamespace() || + dc.Class("ReadWriteGuard").Namespace("utl").GlobalNamespace() || + dc.Class("unique_lock").StdNamespace() || + dc.Class("lock_guard").StdNamespace() || + dc.Class("scoped_lock").StdNamespace()) mbFoundReturnValueDisqualifier = true; return true; } |