[clang] 9f8c0d1 - DeclCXX - Fix getAs<> null-dereference static analyzer warnings. NFCI.
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 4 07:14:48 PST 2021
Author: Simon Pilgrim
Date: 2021-01-04T15:12:55Z
New Revision: 9f8c0d15c7f706a124ba29e8f40dc1937cd5bd49
URL: https://github.com/llvm/llvm-project/commit/9f8c0d15c7f706a124ba29e8f40dc1937cd5bd49
DIFF: https://github.com/llvm/llvm-project/commit/9f8c0d15c7f706a124ba29e8f40dc1937cd5bd49.diff
LOG: DeclCXX - Fix getAs<> null-dereference static analyzer warnings. NFCI.
getAs<> can return null if the cast is invalid, which can lead to null pointer deferences. Use castAs<> instead which will assert that the cast is valid.
Added:
Modified:
clang/lib/AST/DeclCXX.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 16eb8206dba2..b806adf36bfb 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1508,7 +1508,7 @@ CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const {
CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const {
CXXMethodDecl *CallOp = getLambdaCallOperator();
- CallingConv CC = CallOp->getType()->getAs<FunctionType>()->getCallConv();
+ CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv();
return getLambdaStaticInvoker(CC);
}
@@ -1532,8 +1532,8 @@ CXXMethodDecl *CXXRecordDecl::getLambdaStaticInvoker(CallingConv CC) const {
DeclContext::lookup_result Invoker = getLambdaStaticInvokers(*this);
for (NamedDecl *ND : Invoker) {
- const FunctionType *FTy =
- cast<ValueDecl>(ND->getAsFunction())->getType()->getAs<FunctionType>();
+ const auto *FTy =
+ cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>();
if (FTy->getCallConv() == CC)
return getInvokerAsMethod(ND);
}
More information about the cfe-commits
mailing list