-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[alpha.webkit.UncountedCallArgsChecker] Allow ArrayInitLoopExpr and OpaqueValueExpr in trivial expressions #127182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…paqueValueExpr in trivial expressions Allow VisitArrayInitLoopExpr, VisitArrayInitIndexExpr, and VisitOpaqueValueExpr in trivial functions and statements.
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesAllow VisitArrayInitLoopExpr, VisitArrayInitIndexExpr, and VisitOpaqueValueExpr in trivial functions and statements. Full diff: https://github.com/llvm/llvm-project/pull/127182.diff 2 Files Affected:
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);
+}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a small nit about tests. Otherwise, LGTM.
@@ -0,0 +1,47 @@ | |||
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to test these expressions in non-trivial expressions? Or do such tests already exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have tests for non-trivial expressions: clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp. I guess we can add a test case here for non-trivial case as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a non-trivial test case.
Thanks for the review! |
…paqueValueExpr in trivial expressions (llvm#127182) Allow VisitArrayInitLoopExpr, VisitArrayInitIndexExpr, and VisitOpaqueValueExpr in trivial functions and statements.
…paqueValueExpr in trivial expressions (llvm#127182) Allow VisitArrayInitLoopExpr, VisitArrayInitIndexExpr, and VisitOpaqueValueExpr in trivial functions and statements.
Allow VisitArrayInitLoopExpr, VisitArrayInitIndexExpr, and VisitOpaqueValueExpr in trivial functions and statements.