Manna created this revision.
Manna added a reviewer: erichkeane.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.

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;
    }

This patch uses castAs instead of getAs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149922

Files:
  clang/lib/AST/ASTContext.cpp


Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2860,7 +2860,7 @@
     return true;
 
   if (Ty->isMemberPointerType()) {
-    const auto *MPT = Ty->getAs<MemberPointerType>();
+    const auto *MPT = Ty->castAs<MemberPointerType>();
     return !ABI->getMemberPointerInfo(MPT).HasPadding;
   }
 


Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2860,7 +2860,7 @@
     return true;
 
   if (Ty->isMemberPointerType()) {
-    const auto *MPT = Ty->getAs<MemberPointerType>();
+    const auto *MPT = Ty->castAs<MemberPointerType>();
     return !ABI->getMemberPointerInfo(MPT).HasPadding;
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to