Skip to content

[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

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,19 @@ 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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.


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;
}

struct NonTrivial {
NonTrivial();
NonTrivial(const NonTrivial&);
bool operator==(const NonTrivial& other) const { return value == other.value; }
float value;
};

class Component {
public:
void ref() const;
void deref() const;

Obj<float, 4> unresolvedComponents() const { return m_components; }
Obj<NonTrivial, 4> unresolvedNonTrivialComponents() const { return m_nonTrivialComponents; }

bool isEqual(const Component& other) const {
return unresolvedComponents() == other.unresolvedComponents();
}

bool isNonTrivialEqual(const Component& other) const {
return unresolvedNonTrivialComponents() == other.unresolvedNonTrivialComponents();
}

private:
Obj<float, 4> m_components;
Obj<NonTrivial, 4> m_nonTrivialComponents;
};

Component* provide();
bool someFunction(Component* other) {
return provide()->isEqual(*other);
}

bool otherFunction(Component* other) {
return provide()->isNonTrivialEqual(*other);
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
}