[clang] [alpha.webkit.RetainPtrCtorAdoptChecker] Don't treat assignment to an +1 out argument as a leak (PR #161633)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 18 04:00:06 PST 2025
================
@@ -355,14 +355,30 @@ class RetainPtrCtorAdoptChecker
void visitBinaryOperator(const BinaryOperator *BO) const {
if (!BO->isAssignmentOp())
return;
- if (!isa<ObjCIvarRefExpr>(BO->getLHS()))
- return;
+ auto *LHS = BO->getLHS();
auto *RHS = BO->getRHS()->IgnoreParenCasts();
- const Expr *Inner = nullptr;
- if (isAllocInit(RHS, &Inner)) {
- CreateOrCopyFnCall.insert(RHS);
- if (Inner)
- CreateOrCopyFnCall.insert(Inner);
+ if (isa<ObjCIvarRefExpr>(LHS)) {
+ const Expr *Inner = nullptr;
+ if (isAllocInit(RHS, &Inner)) {
+ CreateOrCopyFnCall.insert(RHS);
+ if (Inner)
+ CreateOrCopyFnCall.insert(Inner);
+ }
+ return;
+ } else if (auto *UO = dyn_cast<UnaryOperator>(LHS)) {
----------------
steakhal wrote:
In LLVM I think we try to obey the rule of no [else-after-return](https://clang.llvm.org/extra/clang-tidy/checks/readability/else-after-return.html) rule.
Honouring the rule usually means that we can reduce indentation of the guarded block by one level.
https://github.com/llvm/llvm-project/pull/161633
More information about the cfe-commits
mailing list