-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
UncountedLocalVarsChecker and UncheckedLocalVarsChecker should recognize signletons. #119339
Conversation
…ize signletons. It's safe to have a raw pointer or a raw reference to a singleton object. Explicitly allow this in UncountedLocalVarsChecker and UncheckedLocalVarsChecker.
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesIt's safe to have a raw pointer or a raw reference to a singleton object. Explicitly allow this in UncountedLocalVarsChecker and UncheckedLocalVarsChecker. Full diff: https://github.com/llvm/llvm-project/pull/119339.diff 2 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/12017 Here is the relevant piece of the build log for the reference
|
…ize signletons. (llvm#119339) It's safe to have a raw pointer or a raw reference to a singleton object. Explicitly allow this in UncountedLocalVarsChecker and UncheckedLocalVarsChecker.
…ize signletons. (llvm#119339) It's safe to have a raw pointer or a raw reference to a singleton object. Explicitly allow this in UncountedLocalVarsChecker and UncheckedLocalVarsChecker.
It's safe to have a raw pointer or a raw reference to a singleton object. Explicitly allow this in UncountedLocalVarsChecker and UncheckedLocalVarsChecker.