forked from OSchip/llvm-project
[Static Analyzer] Fixed a false positive case in DynamicTypeChecker when dealing with forward declarations.
llvm-svn: 248065
This commit is contained in:
parent
324da7b207
commit
659842d0fc
|
@ -151,6 +151,14 @@ PathDiagnosticPiece *DynamicTypeChecker::DynamicTypeBugVisitor::VisitNode(
|
|||
return new PathDiagnosticEventPiece(Pos, OS.str(), true, nullptr);
|
||||
}
|
||||
|
||||
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr) {
|
||||
const ObjCInterfaceDecl *Decl = ObjPtr->getInterfaceDecl();
|
||||
if (!Decl)
|
||||
return false;
|
||||
|
||||
return Decl->getDefinition();
|
||||
}
|
||||
|
||||
// TODO: consider checking explicit casts?
|
||||
void DynamicTypeChecker::checkPostStmt(const ImplicitCastExpr *CE,
|
||||
CheckerContext &C) const {
|
||||
|
@ -177,6 +185,9 @@ void DynamicTypeChecker::checkPostStmt(const ImplicitCastExpr *CE,
|
|||
if (!DynObjCType || !StaticObjCType)
|
||||
return;
|
||||
|
||||
if (!hasDefinition(DynObjCType) || !hasDefinition(StaticObjCType))
|
||||
return;
|
||||
|
||||
ASTContext &ASTCtxt = C.getASTContext();
|
||||
|
||||
// Strip kindeofness to correctly detect subtyping relationships.
|
||||
|
|
|
@ -26,8 +26,18 @@ __attribute__((objc_root_class))
|
|||
@interface NSNumber : NSObject <NSCopying>
|
||||
@end
|
||||
|
||||
@class MyType;
|
||||
|
||||
void testTypeCheck(NSString* str) {
|
||||
id obj = str;
|
||||
NSNumber *num = obj; // expected-warning {{}}
|
||||
(void)num;
|
||||
}
|
||||
|
||||
void testForwardDeclarations(NSString* str) {
|
||||
id obj = str;
|
||||
// Do not warn, since no information is available wether MyType is a sub or
|
||||
// super class of any other type.
|
||||
MyType *num = obj; // no warning
|
||||
(void)num;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue