[all-commits] [llvm/llvm-project] 806b0c: [NFC][CLANG] Fix issue with dereference null retur...

smanna12 via All-commits all-commits at lists.llvm.org
Tue May 23 11:45:11 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 806b0cd5ab5686c1a90d4f13f33517f858fcf4e0
      https://github.com/llvm/llvm-project/commit/806b0cd5ab5686c1a90d4f13f33517f858fcf4e0
  Author: Manna, Soumi <soumi.manna at intel.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    M clang/lib/CodeGen/ItaniumCXXABI.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list