summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-1/+1
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* [analyzer] introduce getSVal(Stmt *) helper on ExplodedNode, make sure the ↵George Karpenkov2018-01-171-7/+5
| | | | | | | | | | | | | | | | | | helper is used consistently In most cases using `N->getState()->getSVal(E, N->getLocationContext())` is ugly, verbose, and also opens up more surface area for bugs if an inconsistent location context is used. This patch introduces a helper on an exploded node, and ensures consistent usage of either `ExplodedNode::getSVal` or `CheckContext::getSVal` across the codebase. As a result, a large number of redundant lines is removed. Differential Revision: https://reviews.llvm.org/D42155 llvm-svn: 322753
* Suppress all uses of LLVM_END_WITH_NULL. NFC.Serge Guelton2017-05-091-26/+20
| | | | | | | | | | Use variadic templates instead of relying on <cstdarg> + sentinel. This enforces better type checking and makes code more readable. Differential revision: https://reviews.llvm.org/D32550 llvm-svn: 302572
* [analyzer] Report CFNumberGetValue API misuseAnna Zaks2016-10-261-35/+42
| | | | | | | | | | | | This patch contains 2 improvements to the CFNumber checker: - Checking of CFNumberGetValue misuse. - Treating all CFNumber API misuse errors as non-fatal. (Previously we treated errors that could cause uninitialized memory as syncs and the truncation errors as non-fatal.) This implements a subset of functionality from https://reviews.llvm.org/D17954. Differential Revision: https://reviews.llvm.org/D25876 llvm-svn: 285253
* Fix some Clang-tidy readability-redundant-control-flow warnings; other minor ↵Eugene Zelenko2016-02-101-10/+6
| | | | | | | | fixes. Differential revision: http://reviews.llvm.org/D17060 llvm-svn: 260414
* Refactor: Simplify boolean conditional return statements in ↵Alexander Kornienko2015-12-281-8/+3
| | | | | | | | | | | | | | | | lib/StaticAnalyzer/Checkers Summary: Use clang-tidy to simplify boolean conditional return values Reviewers: dcoughlin, krememek Subscribers: krememek, cfe-commits Patch by Richard Thomson! Differential Revision: http://reviews.llvm.org/D10021 llvm-svn: 256491
* [static analyzer] Don't flag nil storage into NSMutableDictionary.Anna Zaks2015-11-111-2/+1
| | | | | | This is now allowed and has the behavior of removing the mapping. llvm-svn: 252679
* [analyzer] Add generateErrorNode() APIs to CheckerContext.Devin Coughlin2015-09-161-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The analyzer trims unnecessary nodes from the exploded graph before reporting path diagnostics. However, in some cases it can trim all nodes (including the error node), leading to an assertion failure (see https://llvm.org/bugs/show_bug.cgi?id=24184). This commit addresses the issue by adding two new APIs to CheckerContext to explicitly create error nodes. Unless the client provides a custom tag, these APIs tag the node with the checker's tag -- preventing it from being trimmed. The generateErrorNode() method creates a sink error node, while generateNonFatalErrorNode() creates an error node for a path that should continue being explored. The intent is that one of these two methods should be used whenever a checker creates an error node. This commit updates the checkers to use these APIs. These APIs (unlike addTransition() and generateSink()) do not take an explicit Pred node. This is because there are not any error nodes in the checkers that were created with an explicit different than the default (the CheckerContext's Pred node). It also changes generateSink() to require state and pred nodes (previously these were optional) to reduce confusion. Additionally, there were several cases where checkers did check whether a generated node could be null; we now explicitly check for null in these places. This commit also includes a test case written by Ying Yi as part of http://reviews.llvm.org/D12163 (that patch originally addressed this issue but was reverted because it introduced false positive regressions). Differential Revision: http://reviews.llvm.org/D12780 llvm-svn: 247859
* [analyzer] Apply whitespace cleanups by Honggyu Kim.Ted Kremenek2015-09-081-23/+23
| | | | llvm-svn: 246978
* Clarify pointer ownership semantics by hoisting the std::unique_ptr creation ↵Aaron Ballman2015-06-231-10/+10
| | | | | | to the caller instead of hiding it in emitReport. NFC. llvm-svn: 240400
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-5/+5
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-5/+5
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* [analyzer] Check for NULL passed to CFAutorelease.Jordan Rose2014-06-211-6/+11
| | | | | | Patch by Sean McBride, tests adjusted by me. llvm-svn: 211453
* [C++11] Use 'nullptr'. StaticAnalyzer edition.Craig Topper2014-05-271-13/+14
| | | | llvm-svn: 209642
* [analyzer] When checking Foundation method calls, match the selectors exactly.Jordan Rose2014-04-091-42/+72
| | | | | | | | | | This also includes some infrastructure to make it easier to build multi-argument selectors, rather than trying to use string matching on each piece. There's a bit more setup code, but less cost at runtime. PR18908 llvm-svn: 205827
* Replace OwningPtr with std::unique_ptr.Ahmed Charles2014-03-071-5/+5
| | | | | | This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
* [C++11] Replace llvm::tie with std::tie.Benjamin Kramer2014-03-021-2/+2
| | | | llvm-svn: 202639
* Expose the name of the checker producing each diagnostic message.Alexander Kornienko2014-02-111-11/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In clang-tidy we'd like to know the name of the checker producing each diagnostic message. PathDiagnostic has BugType and Category fields, which are both arbitrary human-readable strings, but we need to know the exact name of the checker in the form that can be used in the CheckersControlList option to enable/disable the specific checker. This patch adds the CheckName field to the CheckerBase class, and sets it in the CheckerManager::registerChecker() method, which gets them from the CheckerRegistry. Checkers that implement multiple checks have to store the names of each check in the respective registerXXXChecker method. Reviewers: jordan_rose, krememek Reviewed By: jordan_rose CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2557 llvm-svn: 201186
* [analyzer] Objective-C object literals are always non-nil.Jordan Rose2014-02-081-4/+26
| | | | | | <rdar://problem/15999214> llvm-svn: 201007
* Fixed a FIXME; created a print method for Selectors that accepts a ↵Aaron Ballman2014-01-031-6/+11
| | | | | | | | raw_ostream, and started using it in places it made sense. No functional changes intended, just API cleanliness. llvm-svn: 198428
* Remove a whole lot of unused variablesAlp Toker2013-11-271-2/+1
| | | | | | | There are about 30 removed in this patch, generated by a new FixIt I haven't got round to submitting yet. llvm-svn: 195814
* Revert 'Tweak ContainerNonEmptyMap with "int" instead of "bool"'.Jordan Rose2013-11-081-3/+3
| | | | | | | | | I've added the missing ImutProfileInfo [sic] specialization for bool, so this patch on r194235 is no longer needed. This reverts r194244 / 2baea2887dfcf023c8e3560e5d4713c42eed7b6b. llvm-svn: 194265
* StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp: Tweak ↵NAKAMURA Takumi2013-11-081-3/+3
| | | | | | | | | ContainerNonEmptyMap with "int" instead of "bool", to appease building since r194235. In ADT/ImmutableSet, ImutProfileInfo<bool> cannot be matched to ImutProfileInteger. I didn't have idea it'd the right way if PROFILE_INTEGER_INFO(bool) could be added there. llvm-svn: 194244
* [analyzer] Track whether an ObjC for-in loop had zero iterations.Jordan Rose2013-11-081-16/+85
| | | | | | | | | | | | | | | | | An Objective-C for-in loop will have zero iterations if the collection is empty. Previously, we could only detect this case if the program asked for the collection's -count /before/ the for-in loop. Now, the analyzer distinguishes for-in loops that had zero iterations from those with at least one, and can use this information to constrain the result of calling -count after the loop. In order to make this actually useful, teach the checker that methods on NSArray, NSDictionary, and the other immutable collection classes don't change the count. <rdar://problem/14992886> llvm-svn: 194235
* [analyzer] Track the count of NSOrderedSet similarly to other fast enumerations.Anna Zaks2013-11-041-1/+2
| | | | llvm-svn: 194005
* [analyzer] Use output form collections’ count to decide if ObjC for loop ↵Anna Zaks2013-06-221-8/+175
| | | | | | | | | | | should be entered This fixes false positives by allowing us to know that a loop is always entered if the collection count method returns a positive value and vice versa. Addresses radar://14169391. llvm-svn: 184618
* [analyzer] Refactor: address Jordan’s code review of r181738.Anna Zaks2013-05-131-14/+12
| | | | | | (Modifying the checker to record that the values are no longer nil will be done separately.) llvm-svn: 181744
* [analyzer] Warn about nil elements/keys/values in array and dictionary literals.Anna Zaks2013-05-131-19/+76
| | | | llvm-svn: 181738
* [analyzer] Assume [NSNull null] does not return nil.Anna Zaks2013-05-101-1/+14
| | | | llvm-svn: 181616
* [analyzer] An ObjC for-in loop runs 0 times if the collection is nil.Jordan Rose2013-04-261-22/+65
| | | | | | | | | | | | | | | In an Objective-C for-in loop "for (id element in collection) {}", the loop will run 0 times if the collection is nil. This is because the for-in loop is implemented using a protocol method that returns 0 when there are no elements to iterate, and messages to nil will result in a 0 return value. At some point we may want to actually model this message send, but for now we may as well get the nil case correct, and avoid the false positives that would come with this case. <rdar://problem/13744632> llvm-svn: 180639
* [analyzer] Replace isIntegerType() with isIntegerOrEnumerationType().Jordan Rose2013-04-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Previously, the analyzer used isIntegerType() everywhere, which uses the C definition of "integer". The C++ predicate with the same behavior is isIntegerOrUnscopedEnumerationType(). However, the analyzer is /really/ using this to ask if it's some sort of "integrally representable" type, i.e. it should include C++11 scoped enumerations as well. hasIntegerRepresentation() sounds like the right predicate, but that includes vectors, which the analyzer represents by its elements. This commit audits all uses of isIntegerType() and replaces them with the general isIntegerOrEnumerationType(), except in some specific cases where it makes sense to exclude scoped enumerations, or any enumerations. These cases now use isIntegerOrUnscopedEnumerationType() and getAs<BuiltinType>() plus BuiltinType::isInteger(). isIntegerType() is hereby banned in the analyzer - lib/StaticAnalysis and include/clang/StaticAnalysis. :-) Fixes real assertion failures. PR15703 / <rdar://problem/12350701> llvm-svn: 179081
* Tweak warning text for nil value in ObjC container warning.Ted Kremenek2013-04-081-1/+1
| | | | llvm-svn: 179034
* [analyzer] Reword error messages for nil keys and values of NSMutableDictionary.Anna Zaks2013-04-051-6/+17
| | | | llvm-svn: 178935
* [analyzer] Make sure IDC works for ‘NSContainer value/key is nil’ checks.Anna Zaks2013-03-261-0/+1
| | | | | | | | | Register the nil tracking visitors with the region and refactor trackNullOrUndefValue a bit. Also adds the cast and paren stripping before checking if the value is an OpaqueValueExpr or ExprWithCleanups. llvm-svn: 178093
* [analyzer] Warn when a nil key or value are passed to NSMutableDictionary ↵Anna Zaks2013-03-231-16/+62
| | | | | | and ensure it works with subscripting. llvm-svn: 177789
* [analyzer] Warn when a ‘nil’ object is added to NSArray or NSMutableArray.Anna Zaks2013-03-181-4/+33
| | | | llvm-svn: 177318
* [analyzer] Rename AttrNonNullChecker -> NonNullParamCheckerAnna Zaks2013-03-091-1/+1
| | | | llvm-svn: 176755
* Avoid implicit conversions of Optional<T> to bool.David Blaikie2013-02-211-1/+1
| | | | | | | This is a precursor to making Optional<T>'s operator bool 'explicit' when building Clang & LLVM as C++11. llvm-svn: 175722
* Use None rather than Optional<T>() where possible.David Blaikie2013-02-211-1/+1
| | | | llvm-svn: 175705
* Include llvm::Optional in clang/Basic/LLVM.hDavid Blaikie2013-02-201-9/+6
| | | | | | Post-commit CR feedback from Jordan Rose regarding r175594. llvm-svn: 175679
* Remove redundant Optional type in favor of llvm::OptionalDavid Blaikie2013-02-201-24/+4
| | | | llvm-svn: 175678
* Replace SVal llvm::cast support to be well-defined.David Blaikie2013-02-201-10/+14
| | | | | | See r175462 for another example/more details. llvm-svn: 175594
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-7/+7
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
* Include pruning and general cleanup.Benjamin Kramer2012-12-011-0/+1
| | | | llvm-svn: 169095
* [analyzer] Check that the argument to CFMakeCollectable is non-NULL.Jordan Rose2012-11-071-9/+17
| | | | | | Patch by Sean McBride! llvm-svn: 167537
* [analyzer] Remove isWithinInlined. It's been replaced with inTopFrame().Anna Zaks2012-11-061-1/+1
| | | | | | Thanks Jordan. llvm-svn: 167438
* [analyzer] Rename 'EmitReport' to 'emitReport'.Jordan Rose2012-11-021-5/+5
| | | | | | No functionality change. llvm-svn: 167275
* [analyzer] Fix a buildbot crash triggered by turning on dynamicAnna Zaks2012-09-251-1/+1
| | | | | | dispatch. llvm-svn: 164579
* Make helper functions static.Benjamin Kramer2012-09-101-3/+3
| | | | llvm-svn: 163505
* [analyzer] Remove cast inside dyn_cast.Anna Zaks2012-08-301-1/+1
| | | | llvm-svn: 162951
OpenPOWER on IntegriCloud