Author: Manna, Soumi Date: 2023-05-23T11:44:06-07:00 New Revision: 806b0cd5ab5686c1a90d4f13f33517f858fcf4e0
URL: https://github.com/llvm/llvm-project/commit/806b0cd5ab5686c1a90d4f13f33517f858fcf4e0 DIFF: https://github.com/llvm/llvm-project/commit/806b0cd5ab5686c1a90d4f13f33517f858fcf4e0.diff LOG: [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 Added: Modified: clang/lib/CodeGen/ItaniumCXXABI.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index f4f722a1be06..668660124c74 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -580,7 +580,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer( CGBuilderTy &Builder = CGF.Builder; const FunctionProtoType *FPT = - MPT->getPointeeType()->getAs<FunctionProtoType>(); + MPT->getPointeeType()->castAs<FunctionProtoType>(); auto *RD = cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl()); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits