Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,47 @@
// 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.

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