]> granicus.if.org Git - clang/commitdiff
RewriteModernObjC - silence static analyzer getAs<> null dereference warnings. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 16 Oct 2019 10:50:06 +0000 (10:50 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 16 Oct 2019 10:50:06 +0000 (10:50 +0000)
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<> directly and if not assert will fire for us.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374991 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/Rewrite/RewriteModernObjC.cpp

index 985bb07af65dfe0005d327829e4fdeb068b21f15..45495065ada64c4047da825bbbf9260971d9bd09 100644 (file)
@@ -505,7 +505,7 @@ namespace {
     /// otherwise.
     bool convertBlockPointerToFunctionPointer(QualType &T) {
       if (isTopLevelBlockPointerType(T)) {
-        const BlockPointerType *BPT = T->getAs<BlockPointerType>();
+        const auto *BPT = T->castAs<BlockPointerType>();
         T = Context->getPointerType(BPT->getPointeeType());
         return true;
       }
@@ -856,8 +856,7 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) {
     RD = RD->getDefinition();
     if (RD && !RD->getDeclName().getAsIdentifierInfo()) {
       // decltype(((Foo_IMPL*)0)->bar) *
-      ObjCContainerDecl *CDecl =
-      dyn_cast<ObjCContainerDecl>(D->getDeclContext());
+      auto *CDecl = cast<ObjCContainerDecl>(D->getDeclContext());
       // ivar in class extensions requires special treatment.
       if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
         CDecl = CatDecl->getClassInterface();
@@ -1332,6 +1331,7 @@ void RewriteModernObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
 void RewriteModernObjC::RewriteImplementationDecl(Decl *OID) {
   ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OID);
   ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID);
+  assert((IMD || CID) && "Unknown implementation type");
 
   if (IMD) {
     if (IMD->getIvarRBraceLoc().isValid()) {
@@ -2103,8 +2103,7 @@ RewriteModernObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD,
     ImplicitCastExpr::Create(*Context, pToFunc, CK_FunctionToPointerDecay,
                              DRE, nullptr, VK_RValue);
 
-  const FunctionType *FT = msgSendType->getAs<FunctionType>();
-
+  const auto *FT = msgSendType->castAs<FunctionType>();
   CallExpr *Exp = CallExpr::Create(
       *Context, ICE, Args, FT->getCallResultType(*Context), VK_RValue, EndLoc);
   return Exp;