[analyzer] Fix more analyzer warnings on analyzer and libAnalysis.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 28 Aug 2019 21:19:58 +0000 (21:19 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 28 Aug 2019 21:19:58 +0000 (21:19 +0000)
llvm-svn: 370263

clang/lib/Analysis/BodyFarm.cpp
clang/lib/Analysis/CFG.cpp
clang/lib/Analysis/CocoaConventions.cpp
clang/lib/Analysis/RetainSummaryManager.cpp

index 576f86516017bf94dde930c55c44076e56c6ea32..43f9e715b3de2f9b269e6141469ff38d24e0f943 100644 (file)
@@ -408,8 +408,8 @@ static Stmt *create_call_once(ASTContext &C, const FunctionDecl *D) {
   // reference.
   for (unsigned int ParamIdx = 2; ParamIdx < D->getNumParams(); ParamIdx++) {
     const ParmVarDecl *PDecl = D->getParamDecl(ParamIdx);
-    if (PDecl &&
-        CallbackFunctionType->getParamType(ParamIdx - 2)
+    assert(PDecl);
+    if (CallbackFunctionType->getParamType(ParamIdx - 2)
                 .getNonReferenceType()
                 .getCanonicalType() !=
             PDecl->getType().getNonReferenceType().getCanonicalType()) {
index 33c47b24a9a5bd217f61df9f5e9494573d57efd2..e4ed0f86b918afd5de796a39ee184af6c369a506 100644 (file)
@@ -2480,10 +2480,8 @@ CFGBlock *CFGBuilder::VisitBreakStmt(BreakStmt *B) {
 
 static bool CanThrow(Expr *E, ASTContext &Ctx) {
   QualType Ty = E->getType();
-  if (Ty->isFunctionPointerType())
-    Ty = Ty->getAs<PointerType>()->getPointeeType();
-  else if (Ty->isBlockPointerType())
-    Ty = Ty->getAs<BlockPointerType>()->getPointeeType();
+  if (Ty->isFunctionPointerType() || Ty->isBlockPointerType())
+    Ty = Ty->getPointeeType();
 
   const FunctionType *FT = Ty->getAs<FunctionType>();
   if (FT) {
@@ -4906,9 +4904,13 @@ CFGImplicitDtor::getDestructorDecl(ASTContext &astContext) const {
       while (const ArrayType *arrayType = astContext.getAsArrayType(ty)) {
         ty = arrayType->getElementType();
       }
-      const RecordType *recordType = ty->getAs<RecordType>();
-      const CXXRecordDecl *classDecl =
-      cast<CXXRecordDecl>(recordType->getDecl());
+
+      // The situation when the type of the lifetime-extending reference
+      // does not correspond to the type of the object is supposed
+      // to be handled by now. In particular, 'ty' is now the unwrapped
+      // record type.
+      const CXXRecordDecl *classDecl = ty->getAsCXXRecordDecl();
+      assert(classDecl);
       return classDecl->getDestructor();
     }
     case CFGElement::DeleteDtor: {
@@ -4933,12 +4935,6 @@ CFGImplicitDtor::getDestructorDecl(ASTContext &astContext) const {
   llvm_unreachable("getKind() returned bogus value");
 }
 
-bool CFGImplicitDtor::isNoReturn(ASTContext &astContext) const {
-  if (const CXXDestructorDecl *DD = getDestructorDecl(astContext))
-    return DD->isNoReturn();
-  return false;
-}
-
 //===----------------------------------------------------------------------===//
 // CFGBlock operations.
 //===----------------------------------------------------------------------===//
index b2ef426dead28388fabf8e78399b2a6ca6669302..571d72e1a841656e681858332a336e539d4d9042 100644 (file)
@@ -38,8 +38,8 @@ bool cocoa::isRefType(QualType RetTy, StringRef Prefix,
     return false;
 
   // Is the type void*?
-  const PointerType* PT = RetTy->getAs<PointerType>();
-  if (!(PT->getPointeeType().getUnqualifiedType()->isVoidType()))
+  const PointerType* PT = RetTy->castAs<PointerType>();
+  if (!PT || !PT->getPointeeType().getUnqualifiedType()->isVoidType())
     return false;
 
   // Does the name start with the prefix?
index 132053fd2c244559472e64a1c55ad81c7f8c2749..6f46917b2dfc686f852e4846f460e31810ad1ff1 100644 (file)
@@ -504,7 +504,7 @@ RetainSummaryManager::generateSummary(const FunctionDecl *FD,
   FName = FName.substr(FName.find_first_not_of('_'));
 
   // Inspect the result type. Strip away any typedefs.
-  const auto *FT = FD->getType()->getAs<FunctionType>();
+  const auto *FT = FD->getType()->castAs<FunctionType>();
   QualType RetTy = FT->getReturnType();
 
   if (TrackOSObjects)