Skip to content

Commit f5d4535

Browse files
committedFeb 7, 2025
[alpha.webkit.UncountedCallArgsChecker] Use canonical type (llvm#109393)
This PR fixes a bug in UncountedCallArgsChecker that calling a function with a member variable which is Ref/RefPtr is erroneously treated as safe by canoniclizing the type before checking whether it's ref counted or not.
1 parent 69bbcce commit f5d4535

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ std::optional<bool> isUncounted(const QualType T) {
155155
std::optional<bool> isUncounted(const CXXRecordDecl* Class)
156156
{
157157
// Keep isRefCounted first as it's cheaper.
158-
if (isRefCounted(Class))
158+
if (!Class || isRefCounted(Class))
159159
return false;
160160

161161
std::optional<bool> IsRefCountable = isRefCountable(Class);

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class UncountedCallArgsChecker
8686
return;
8787
}
8888
auto *E = MemberCallExpr->getImplicitObjectArgument();
89-
QualType ArgType = MemberCallExpr->getObjectType();
89+
QualType ArgType = MemberCallExpr->getObjectType().getCanonicalType();
9090
std::optional<bool> IsUncounted = isUncounted(ArgType);
9191
if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
9292
reportBugOnThis(E);
@@ -102,12 +102,13 @@ class UncountedCallArgsChecker
102102
// if ((*P)->hasAttr<SafeRefCntblRawPtrAttr>())
103103
// continue;
104104

105-
const auto *ArgType = (*P)->getType().getTypePtrOrNull();
106-
if (!ArgType)
105+
QualType ArgType = (*P)->getType().getCanonicalType();
106+
const auto *TypePtr = ArgType.getTypePtrOrNull();
107+
if (!TypePtr)
107108
continue; // FIXME? Should we bail?
108109

109110
// FIXME: more complex types (arrays, references to raw pointers, etc)
110-
std::optional<bool> IsUncounted = isUncountedPtr(ArgType);
111+
std::optional<bool> IsUncounted = isUncountedPtr(TypePtr);
111112
if (!IsUncounted || !(*IsUncounted))
112113
continue;
113114

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
3+
#include "mock-types.h"
4+
5+
class Object {
6+
public:
7+
void ref() const;
8+
void deref() const;
9+
10+
bool constFunc() const;
11+
void mutableFunc();
12+
};
13+
14+
class Caller {
15+
void someFunction();
16+
void otherFunction();
17+
private:
18+
RefPtr<Object> m_obj;
19+
};
20+
21+
void Caller::someFunction()
22+
{
23+
m_obj->constFunc();
24+
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
25+
m_obj->mutableFunc();
26+
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
27+
}

0 commit comments

Comments
 (0)
Please sign in to comment.