diff options
| author | Ryosuke Niwa <rniwa@webkit.org> | 2024-09-11 12:03:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-11 12:03:23 -0700 |
| commit | 882f21ec87abd960b7ce3e10225f2bfeda3e1f74 (patch) | |
| tree | 0c600cf956cc3cb7d742ff5eafe46d4720241137 | |
| parent | 118f120eaab8d763b28c71f0d2e2c1e0c752832b (diff) | |
| download | llvm-882f21ec87abd960b7ce3e10225f2bfeda3e1f74.zip llvm-882f21ec87abd960b7ce3e10225f2bfeda3e1f74.tar.gz llvm-882f21ec87abd960b7ce3e10225f2bfeda3e1f74.tar.bz2 | |
[WebKit Checkers] Allow "singleton" suffix to be camelCased. (#108257)
We should allow singleton and fooSingleton as singleton function names.
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 8 | ||||
| -rw-r--r-- | clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp | 8 |
2 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 2b9b788..42efc0c4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -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 diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp index 424ebd3..97efb35 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp @@ -343,6 +343,12 @@ public: 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; } @@ -512,6 +518,8 @@ public: 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); |
