Skip to content

Commit

Permalink
Replace getAs with castAs to fix null dereference static analyzer war…
Browse files Browse the repository at this point in the history
…nings.

Use castAs as we know the cast should succeed (and castAs will assert if it doesn't) and we're dereferencing it directly in the getThisType/getThisObjectType calls.
  • Loading branch information
RKSimon committed Mar 12, 2020
1 parent dbde39e commit 7c2b3c9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions clang/lib/AST/DeclCXX.cpp
Expand Up @@ -2364,17 +2364,15 @@ QualType CXXMethodDecl::getThisType() const {
// volatile X*, and if the member function is declared const volatile,
// the type of this is const volatile X*.
assert(isInstance() && "No 'this' for static methods!");

return CXXMethodDecl::getThisType(getType()->getAs<FunctionProtoType>(),
return CXXMethodDecl::getThisType(getType()->castAs<FunctionProtoType>(),
getParent());
}

QualType CXXMethodDecl::getThisObjectType() const {
// Ditto getThisType.
assert(isInstance() && "No 'this' for static methods!");

return CXXMethodDecl::getThisObjectType(getType()->getAs<FunctionProtoType>(),
getParent());
return CXXMethodDecl::getThisObjectType(
getType()->castAs<FunctionProtoType>(), getParent());
}

bool CXXMethodDecl::hasInlineBody() const {
Expand Down

0 comments on commit 7c2b3c9

Please sign in to comment.