[clang] 6e0c441 - [NFC][CLANG] Fix nullptr dereference found by Coverity static analysis tool
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 5 11:58:09 PDT 2023
Author: Manna, Soumi
Date: 2023-05-05T11:57:33-07:00
New Revision: 6e0c44174823260fd74d14d036eaf1c64fa5eded
URL: https://github.com/llvm/llvm-project/commit/6e0c44174823260fd74d14d036eaf1c64fa5eded
DIFF: https://github.com/llvm/llvm-project/commit/6e0c44174823260fd74d14d036eaf1c64fa5eded.diff
LOG: [NFC][CLANG] Fix nullptr dereference found by Coverity static analysis tool
Reported by Coverity:
In clang::ASTContext::hasUniqueObjectRepresentations(clang::QualType, bool): Return value of function which returns null is dereferenced without checking.
(Ty->isMemberPointerType()) {
//returned_null: getAs returns nullptr.
//var_assigned: Assigning: MPT = nullptr return value from getAs.
const auto *MPT = Ty->getAs<MemberPointerType>();
//dereference: Dereferencing a pointer that might be nullptr MPT when calling getMemberPointerInfo. (The virtual call resolves to
<unnamed>::ItaniumCXXABI::getMemberPointerInfo.)
return !ABI->getMemberPointerInfo(MPT).HasPadding;
}
ABIs assume the parameter passed to `getMemberPointerInfo` is non-null.
This patch checks type by doing a `if (const auto *MPT = Ty->getAs<MemberPointerType>())` instead.
Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D149922
Added:
Modified:
clang/lib/AST/ASTContext.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 3a72c3d25794..de65c3cc47b9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2859,10 +2859,8 @@ bool ASTContext::hasUniqueObjectRepresentations(
if (Ty->isPointerType())
return true;
- if (Ty->isMemberPointerType()) {
- const auto *MPT = Ty->getAs<MemberPointerType>();
+ if (const auto *MPT = Ty->getAs<MemberPointerType>())
return !ABI->getMemberPointerInfo(MPT).HasPadding;
- }
if (Ty->isRecordType()) {
const RecordDecl *Record = Ty->castAs<RecordType>()->getDecl();
More information about the cfe-commits
mailing list