-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[alpha.webkit.UncountedCallArgsChecker] Treat an explicit construction of Ref from a Ref return value safe. #130911
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
[alpha.webkit.UncountedCallArgsChecker] Treat an explicit construction of Ref from a Ref return value safe. #130911
Conversation
…n of Ref from a Ref return value safe. Fix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) ChangesFix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant. Full diff: https://github.com/llvm/llvm-project/pull/130911.diff 2 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 5e67cb29d08e4..1d9e8a468e899 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -70,6 +70,8 @@ bool tryToFindPtrOrigin(
if (isCtorOfSafePtr(ConversionFunc))
return callback(E, true);
}
+ if (isa<CXXFunctionalCastExpr>(E) && isSafePtrType(cast->getType()))
+ return callback(E, true);
}
// FIXME: This can give false "origin" that would lead to false negatives
// in checkers. See https://reviews.llvm.org/D37023 for reference.
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index e7afd9798da3e..0d53df6a2052f 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -407,6 +407,13 @@ namespace call_with_explicit_temporary_obj {
void baz() {
bar<int>();
}
+
+ class Foo {
+ Ref<RefCountable> ensure();
+ void foo() {
+ Ref { ensure() }->method();
+ }
+ };
}
namespace call_with_explicit_construct {
|
@@ -70,6 +70,8 @@ bool tryToFindPtrOrigin( | |||
if (isCtorOfSafePtr(ConversionFunc)) | |||
return callback(E, true); | |||
} | |||
if (isa<CXXFunctionalCastExpr>(E) && isSafePtrType(cast->getType())) | |||
return callback(E, true); |
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.
Is this case already handled for parameters and locals? Like are there instances of a constructing a Ref from another Ref parameter?
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.
We typically don't pass arguments as RefPtr / Ref except a few cases where we pass in as RefPtr&& / Ref&&. I guess we can add a test for it though.
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.
Added
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!
…n of Ref from a Ref return value safe. (llvm#130911) Fix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant.
…n of Ref from a Ref return value safe. (llvm#130911) Fix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant.
…n of Ref from a Ref return value safe. (llvm#130911) Fix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant.
Fix a bug that an explicit construction of Ref out of a Ref return value would not be treated as safe. It is definitely safe albit redundant.