-
Notifications
You must be signed in to change notification settings - Fork 14.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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
clang/test/Analysis/Checkers/WebKit/call-args-loop-init-opaque-value.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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}} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.