Skip to content

Commit

Permalink
Update clang static analyzers per rename of member functions in CanMa…
Browse files Browse the repository at this point in the history
…keCheckedPtr. (llvm#114636)

The member functions that define CheckedPtr capable type is
incrementCheckedPtrCount and decrementCheckedPtrCount after the rename.
  • Loading branch information
rniwa committed Nov 5, 2024
1 parent dc0b213 commit e82f75f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions clang/docs/analyzer/checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3029,8 +3029,8 @@ Raw pointers and references to an object which supports CheckedPtr or CheckedRef
.. code-block:: cpp
struct CheckableObj {
void incrementPtrCount() {}
void decrementPtrCount() {}
void incrementCheckedPtrCount() {}
void decrementCheckedPtrCount() {}
};
struct Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ std::optional<bool> isRefCountable(const clang::CXXRecordDecl *R) {
}

std::optional<bool> isCheckedPtrCapable(const clang::CXXRecordDecl *R) {
return isSmartPtrCompatible(R, "incrementPtrCount", "decrementPtrCount");
return isSmartPtrCompatible(R, "incrementCheckedPtrCount",
"decrementCheckedPtrCount");
}

bool isRefType(const std::string &Name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class UncountedCallArgsChecker
auto name = safeGetName(MD);
if (name == "ref" || name == "deref")
return;
if (name == "incrementPtrCount" || name == "decrementPtrCount")
if (name == "incrementCheckedPtrCount" ||
name == "decrementCheckedPtrCount")
return;
}
auto *E = MemberCallExpr->getImplicitObjectArgument();
Expand Down
18 changes: 9 additions & 9 deletions clang/test/Analysis/Checkers/WebKit/mock-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ template <typename T> struct CheckedRef {

public:
CheckedRef() : t{} {};
CheckedRef(T &t) : t(&t) { t.incrementPtrCount(); }
CheckedRef(const CheckedRef &o) : t(o.t) { if (t) t->incrementPtrCount(); }
~CheckedRef() { if (t) t->decrementPtrCount(); }
CheckedRef(T &t) : t(&t) { t.incrementCheckedPtrCount(); }
CheckedRef(const CheckedRef &o) : t(o.t) { if (t) t->incrementCheckedPtrCount(); }
~CheckedRef() { if (t) t->decrementCheckedPtrCount(); }
T &get() { return *t; }
T *ptr() { return t; }
T *operator->() { return t; }
Expand All @@ -165,14 +165,14 @@ template <typename T> struct CheckedPtr {
CheckedPtr(T *t)
: t(t) {
if (t)
t->incrementPtrCount();
t->incrementCheckedPtrCount();
}
CheckedPtr(Ref<T> &&o)
: t(o.leakRef())
{ }
~CheckedPtr() {
if (t)
t->decrementPtrCount();
t->decrementCheckedPtrCount();
}
T *get() { return t; }
T *operator->() { return t; }
Expand All @@ -184,16 +184,16 @@ template <typename T> struct CheckedPtr {

class CheckedObj {
public:
void incrementPtrCount();
void decrementPtrCount();
void incrementCheckedPtrCount();
void decrementCheckedPtrCount();
void method();
int trivial() { return 123; }
};

class RefCountableAndCheckable {
public:
void incrementPtrCount() const;
void decrementPtrCount() const;
void incrementCheckedPtrCount() const;
void decrementCheckedPtrCount() const;
void ref() const;
void deref() const;
void method();
Expand Down

0 comments on commit e82f75f

Please sign in to comment.