[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
Showing
- include/clang/StaticAnalyzer/Core/Checker.h 15 additions, 0 deletionsinclude/clang/StaticAnalyzer/Core/Checker.h
- include/clang/StaticAnalyzer/Core/CheckerManager.h 27 additions, 3 deletionsinclude/clang/StaticAnalyzer/Core/CheckerManager.h
- lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp 12 additions, 13 deletionslib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
- lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp 10 additions, 0 deletionslib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
- lib/StaticAnalyzer/Core/CheckerManager.cpp 39 additions, 8 deletionslib/StaticAnalyzer/Core/CheckerManager.cpp
- lib/StaticAnalyzer/Core/ExprEngineObjC.cpp 68 additions, 26 deletionslib/StaticAnalyzer/Core/ExprEngineObjC.cpp
- test/Analysis/NSContainers.m 19 additions, 0 deletionstest/Analysis/NSContainers.m
- test/Analysis/objc-message.m 40 additions, 0 deletionstest/Analysis/objc-message.m
Loading
Please register or sign in to comment