[clang] [alpha.webkit.UncountedCallArgsChecker] Allow explicit instantiation of Ref/RefPtr on call arguments. (PR #91875)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Sat May 11 17:04:56 PDT 2024
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91875
>From d5a676c1cbe6d9804e6b2d3582df3c4977684188 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at apple.com>
Date: Sat, 11 May 2024 16:59:27 -0700
Subject: [PATCH 1/2] [alpha.webkit.UncountedCallArgsChecker] Allow explicit
instantiation of Ref/RefPtr on call arguments.
---
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp | 7 +++++++
clang/test/Analysis/Checkers/WebKit/call-args.cpp | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index f81db0e67d835..423c2d749bcfb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -28,6 +28,13 @@ bool tryToFindPtrOrigin(
E = tempExpr->getSubExpr();
continue;
}
+ if (auto *tempExpr = dyn_cast<CXXTemporaryObjectExpr>(E)) {
+ if (auto *C = tempExpr->getConstructor()) {
+ if (auto* Class = C->getParent(); Class && isRefCounted(Class))
+ return callback(E, true);
+ break;
+ }
+ }
if (auto *tempExpr = dyn_cast<ParenExpr>(E)) {
E = tempExpr->getSubExpr();
continue;
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index e1bee8a23a250..94efddeaf66cd 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -358,3 +358,10 @@ namespace call_with_ptr_on_ref {
// expected-warning at -1{{Call argument for parameter 'bad' is uncounted and unsafe}}
}
}
+
+namespace call_with_explicit_temporary_obj {
+ void foo() {
+ Ref { *provide() }->method();
+ RefPtr { provide() }->method();
+ }
+}
>From 9b72796910a694c8c88435c43459bebfd1709e52 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at apple.com>
Date: Sat, 11 May 2024 17:01:42 -0700
Subject: [PATCH 2/2] Fix formatting.
---
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 423c2d749bcfb..be07cf51eefb3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -30,7 +30,7 @@ bool tryToFindPtrOrigin(
}
if (auto *tempExpr = dyn_cast<CXXTemporaryObjectExpr>(E)) {
if (auto *C = tempExpr->getConstructor()) {
- if (auto* Class = C->getParent(); Class && isRefCounted(Class))
+ if (auto *Class = C->getParent(); Class && isRefCounted(Class))
return callback(E, true);
break;
}
More information about the cfe-commits
mailing list