Skip to content

Commit b150494

Browse files
committed
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: 374991
1 parent 95b5d45 commit b150494

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ namespace {
505505
/// otherwise.
506506
bool convertBlockPointerToFunctionPointer(QualType &T) {
507507
if (isTopLevelBlockPointerType(T)) {
508-
const BlockPointerType *BPT = T->getAs<BlockPointerType>();
508+
const auto *BPT = T->castAs<BlockPointerType>();
509509
T = Context->getPointerType(BPT->getPointeeType());
510510
return true;
511511
}
@@ -856,8 +856,7 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) {
856856
RD = RD->getDefinition();
857857
if (RD && !RD->getDeclName().getAsIdentifierInfo()) {
858858
// decltype(((Foo_IMPL*)0)->bar) *
859-
ObjCContainerDecl *CDecl =
860-
dyn_cast<ObjCContainerDecl>(D->getDeclContext());
859+
auto *CDecl = cast<ObjCContainerDecl>(D->getDeclContext());
861860
// ivar in class extensions requires special treatment.
862861
if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
863862
CDecl = CatDecl->getClassInterface();
@@ -1332,6 +1331,7 @@ void RewriteModernObjC::RewriteObjCMethodDecl(const ObjCInterfaceDecl *IDecl,
13321331
void RewriteModernObjC::RewriteImplementationDecl(Decl *OID) {
13331332
ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OID);
13341333
ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID);
1334+
assert((IMD || CID) && "Unknown implementation type");
13351335

13361336
if (IMD) {
13371337
if (IMD->getIvarRBraceLoc().isValid()) {
@@ -2103,8 +2103,7 @@ RewriteModernObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD,
21032103
ImplicitCastExpr::Create(*Context, pToFunc, CK_FunctionToPointerDecay,
21042104
DRE, nullptr, VK_RValue);
21052105

2106-
const FunctionType *FT = msgSendType->getAs<FunctionType>();
2107-
2106+
const auto *FT = msgSendType->castAs<FunctionType>();
21082107
CallExpr *Exp = CallExpr::Create(
21092108
*Context, ICE, Args, FT->getCallResultType(*Context), VK_RValue, EndLoc);
21102109
return Exp;

0 commit comments

Comments
 (0)