diff options
author | Ryosuke Niwa <rniwa@webkit.org> | 2025-05-09 17:44:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-09 17:44:36 -0700 |
commit | 436504c3b9db3bd11d34ec7457b52bef43fc35cc (patch) | |
tree | ede89b4fb566448105c9cfd852433188c7950f8b /clang/lib/StaticAnalyzer/Checkers | |
parent | 984475d82df8d75095c987c909073cec83d5375e (diff) | |
download | llvm-436504c3b9db3bd11d34ec7457b52bef43fc35cc.zip llvm-436504c3b9db3bd11d34ec7457b52bef43fc35cc.tar.gz llvm-436504c3b9db3bd11d34ec7457b52bef43fc35cc.tar.bz2 |
[webkit.UncountedLambdaCapturesChecker] Treat every argument of std::ranges functions as noescape. (#138995)
Functions in std::ranges namespace does not store the lambada passed-in
as an arugment in heap so treat such an argument as if it has
[[noescape]] in the WebKit lambda capture checker so that we don't emit
warnings for capturing raw pointers or references to smart-pointer
capable objects.
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp index 01faa92..c322f37 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLambdaCapturesChecker.cpp @@ -127,13 +127,22 @@ public: return true; } - // WTF::switchOn(T, F... f) is a variadic template function and couldn't - // be annotated with NOESCAPE. We hard code it here to workaround that. bool shouldTreatAllArgAsNoEscape(FunctionDecl *Decl) { auto *NsDecl = Decl->getParent(); if (!NsDecl || !isa<NamespaceDecl>(NsDecl)) return false; - return safeGetName(NsDecl) == "WTF" && safeGetName(Decl) == "switchOn"; + // WTF::switchOn(T, F... f) is a variadic template function and couldn't + // be annotated with NOESCAPE. We hard code it here to workaround that. + if (safeGetName(NsDecl) == "WTF" && safeGetName(Decl) == "switchOn") + return true; + // Treat every argument of functions in std::ranges as noescape. + if (safeGetName(NsDecl) == "ranges") { + if (auto *OuterDecl = NsDecl->getParent(); + OuterDecl && isa<NamespaceDecl>(OuterDecl) && + safeGetName(OuterDecl) == "std") + return true; + } + return false; } bool VisitCXXConstructExpr(CXXConstructExpr *CE) override { |