]> granicus.if.org Git - clang/commit
[analyzer] Skip Pre/Post handlers for ObjC calls when receiver is nil.
authorDevin Coughlin <dcoughlin@apple.com>
Tue, 15 Sep 2015 01:13:53 +0000 (01:13 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Tue, 15 Sep 2015 01:13:53 +0000 (01:13 +0000)
commit0e7d51e97642e26cc852cca312acd3e1593a9989
treed452057ac35995deb7c7793632fc3dde95d6f870
parentf4a9596475bc09ffe2ef232b68feb81a6e204402
[analyzer] Skip Pre/Post handlers for ObjC calls when receiver is nil.

In Objective-C, method calls with nil receivers are essentially no-ops. They
do not fault (although the returned value may be garbage depending on the
declared return type and architecture). Programmers are aware of this
behavior and will complain about a false alarm when the analyzer
diagnoses API violations for method calls when the receiver is known to
be nil.

Rather than require each individual checker to be aware of this behavior
and suppress a warning when the receiver is nil, this commit
changes ExprEngineObjC so that VisitObjCMessage skips calling checker
pre/post handlers when the receiver is definitely nil. Instead, it adds a
new event, ObjCMessageNil, that is only called in that case.

The CallAndMessageChecker explicitly cares about this case, so I've changed it
to add a callback for ObjCMessageNil and moved the logic in PreObjCMessage
that handles nil receivers to the new callback.

rdar://problem/18092611

Differential Revision: http://reviews.llvm.org/D12123

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247653 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/StaticAnalyzer/Core/Checker.h
include/clang/StaticAnalyzer/Core/CheckerManager.h
lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
lib/StaticAnalyzer/Core/CheckerManager.cpp
lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
test/Analysis/NSContainers.m
test/Analysis/objc-message.m [new file with mode: 0644]