Skip to content

Commit 377d1f0

Browse files
authoredDec 10, 2024··
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.
1 parent 4027e2f commit 377d1f0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class RawPtrRefLocalVarsChecker
263263
if (tryToFindPtrOrigin(
264264
Value, /*StopAtFirstRefCountedObj=*/false,
265265
[&](const clang::Expr *InitArgOrigin, bool IsSafe) {
266-
if (!InitArgOrigin)
266+
if (!InitArgOrigin || IsSafe)
267267
return true;
268268

269269
if (isa<CXXThisExpr>(InitArgOrigin))

‎clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,12 @@ int TreeNode::recursiveWeight() {
456456
}
457457

458458
} // namespace local_var_in_recursive_function
459+
460+
namespace local_var_for_singleton {
461+
RefCountable *singleton();
462+
RefCountable *otherSingleton();
463+
void foo() {
464+
RefCountable* bar = singleton();
465+
RefCountable* baz = otherSingleton();
466+
}
467+
}

0 commit comments

Comments
 (0)
Please sign in to comment.