[clang] [alpha.webkit.UncountedCallArgsChecker] Allow ArrayInitLoopExpr and OpaqueValueExpr in trivial expressions (PR #127182)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 14 10:09:46 PST 2025


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

>From 2be47498ca7597748ee8b29f5d39d74608c2f4d3 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Fri, 14 Feb 2025 00:48:36 -0800
Subject: [PATCH 1/2] [alpha.webkit.UncountedCallArgsChecker] Allow
 ArrayInitLoopExpr and OpaqueValueExpr in trivial expressions

Allow VisitArrayInitLoopExpr, VisitArrayInitIndexExpr, and VisitOpaqueValueExpr in trivial functions and statements.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp     | 12 +++++
 .../call-args-loop-init-opaque-value.cpp      | 47 +++++++++++++++++++
 2 files changed, 59 insertions(+)
 create mode 100644 clang/test/Analysis/Checkers/WebKit/call-args-loop-init-opaque-value.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d40b4b4dbb560..edfe72c62b2c8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -589,6 +589,18 @@ class TrivialFunctionAnalysisVisitor
     return Visit(BTE->getSubExpr());
   }
 
+  bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *AILE) {
+    return Visit(AILE->getCommonExpr()) && Visit(AILE->getSubExpr());
+  }
+
+  bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *AIIE) {
+    return true; // The current array index in VisitArrayInitLoopExpr is always trivial.
+  }
+
+  bool VisitOpaqueValueExpr(const OpaqueValueExpr *OVE) {
+    return Visit(OVE->getSourceExpr());
+  }
+
   bool VisitExprWithCleanups(const ExprWithCleanups *EWC) {
     return Visit(EWC->getSubExpr());
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-loop-init-opaque-value.cpp b/clang/test/Analysis/Checkers/WebKit/call-args-loop-init-opaque-value.cpp
new file mode 100644
index 0000000000000..69987c600eeb5
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-loop-init-opaque-value.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+typedef unsigned long size_t;
+template<typename T, size_t N>
+struct Obj {
+    constexpr static size_t Size = N;
+
+    constexpr T& operator[](size_t i) { return components[i]; }
+    constexpr const T& operator[](size_t i) const { return components[i]; }
+
+    constexpr size_t size() const { return Size; }
+
+    T components[N];
+};
+
+template<typename T, size_t N>
+constexpr bool operator==(const Obj<T, N>& a, const Obj<T, N>& b)
+{
+    for (size_t i = 0; i < N; ++i) {
+        if (a[i] == b[i])
+            continue;
+        return false;
+    }
+
+    return true;
+}
+
+class Component {
+public:
+    void ref() const;
+    void deref() const;
+
+    Obj<float, 4> unresolvedComponents() const { return m_components; }
+
+    bool isEqual(const Component& other) const {
+        return unresolvedComponents() == other.unresolvedComponents();
+    }
+
+private:
+    Obj<float, 4> m_components;
+};
+
+Component* provide();
+bool someFunction(Component* other) {
+    return provide()->isEqual(*other);
+}

>From e49246b2c9e73a2b7cdd128f7c9afc02c433a01b Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Fri, 14 Feb 2025 10:09:30 -0800
Subject: [PATCH 2/2] Fix formatting

---
 clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index edfe72c62b2c8..0f0aaa0e1902b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -594,7 +594,8 @@ class TrivialFunctionAnalysisVisitor
   }
 
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *AIIE) {
-    return true; // The current array index in VisitArrayInitLoopExpr is always trivial.
+    return true; // The current array index in VisitArrayInitLoopExpr is always
+                 // trivial.
   }
 
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *OVE) {



More information about the cfe-commits mailing list