r373398 - CGVTables - silence static analyzer getAs<FunctionProtoType> null dereference warnings. NFCI.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 1 15:02:47 PDT 2019


Author: rksimon
Date: Tue Oct  1 15:02:46 2019
New Revision: 373398

URL: http://llvm.org/viewvc/llvm-project?rev=373398&view=rev
Log:
CGVTables - silence static analyzer getAs<FunctionProtoType> null dereference warnings. NFCI.

The static analyzer is warning about potential null dereferences, but we should be able to use castAs<FunctionProtoType> directly and if not assert will fire for us.

Modified:
    cfe/trunk/lib/CodeGen/CGVTables.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=373398&r1=373397&r2=373398&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Oct  1 15:02:46 2019
@@ -157,7 +157,7 @@ CodeGenFunction::GenerateVarArgsThunk(ll
                                       const CGFunctionInfo &FnInfo,
                                       GlobalDecl GD, const ThunkInfo &Thunk) {
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
-  const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
+  const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
   QualType ResultType = FPT->getReturnType();
 
   // Get the original function
@@ -242,7 +242,6 @@ void CodeGenFunction::StartThunk(llvm::F
   // Build FunctionArgs.
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   QualType ThisType = MD->getThisType();
-  const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
   QualType ResultType;
   if (IsUnprototyped)
     ResultType = CGM.getContext().VoidTy;
@@ -251,7 +250,7 @@ void CodeGenFunction::StartThunk(llvm::F
   else if (CGM.getCXXABI().hasMostDerivedReturn(GD))
     ResultType = CGM.getContext().VoidPtrTy;
   else
-    ResultType = FPT->getReturnType();
+    ResultType = MD->getType()->castAs<FunctionProtoType>()->getReturnType();
   FunctionArgList FunctionArgs;
 
   // Create the implicit 'this' parameter declaration.




More information about the cfe-commits mailing list