[clang] 7bfc3bf - Replace getAs/dyn_cast with castAs/cast to fix null dereference static analyzer warnings.
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 12 09:55:10 PDT 2020
Author: Simon Pilgrim
Date: 2020-03-12T16:50:50Z
New Revision: 7bfc3bf39b6d279657b480963e72b6c08191b2f2
URL: https://github.com/llvm/llvm-project/commit/7bfc3bf39b6d279657b480963e72b6c08191b2f2
DIFF: https://github.com/llvm/llvm-project/commit/7bfc3bf39b6d279657b480963e72b6c08191b2f2.diff
LOG: Replace getAs/dyn_cast with castAs/cast to fix null dereference static analyzer warnings.
Both these casts are immediately deferenced and the cast will assert for us that they are of the correct type.
Added:
Modified:
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
index f3a27804bcac..fff4a45c5330 100644
--- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
@@ -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);
@@ -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();
More information about the cfe-commits
mailing list