Skip to content

Commit

Permalink
Replace getAs/dyn_cast with castAs/cast to fix null dereference stati…
Browse files Browse the repository at this point in the history
…c analyzer warnings.

Both these casts are immediately deferenced and the cast will assert for us that they are of the correct type.
  • Loading branch information
RKSimon committed Mar 12, 2020
1 parent b93dd67 commit 7bfc3bf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
Expand Up @@ -2688,7 +2688,7 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) {
// Don't forget the parens to enforce the proper binding.
ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast);

const FunctionType *FT = msgSendType->getAs<FunctionType>();
auto *FT = msgSendType->castAs<FunctionType>();
CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(),
VK_RValue, EndLoc);
ReplaceStmt(Exp, CE);
Expand Down Expand Up @@ -7501,8 +7501,7 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
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();
Expand Down

0 comments on commit 7bfc3bf

Please sign in to comment.