[clang] 25dc5c7 - Fix "pointer is null" static analyzer warnings. NFCI.
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 14 06:01:11 PST 2020
Author: Simon Pilgrim
Date: 2020-01-14T14:00:37Z
New Revision: 25dc5c7cd159522ec2375544f473c757ee13a03b
URL: https://github.com/llvm/llvm-project/commit/25dc5c7cd159522ec2375544f473c757ee13a03b
DIFF: https://github.com/llvm/llvm-project/commit/25dc5c7cd159522ec2375544f473c757ee13a03b.diff
LOG: Fix "pointer is null" static analyzer warnings. NFCI.
Use castAs<> instead of getAs<> since the pointer is dereferenced immediately below and castAs will perform the null assertion for us.
Added:
Modified:
clang/lib/CodeGen/CGObjC.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 3c11aa7f2f42..c52aa6bb5496 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -488,7 +488,7 @@ tryEmitSpecializedAllocInit(CodeGenFunction &CGF, const ObjCMessageExpr *OME) {
Receiver = CGF.EmitScalarExpr(SelfInClassMethod);
} else {
QualType ReceiverType = SubOME->getClassReceiver();
- const ObjCObjectType *ObjTy = ReceiverType->getAs<ObjCObjectType>();
+ const ObjCObjectType *ObjTy = ReceiverType->castAs<ObjCObjectType>();
const ObjCInterfaceDecl *ID = ObjTy->getInterface();
assert(ID && "null interface should be impossible here");
Receiver = CGF.CGM.getObjCRuntime().GetClass(CGF, ID);
@@ -555,9 +555,7 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E,
case ObjCMessageExpr::Class: {
ReceiverType = E->getClassReceiver();
- const ObjCObjectType *ObjTy = ReceiverType->getAs<ObjCObjectType>();
- assert(ObjTy && "Invalid Objective-C class message send");
- OID = ObjTy->getInterface();
+ OID = ReceiverType->castAs<ObjCObjectType>()->getInterface();
assert(OID && "Invalid Objective-C class message send");
Receiver = Runtime.GetClass(*this, OID);
isClassMessage = true;
More information about the cfe-commits
mailing list