From 8dc1700979bc630e6bd8b0912cfc034814e67c7f Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 7 Oct 2019 13:58:15 +0000 Subject: [PATCH] RewriteModernObjC - silence static analyzer getAs<> null dereference warnings. NFCI. 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. llvm-svn: 373905 --- clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 0c2ab7a..985bb07 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -2752,7 +2752,7 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { // Create a call to objc_getClass("NSArray"). It will be th 1st argument. ObjCInterfaceDecl *Class = - expType->getPointeeType()->getAs()->getInterface(); + expType->getPointeeType()->castAs()->getInterface(); IdentifierInfo *clsName = Class->getIdentifier(); ClsExprs.push_back(getStringLiteral(clsName->getName())); @@ -2806,7 +2806,7 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); - const FunctionType *FT = msgSendType->getAs(); + const FunctionType *FT = msgSendType->castAs(); CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); ReplaceStmt(Exp, CE); @@ -2894,7 +2894,7 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral // Create a call to objc_getClass("NSArray"). It will be th 1st argument. ObjCInterfaceDecl *Class = - expType->getPointeeType()->getAs()->getInterface(); + expType->getPointeeType()->castAs()->getInterface(); IdentifierInfo *clsName = Class->getIdentifier(); ClsExprs.push_back(getStringLiteral(clsName->getName())); @@ -2957,7 +2957,7 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); - const FunctionType *FT = msgSendType->getAs(); + const FunctionType *FT = msgSendType->castAs(); CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); ReplaceStmt(Exp, CE); @@ -3309,7 +3309,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, case ObjCMessageExpr::Class: { SmallVector ClsExprs; ObjCInterfaceDecl *Class - = Exp->getClassReceiver()->getAs()->getInterface(); + = Exp->getClassReceiver()->castAs()->getInterface(); IdentifierInfo *clsName = Class->getIdentifier(); ClsExprs.push_back(getStringLiteral(clsName->getName())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, ClsExprs, @@ -3530,7 +3530,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, // Don't forget the parens to enforce the proper binding. ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); - const FunctionType *FT = msgSendType->getAs(); + const FunctionType *FT = msgSendType->castAs(); CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); Stmt *ReplacingStmt = CE; @@ -3660,7 +3660,7 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, } } else if (Type->isEnumeralType()) { - EnumDecl *ED = Type->getAs()->getDecl(); + EnumDecl *ED = Type->castAs()->getDecl(); if (ED->isCompleteDefinition()) { Result += "\n\tenum "; Result += ED->getName(); -- 2.7.4