Skip to content

Commit 39a9141

Browse files
authored
isUncountedPtr should take QualType as an argument. (#110213)
Make isUncountedPtr take QualType as an argument instead of Type*. This simplifies some code.
1 parent 820bab8 commit 39a9141

File tree

5 files changed

+12
-28
lines changed

5 files changed

+12
-28
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,10 @@ std::optional<bool> isUncounted(const CXXRecordDecl* Class)
177177
return (*IsRefCountable);
178178
}
179179

180-
std::optional<bool> isUncountedPtr(const Type* T)
181-
{
182-
assert(T);
183-
180+
std::optional<bool> isUncountedPtr(const QualType T) {
184181
if (T->isPointerType() || T->isReferenceType()) {
185-
if (auto *CXXRD = T->getPointeeCXXRecordDecl()) {
182+
if (auto *CXXRD = T->getPointeeCXXRecordDecl())
186183
return isUncounted(CXXRD);
187-
}
188184
}
189185
return false;
190186
}
@@ -208,12 +204,8 @@ std::optional<bool> isGetterOfRefCounted(const CXXMethodDecl* M)
208204
// Ref<T> -> T conversion
209205
// FIXME: Currently allowing any Ref<T> -> whatever cast.
210206
if (isRefType(className)) {
211-
if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
212-
if (auto *targetConversionType =
213-
maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) {
214-
return isUncountedPtr(targetConversionType);
215-
}
216-
}
207+
if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M))
208+
return isUncountedPtr(maybeRefToRawOperator->getConversionType());
217209
}
218210
}
219211
return false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ std::optional<bool> isUncounted(const clang::CXXRecordDecl* Class);
6161

6262
/// \returns true if \p T is either a raw pointer or reference to an uncounted
6363
/// class, false if not, std::nullopt if inconclusive.
64-
std::optional<bool> isUncountedPtr(const clang::Type* T);
64+
std::optional<bool> isUncountedPtr(const clang::QualType T);
6565

6666
/// \returns true if Name is a RefPtr, Ref, or its variant, false if not.
6767
bool isRefType(const std::string &Name);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,8 @@ class UncountedCallArgsChecker
115115
// continue;
116116

117117
QualType ArgType = (*P)->getType().getCanonicalType();
118-
const auto *TypePtr = ArgType.getTypePtrOrNull();
119-
if (!TypePtr)
120-
continue; // FIXME? Should we bail?
121-
122118
// FIXME: more complex types (arrays, references to raw pointers, etc)
123-
std::optional<bool> IsUncounted = isUncountedPtr(TypePtr);
119+
std::optional<bool> IsUncounted = isUncountedPtr(ArgType);
124120
if (!IsUncounted || !(*IsUncounted))
125121
continue;
126122

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class UncountedLambdaCapturesChecker
5959
for (const LambdaCapture &C : L->captures()) {
6060
if (C.capturesVariable()) {
6161
ValueDecl *CapturedVar = C.getCapturedVar();
62-
if (auto *CapturedVarType = CapturedVar->getType().getTypePtrOrNull()) {
63-
std::optional<bool> IsUncountedPtr = isUncountedPtr(CapturedVarType);
64-
if (IsUncountedPtr && *IsUncountedPtr) {
65-
reportBug(C, CapturedVar, CapturedVarType);
66-
}
62+
QualType CapturedVarQualType = CapturedVar->getType();
63+
if (auto *CapturedVarType = CapturedVarQualType.getTypePtrOrNull()) {
64+
auto IsUncountedPtr = isUncountedPtr(CapturedVarQualType);
65+
if (IsUncountedPtr && *IsUncountedPtr)
66+
reportBug(C, CapturedVar, CapturedVarType);
6767
}
6868
}
6969
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ class UncountedLocalVarsChecker
199199
if (shouldSkipVarDecl(V))
200200
return;
201201

202-
const auto *ArgType = V->getType().getTypePtr();
203-
if (!ArgType)
204-
return;
205-
206-
std::optional<bool> IsUncountedPtr = isUncountedPtr(ArgType);
202+
std::optional<bool> IsUncountedPtr = isUncountedPtr(V->getType());
207203
if (IsUncountedPtr && *IsUncountedPtr) {
208204
if (tryToFindPtrOrigin(
209205
Value, /*StopAtFirstRefCountedObj=*/false,

0 commit comments

Comments
 (0)