[clang] [alpha.webkit.UncountedCallArgsChecker] Treat (foo())->bar() like foo()->bar(). (PR #91052)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Sat May 4 17:40:28 PDT 2024


https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91052

>From 357b8bfa0cef2632930e3f037ed66360b0fa3615 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Sat, 4 May 2024 00:38:08 -0700
Subject: [PATCH 1/2] [alpha.webkit.UncountedCallArgsChecker] Treat
 (foo())->bar() like foo()->bar().

---
 clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp |  4 ++++
 clang/test/Analysis/Checkers/WebKit/call-args.cpp     | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index b36fa95bc73f3e..4b14cdbf10a3da 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -27,6 +27,10 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) {
       E = tempExpr->getSubExpr();
       continue;
     }
+    if (auto* tempExpr = dyn_cast<ParenExpr>(E)) {
+      E = tempExpr->getSubExpr();
+      continue;
+    }
     if (auto *cast = dyn_cast<CastExpr>(E)) {
       if (StopAtFirstRefCountedObj) {
         if (auto *ConversionFunc =
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index 2a4b6bb1f1063a..45d900d4ba880e 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -313,6 +313,17 @@ namespace default_arg {
   }
 }
 
+namespace cxx_member_func {
+  Ref<RefCountable> provideProtected();
+  void foo() {
+    provide()->trivial();
+    provide()->method();
+    // expected-warning at -1{{Call argument for 'this' parameter is uncounted and unsafe}}
+    provideProtected()->method();
+    (provideProtected())->method();
+  };
+}
+
 namespace cxx_member_operator_call {
   // The hidden this-pointer argument without a corresponding parameter caused couple bugs in parameter <-> argument attribution.
   struct Foo {

>From 1b006c4b2642c630d20135d96c1d85c45848f142 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Sat, 4 May 2024 17:40:03 -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 4b14cdbf10a3da..5c49eecacc0f27 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -27,7 +27,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) {
       E = tempExpr->getSubExpr();
       continue;
     }
-    if (auto* tempExpr = dyn_cast<ParenExpr>(E)) {
+    if (auto *tempExpr = dyn_cast<ParenExpr>(E)) {
       E = tempExpr->getSubExpr();
       continue;
     }



More information about the cfe-commits mailing list