[clang] 7c2b3c9 - Replace getAs with castAs to fix null dereference static analyzer warnings.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 12 07:59:43 PDT 2020


Author: Simon Pilgrim
Date: 2020-03-12T14:56:51Z
New Revision: 7c2b3c9dda37ab25a6849a3670f1bfda6aa17e5e

URL: https://github.com/llvm/llvm-project/commit/7c2b3c9dda37ab25a6849a3670f1bfda6aa17e5e
DIFF: https://github.com/llvm/llvm-project/commit/7c2b3c9dda37ab25a6849a3670f1bfda6aa17e5e.diff

LOG: Replace getAs with castAs to fix null dereference static analyzer warnings.

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.

Added: 
    

Modified: 
    clang/lib/AST/DeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 3645169b8901..8e9258a8ab88 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -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 {


        


More information about the cfe-commits mailing list