[all-commits] [llvm/llvm-project] 287781: [webkit.UncountedLambdaCapturesChecker] Ignore tri...

Ryosuke Niwa via All-commits all-commits at lists.llvm.org
Thu Oct 31 00:14:45 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 287781c7c9dbd7674cf7cbab8a8fe8a49a4b9317
      https://github.com/llvm/llvm-project/commit/287781c7c9dbd7674cf7cbab8a8fe8a49a4b9317
  Author: Ryosuke Niwa <rniwa at webkit.org>
  Date:   2024-10-31 (Thu, 31 Oct 2024)

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

  Log Message:
  -----------
  [webkit.UncountedLambdaCapturesChecker] Ignore trivial functions and [[clang::noescape]]. (#113845)

This PR makes webkit.UncountedLambdaCapturesChecker ignore trivial
functions as well as the one being passed to an argument with
[[clang::noescape]] attribute. This dramatically reduces the false
positive rate for this checker.

To do this, this PR replaces VisitLambdaExpr in favor of checking
lambdas via VisitDeclRefExpr and VisitCallExpr. The idea is that if a
lambda is defined but never called or stored somewhere, then capturing
whatever variable in such a lambda is harmless.

VisitCallExpr explicitly looks for direct invocation of lambdas and
registers its DeclRefExpr to be ignored in VisitDeclRefExpr. If a lambda
is being passed to a function, it checks whether its argument is
annotated with [[clang::noescape]]. If it's not annotated such, it
checks captures for their safety.

Because WTF::switchOn could not be annotated with [[clang::noescape]] as
function type parameters are variadic template function so we hard-code
this function into the checker.

Finally, this PR also converts the accompanying test to use -verify and
adds a bunch of tests.



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