Skip to content

Commit 882f21e

Browse files
authored
[WebKit Checkers] Allow "singleton" suffix to be camelCased. (#108257)
We should allow singleton and fooSingleton as singleton function names.
1 parent 118f120 commit 882f21e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,9 @@ bool isSingleton(const FunctionDecl *F) {
231231
if (!MethodDecl->isStatic())
232232
return false;
233233
}
234-
const auto &Name = safeGetName(F);
235-
std::string SingletonStr = "singleton";
236-
auto index = Name.find(SingletonStr);
237-
return index != std::string::npos &&
238-
index == Name.size() - SingletonStr.size();
234+
const auto &NameStr = safeGetName(F);
235+
StringRef Name = NameStr; // FIXME: Make safeGetName return StringRef.
236+
return Name == "singleton" || Name.ends_with("Singleton");
239237
}
240238

241239
// We only care about statements so let's use the simple

clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ class RefCounted {
343343
return s_RefCounted;
344344
}
345345

346+
static RefCounted& otherSingleton() {
347+
static RefCounted s_RefCounted;
348+
s_RefCounted.ref();
349+
return s_RefCounted;
350+
}
351+
346352
Number nonTrivial1() { return Number(3) + Number(4); }
347353
Number nonTrivial2() { return Number { 0.3 }; }
348354
int nonTrivial3() { return v ? otherFunction() : 0; }
@@ -512,6 +518,8 @@ class UnrelatedClass {
512518

513519
RefCounted::singleton().trivial18(); // no-warning
514520
RefCounted::singleton().someFunction(); // no-warning
521+
RefCounted::otherSingleton().trivial18(); // no-warning
522+
RefCounted::otherSingleton().someFunction(); // no-warning
515523

516524
getFieldTrivial().recursiveTrivialFunction(7); // no-warning
517525
getFieldTrivial().recursiveComplexFunction(9);

0 commit comments

Comments
 (0)