This is an archive of the discontinued LLVM Phabricator instance.

[NFC][CLANG] Fix issue with dereference null return value found by Coverity static analyzer tool
ClosedPublic

Authored by Manna on May 21 2023, 8:25 PM.

Details

Summary

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.

Diff Detail

Event Timeline

Manna created this revision.May 21 2023, 8:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 21 2023, 8:25 PM
Manna requested review of this revision.May 21 2023, 8:25 PM
Manna edited the summary of this revision. (Show Details)
Manna edited the summary of this revision. (Show Details)May 21 2023, 8:29 PM
erichkeane accepted this revision.May 22 2023, 6:13 AM
This revision is now accepted and ready to land.May 22 2023, 6:13 AM
Manna added a comment.May 22 2023, 7:20 AM

Thank you @erichkeane for reviews!

Manna updated this revision to Diff 524296.May 22 2023, 7:21 AM

Fix Clang-format errors

Manna set the repository for this revision to rG LLVM Github Monorepo.May 22 2023, 12:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 12:23 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript