Author: Ryosuke Niwa Date: 2024-12-10T15:57:58-08:00 New Revision: 377d1f0a6b862183b25701cc765fca7f84ea8e32
URL: https://github.com/llvm/llvm-project/commit/377d1f0a6b862183b25701cc765fca7f84ea8e32 DIFF: https://github.com/llvm/llvm-project/commit/377d1f0a6b862183b25701cc765fca7f84ea8e32.diff LOG: UncountedLocalVarsChecker and UncheckedLocalVarsChecker should recognize signletons. (#119339) It's safe to have a raw pointer or a raw reference to a singleton object. Explicitly allow this in UncountedLocalVarsChecker and UncheckedLocalVarsChecker. Added: Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp index e0433c5c2c1a09..bb580b06e2c53f 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp @@ -263,7 +263,7 @@ class RawPtrRefLocalVarsChecker if (tryToFindPtrOrigin( Value, /*StopAtFirstRefCountedObj=*/false, [&](const clang::Expr *InitArgOrigin, bool IsSafe) { - if (!InitArgOrigin) + if (!InitArgOrigin || IsSafe) return true; if (isa<CXXThisExpr>(InitArgOrigin)) diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp index d7fb689557a6fc..52854cd10f68c7 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp @@ -456,3 +456,12 @@ int TreeNode::recursiveWeight() { } } // namespace local_var_in_recursive_function + +namespace local_var_for_singleton { + RefCountable *singleton(); + RefCountable *otherSingleton(); + void foo() { + RefCountable* bar = singleton(); + RefCountable* baz = otherSingleton(); + } +} \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits