[NFC][CLANG] Fix issue with dereference null return value found by Coverity static...
authorManna, Soumi <soumi.manna@intel.com>
Tue, 23 May 2023 18:41:28 +0000 (11:41 -0700)
committerManna, Soumi <soumi.manna@intel.com>
Tue, 23 May 2023 18:44:06 +0000 (11:44 -0700)
commit806b0cd5ab5686c1a90d4f13f33517f858fcf4e0
tree366563b7e87615a3064b136f203674898caaec0d
parentece2b65bc6543fa5da5f7a8afab2087860feb556
[NFC][CLANG] Fix issue with dereference null return value found by Coverity static analyzer tool

Reported by Coverity static analyzer tool:

Inside "ItaniumCXXABI.cpp" file, in <unnamed>::ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(clang::CodeGen::CodeGenFunction &, clang::Expr const *, clang::CodeGen::Address, llvm::Value *&, llvm::Value *, clang::MemberPointerType const *): Return value of function which returns null is dereferenced without checking.

   //returned_null: getAs returns nullptr (checked 130 out of 156 times).
   //var_assigned: Assigning: FPT = nullptr return value from getAs.
   const FunctionProtoType *FPT =
     MPT->getPointeeType()->getAs<FunctionProtoType>();
  auto *RD =
     cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl());

  // Dereference null return value (NULL_RETURNS)
  //dereference: Dereferencing a pointer that might be nullptr FPT when calling arrangeCXXMethodType.
   llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(
       CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr));

This patch uses castAs instead of getAs which will assert if the type doesn't match.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D151054
clang/lib/CodeGen/ItaniumCXXABI.cpp