Skip to content

Commit c419acd

Browse files
authored
[alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. (#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.
1 parent 993cbea commit c419acd

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ bool tryToFindPtrOrigin(
4343
break;
4444
}
4545
}
46+
if (auto *TempExpr = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
47+
if (isSafePtrType(TempExpr->getTypeAsWritten()))
48+
return callback(TempExpr, true);
49+
}
4650
if (auto *POE = dyn_cast<PseudoObjectExpr>(E)) {
4751
if (auto *RF = POE->getResultExpr()) {
4852
E = RF;

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ static bool isPtrOfType(const clang::QualType T, Predicate Pred) {
162162
type = elaboratedT->desugar();
163163
continue;
164164
}
165-
auto *SpecialT = type->getAs<TemplateSpecializationType>();
166-
if (!SpecialT)
167-
return false;
168-
auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
169-
if (!Decl)
170-
return false;
171-
return Pred(Decl->getNameAsString());
165+
if (auto *SpecialT = type->getAs<TemplateSpecializationType>()) {
166+
auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
167+
return Decl && Pred(Decl->getNameAsString());
168+
} else if (auto *DTS = type->getAs<DeducedTemplateSpecializationType>()) {
169+
auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
170+
return Decl && Pred(Decl->getNameAsString());
171+
} else
172+
break;
172173
}
173174
return false;
174175
}

clang/test/Analysis/Checkers/WebKit/call-args.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,41 @@ namespace call_with_ptr_on_ref {
359359
}
360360
}
361361

362+
namespace call_with_explicit_construct_from_auto {
363+
364+
struct Impl {
365+
void ref() const;
366+
void deref() const;
367+
368+
static Ref<Impl> create();
369+
};
370+
371+
template <typename T>
372+
struct ArgObj {
373+
T* t;
374+
};
375+
376+
struct Object {
377+
Object();
378+
Object(Ref<Impl>&&);
379+
380+
Impl* impl() const { return m_impl.get(); }
381+
382+
static Object create(ArgObj<char>&) { return Impl::create(); }
383+
static void bar(Impl&);
384+
385+
private:
386+
RefPtr<Impl> m_impl;
387+
};
388+
389+
template<typename CharacterType> void foo()
390+
{
391+
auto result = Object::create(ArgObj<CharacterType> { });
392+
Object::bar(Ref { *result.impl() });
393+
}
394+
395+
}
396+
362397
namespace call_with_explicit_temporary_obj {
363398
void foo() {
364399
Ref { *provide() }->method();

0 commit comments

Comments
 (0)