Skip to content

Commit 5a8b229

Browse files
committed
CGObjCMac - silence static analyzer dyn_cast<>/getAs<> null dereference warnings. NFCI.
The static analyzer is warning about potential null dereferences, but we should be able to use cast<>/castAs<> directly and if not assert will fire for us. llvm-svn: 373520
1 parent c7be067 commit 5a8b229

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,14 +2517,12 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout,
25172517
}
25182518

25192519
if (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) {
2520-
const ConstantArrayType *CArray =
2521-
dyn_cast_or_null<ConstantArrayType>(Array);
2520+
auto *CArray = cast<ConstantArrayType>(Array);
25222521
uint64_t ElCount = CArray->getSize().getZExtValue();
25232522
assert(CArray && "only array with known element size is supported");
25242523
FQT = CArray->getElementType();
25252524
while (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) {
2526-
const ConstantArrayType *CArray =
2527-
dyn_cast_or_null<ConstantArrayType>(Array);
2525+
auto *CArray = cast<ConstantArrayType>(Array);
25282526
ElCount *= CArray->getSize().getZExtValue();
25292527
FQT = CArray->getElementType();
25302528
}
@@ -4902,7 +4900,7 @@ LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
49024900
const ObjCIvarDecl *Ivar,
49034901
unsigned CVRQualifiers) {
49044902
const ObjCInterfaceDecl *ID =
4905-
ObjectTy->getAs<ObjCObjectType>()->getInterface();
4903+
ObjectTy->castAs<ObjCObjectType>()->getInterface();
49064904
return EmitValueForIvarAtOffset(CGF, ID, BaseValue, Ivar, CVRQualifiers,
49074905
EmitIvarOffset(CGF, ID, Ivar));
49084906
}
@@ -7053,7 +7051,7 @@ LValue CGObjCNonFragileABIMac::EmitObjCValueForIvar(
70537051
llvm::Value *BaseValue,
70547052
const ObjCIvarDecl *Ivar,
70557053
unsigned CVRQualifiers) {
7056-
ObjCInterfaceDecl *ID = ObjectTy->getAs<ObjCObjectType>()->getInterface();
7054+
ObjCInterfaceDecl *ID = ObjectTy->castAs<ObjCObjectType>()->getInterface();
70577055
llvm::Value *Offset = EmitIvarOffset(CGF, ID, Ivar);
70587056
return EmitValueForIvarAtOffset(CGF, ID, BaseValue, Ivar, CVRQualifiers,
70597057
Offset);

0 commit comments

Comments
 (0)