[all-commits] [llvm/llvm-project] 77041d: [webkit.UncountedLambdaCapturesChecker] Recognize ...

Ryosuke Niwa via All-commits all-commits at lists.llvm.org
Fri Feb 14 16:33:55 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 77041da98932f77896d48366703d956ae7a82036
      https://github.com/llvm/llvm-project/commit/77041da98932f77896d48366703d956ae7a82036
  Author: Ryosuke Niwa <rniwa at webkit.org>
  Date:   2025-02-14 (Fri, 14 Feb 2025)

  Changed paths:
    M clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
    M clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp

  Log Message:
  -----------
  [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (#126443)

In WebKit, it's pretty common to capture "this" and "protectedThis"
where "protectedThis" is a guardian variable of type Ref or RefPtr for
"this". Furthermore, it's common for this "protectedThis" variable from
being passed to an inner lambda by std::move. Recognize this pattern so
that we don't emit warnings for nested inner lambdas.

To recognize this pattern, we introduce a new DenseSet,
ProtectedThisDecls, which contains every "protectedThis" we've
recognized to our subclass of DynamicRecursiveASTVisitor. This set is
now populated in "hasProtectedThis" and "declProtectsThis" uses this
DenseSet to determine a given value declaration constitutes a
"protectedThis" pattern or not.

Because hasProtectedThis and declProtectsThis had to be moved from the
checker class to the visitor class, it's now a responsibility of each
caller of visitLambdaExpr to check whether a given lambda captures
"this" without a "protectedThis" or not.

Finally, this PR improves the code to recognize "protectedThis" pattern
by allowing more nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and
UnaryOperator expressions.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list