-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. #130258
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
Conversation
…uctExpr as a safe origin. Handle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that constructing Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in such a way that its type is unresolved at AST level will be still treated as a safe pointer origin. Also fix a bug in isPtrOfType that it was not recognizing DeducedTemplateSpecializationType.
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) ChangesHandle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that constructing Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in such a way that its type is unresolved at AST level will be still treated as a safe pointer origin. Also fix a bug in isPtrOfType that it was not recognizing DeducedTemplateSpecializationType. Full diff: https://github.com/llvm/llvm-project/pull/130258.diff 3 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index dc86c4fcc64b1..885203550b8a8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -43,6 +43,10 @@ bool tryToFindPtrOrigin(
break;
}
}
+ if (auto *TempExpr = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
+ if (isSafePtrType(TempExpr->getTypeAsWritten()))
+ return callback(TempExpr, true);
+ }
if (auto *POE = dyn_cast<PseudoObjectExpr>(E)) {
if (auto *RF = POE->getResultExpr()) {
E = RF;
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..8a304a07296fc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -162,13 +162,14 @@ static bool isPtrOfType(const clang::QualType T, Predicate Pred) {
type = elaboratedT->desugar();
continue;
}
- auto *SpecialT = type->getAs<TemplateSpecializationType>();
- if (!SpecialT)
- return false;
- auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
- if (!Decl)
- return false;
- return Pred(Decl->getNameAsString());
+ if (auto *SpecialT = type->getAs<TemplateSpecializationType>()) {
+ auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
+ return Decl && Pred(Decl->getNameAsString());
+ } else if (auto *DTS = type->getAs<DeducedTemplateSpecializationType>()) {
+ auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
+ return Decl && Pred(Decl->getNameAsString());
+ } else
+ break;
}
return false;
}
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index b4613d5090f29..e7afd9798da3e 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -359,6 +359,41 @@ namespace call_with_ptr_on_ref {
}
}
+namespace call_with_explicit_construct_from_auto {
+
+ struct Impl {
+ void ref() const;
+ void deref() const;
+
+ static Ref<Impl> create();
+ };
+
+ template <typename T>
+ struct ArgObj {
+ T* t;
+ };
+
+ struct Object {
+ Object();
+ Object(Ref<Impl>&&);
+
+ Impl* impl() const { return m_impl.get(); }
+
+ static Object create(ArgObj<char>&) { return Impl::create(); }
+ static void bar(Impl&);
+
+ private:
+ RefPtr<Impl> m_impl;
+ };
+
+ template<typename CharacterType> void foo()
+ {
+ auto result = Object::create(ArgObj<CharacterType> { });
+ Object::bar(Ref { *result.impl() });
+ }
+
+}
+
namespace call_with_explicit_temporary_obj {
void foo() {
Ref { *provide() }->method();
|
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!
Thanks for the review! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/14201 Here is the relevant piece of the build log for the reference
|
…uctExpr as a safe origin. (llvm#130258) Handle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that constructing Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in such a way that its type is unresolved at AST level will be still treated as a safe pointer origin. Also fix a bug in isPtrOfType that it was not recognizing DeducedTemplateSpecializationType.
…uctExpr as a safe origin. (llvm#130258) Handle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that constructing Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in such a way that its type is unresolved at AST level will be still treated as a safe pointer origin. Also fix a bug in isPtrOfType that it was not recognizing DeducedTemplateSpecializationType.
Handle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that constructing Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in such a way that its type is unresolved at AST level will be still treated as a safe pointer origin.
Also fix a bug in isPtrOfType that it was not recognizing DeducedTemplateSpecializationType.