[all-commits] [llvm/llvm-project] 6e0c44: [NFC][CLANG] Fix nullptr dereference found by Cove...

smanna12 via All-commits all-commits at lists.llvm.org
Fri May 5 11:58:17 PDT 2023


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

  Changed paths:
    M clang/lib/AST/ASTContext.cpp

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




More information about the All-commits mailing list