Skip to content

[WebKit Checkers] Allow "singleton" suffix to be camelCased. #108257

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 1 commit into from
Sep 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,9 @@ bool isSingleton(const FunctionDecl *F) {
if (!MethodDecl->isStatic())
return false;
}
const auto &Name = safeGetName(F);
std::string SingletonStr = "singleton";
auto index = Name.find(SingletonStr);
return index != std::string::npos &&
index == Name.size() - SingletonStr.size();
const auto &NameStr = safeGetName(F);
StringRef Name = NameStr; // FIXME: Make safeGetName return StringRef.
return Name == "singleton" || Name.ends_with("Singleton");
}

// We only care about statements so let's use the simple
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ class RefCounted {
return s_RefCounted;
}

static RefCounted& otherSingleton() {
static RefCounted s_RefCounted;
s_RefCounted.ref();
return s_RefCounted;
}

Number nonTrivial1() { return Number(3) + Number(4); }
Number nonTrivial2() { return Number { 0.3 }; }
int nonTrivial3() { return v ? otherFunction() : 0; }
Expand Down Expand Up @@ -509,6 +515,8 @@ class UnrelatedClass {

RefCounted::singleton().trivial18(); // no-warning
RefCounted::singleton().someFunction(); // no-warning
RefCounted::otherSingleton().trivial18(); // no-warning
RefCounted::otherSingleton().someFunction(); // no-warning

getFieldTrivial().recursiveTrivialFunction(7); // no-warning
getFieldTrivial().recursiveComplexFunction(9);
Expand Down
Loading