summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers
Commit message (Collapse)AuthorAgeFilesLines
...
* [analyzer] Improve localizability checks for iOS / OS X.Devin Coughlin2015-09-222-97/+707
| | | | | | | | | | | | | | | | | | Various improvements to the localization checker: * Adjusted copy to be consistent with diagnostic text in other Apple API checkers. * Added in ~150 UIKit / AppKit methods that require localized strings in UnlocalizedStringsChecker. * UnlocalizedStringChecker now checks for UI methods up the class hierarchy and UI methods that conform for a certain Objective-C protocol. * Added in alpha version of PluralMisuseChecker and some regression tests. False positives are still not ideal. A patch by Kulpreet Chilana! Differential Revision: http://reviews.llvm.org/D12417 llvm-svn: 248350
* [analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).Devin Coughlin2015-09-221-13/+25
| | | | | | | | | | | | | | | | | | Currently realloc(ptr, 0) is treated as free() which seems to be not correct. C standard (N1570) establishes equivalent behavior for malloc(0) and realloc(ptr, 0): "7.22.3 Memory management functions calloc, malloc, realloc: If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object." The patch equalizes the processing of malloc(0) and realloc(ptr,0). The patch also enables unix.Malloc checker to detect references to zero-allocated memory returned by realloc(ptr,0) ("Use of zero-allocated memory" warning). A patch by Антон Ярцев! Differential Revision: http://reviews.llvm.org/D9040 llvm-svn: 248336
* [Static Analyzer] Fixed a false positive case in DynamicTypeChecker when ↵Gabor Horvath2015-09-181-0/+11
| | | | | | dealing with forward declarations. llvm-svn: 248065
* [Static Analyzer] General type checker based on dynamic type information.Gabor Horvath2015-09-184-52/+207
| | | | | | Differential Revision: http://reviews.llvm.org/D12973 llvm-svn: 248041
* [Static Analyzer] Use generics related information to infer dynamic types.Gabor Horvath2015-09-181-13/+31
| | | | | | Differential Revision: http://reviews.llvm.org/D12916 llvm-svn: 248002
* [Static Analyzer] Generics Checker: When an ObjC method returns a ↵Gabor Horvath2015-09-161-76/+136
| | | | | | | | specialized object, track it properly. Differential Revision: http://reviews.llvm.org/D12889 llvm-svn: 247861
* [analyzer] Add generateErrorNode() APIs to CheckerContext.Devin Coughlin2015-09-1642-102/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Skip Pre/Post handlers for ObjC calls when receiver is nil.Devin Coughlin2015-09-152-13/+22
| | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 247653
* [Static Analyzer] Nullability checker optimization.Gabor Horvath2015-09-141-1/+6
| | | | | | Differential Revision: http://reviews.llvm.org/D12848 llvm-svn: 247612
* [Static Analyzer] Moving nullability checkers out of alpha.Gabor Horvath2015-09-141-2/+2
| | | | llvm-svn: 247595
* [Static Analyzer] Moving nullability checkers to a top level package.Gabor Horvath2015-09-142-12/+29
| | | | | | Differential Revision: http://reviews.llvm.org/D12852 llvm-svn: 247590
* [Static Analyzer] Remove a redundant file.Gabor Horvath2015-09-131-623/+0
| | | | llvm-svn: 247533
* [Static Analyzer] Merge the Objective-C Generics Checker into Dynamic Type ↵Gabor Horvath2015-09-133-20/+635
| | | | | | | | Propagation checker. Differential Revision: http://reviews.llvm.org/D12381 llvm-svn: 247532
* [Static Analyzer] Fixed a typo in a diagnostic message.Gabor Horvath2015-09-111-1/+1
| | | | llvm-svn: 247444
* [Static Analyzer] Properly clean up the dynamic type information for dead ↵Gabor Horvath2015-09-111-8/+25
| | | | | | | | regions. Differential Revision: http://reviews.llvm.org/D12767 llvm-svn: 247430
* [Static Analyzer] Minor cleanups for the nullability checker.Gabor Horvath2015-09-111-46/+40
| | | | | | Differential Revision: http://reviews.llvm.org/D12619 llvm-svn: 247423
* [Static Analyzer] Objective-C Generics Checker improvements.Gabor Horvath2015-09-082-150/+204
| | | | | | Differential Revision: http://reviews.llvm.org/D12701 llvm-svn: 247071
* [analyzer] Apply whitespace cleanups by Honggyu Kim.Ted Kremenek2015-09-0846-425/+425
| | | | llvm-svn: 246978
* [Static Analyzer] Remove sinks from nullability checks.Gabor Horvath2015-09-031-26/+146
| | | | | | Differential Revision: http://reviews.llvm.org/D12445 llvm-svn: 246818
* add __builtin_unpredictable and convert to metadataSanjay Patel2015-09-021-2/+3
| | | | | | | | | | | | | | | | | | | | | | | This patch depends on r246688 (D12341). The goal is to make LLVM generate different code for these functions for a target that has cheap branches (see PR23827 for more details): int foo(); int normal(int x, int y, int z) { if (x != 0 && y != 0) return foo(); return 1; } int crazy(int x, int y) { if (__builtin_unpredictable(x != 0 && y != 0)) return foo(); return 1; } Differential Revision: http://reviews.llvm.org/D12458 llvm-svn: 246699
* Revert r246345 until an assertion is fixed.Gabor Horvath2015-08-311-85/+7
| | | | llvm-svn: 246479
* [analyzer] When memcpy'ing into a fixed-size array, do not invalidate entire ↵Devin Coughlin2015-08-281-7/+85
| | | | | | | | | | | | | | | | | | region. Change the analyzer's modeling of memcpy to be more precise when copying into fixed-size array fields. With this change, instead of invalidating the entire containing region the analyzer now invalidates only offsets for the array itself when it can show that the memcpy stays within the bounds of the array. This addresses false positive memory leak warnings of the kind reported by krzysztof in https://llvm.org/bugs/show_bug.cgi?id=22954 A patch by Pierre Gousseau! Differential Revision: http://reviews.llvm.org/D11832 llvm-svn: 246345
* [Static Analyzer] Make NonNullParamChecker emit implicit null dereference ↵Gabor Horvath2015-08-273-21/+34
| | | | | | | | events. Differential Revision: http://reviews.llvm.org/D11433 llvm-svn: 246182
* [Static Analyzer] Checks to catch nullability related issues.Gabor Horvath2015-08-263-0/+864
| | | | | | Differential Revision: http://reviews.llvm.org/D11468 llvm-svn: 246105
* Add missing newline.Ted Kremenek2015-08-261-1/+1
| | | | llvm-svn: 246003
* [Static Analyzer] Fixed a typo in a diagnostic message.Gabor Horvath2015-08-251-1/+1
| | | | llvm-svn: 245949
* [OPENMP 4.0] Initial support for array sections.Alexey Bataev2015-08-252-0/+10
| | | | | | | | Adds parsing/sema analysis/serialization/deserialization for array sections in OpenMP constructs (introduced in OpenMP 4.0). Currently it is allowed to use array sections only in OpenMP clauses that accepts list of expressions. Differential Revision: http://reviews.llvm.org/D10732 llvm-svn: 245937
* [Static Analyzer] Add checker to catch lightweight generics related type ↵Gabor Horvath2015-08-213-0/+574
| | | | | | | | errors in Objective-C. Differential Revision: http://reviews.llvm.org/D11427 llvm-svn: 245646
* clangStaticAnalyzerCheckers: Update libdesp.NAKAMURA Takumi2015-08-151-0/+1
| | | | llvm-svn: 245145
* [analyzer] Add checkers for OS X / iOS localizability issuesAnna Zaks2015-08-143-0/+604
| | | | | | | | | | | | | | | Add checkers that detect code-level localizability issues for OS X / iOS: - A path sensitive checker that warns about uses of non-localized NSStrings passed to UI methods expecting localized strings. - A syntax checker that warns against not including a comment in NSLocalizedString macros. A patch by Kulpreet Chilana! (This is the second attempt with the compilation issue on Windows and the random test failures resolved.) llvm-svn: 245093
* Wdeprecated: Make the SecKeychainBugVisitor copyable (for the clone support ↵David Blaikie2015-08-131-1/+0
| | | | | | | | | in the CRTP base) my removing the user-declared dtor The implicit dtor is just as good, and avoid suppressing implicit copy/move ops. llvm-svn: 244981
* Wdeprecated: BugReporterVisitors are copied for cloning ↵David Blaikie2015-08-131-3/+2
| | | | | | | | | | (BugReporterVisitorImpl), make sure such copies are safe Make the copy/move ctors defaulted in the base class and make the derived classes final to avoid any intermediate hierarchy slicing if these types were further derived. llvm-svn: 244979
* Wdeprecated: CollectReachableSymbolsCallback are move constructed/returned ↵David Blaikie2015-08-133-3/+3
| | | | | | | | | | | | | | by value, so make sure they're copy/moveable (return by value is in ExprEngine::processPointerEscapedOnBind and any other call to the scanReachableSymbols function template used there) Protect the special members in the base class to avoid slicing, and make derived classes final so these special members don't accidentally become public on an intermediate base which would open up the possibility of slicing again. llvm-svn: 244975
* Remove and forbid raw_svector_ostream::flush() calls.Yaron Keren2015-08-132-2/+0
| | | | | | | | | | After r244870 flush() will only compare two null pointers and return, doing nothing but wasting run time. The call is not required any more as the stream and its SmallString are always in sync. Thanks to David Blaikie for reviewing. llvm-svn: 244928
* [Static Analyzer] Warn when inner and outer conditions are identical. The ↵Daniel Marjamaki2015-08-101-0/+18
| | | | | | | | inner condition is always true. Reviewed in http://reviews.llvm.org/D10892. llvm-svn: 244435
* Revert "[analyzer] Add checkers for OS X / iOS localizability issues"Anna Zaks2015-08-083-568/+0
| | | | | | | | This reverts commit fc885033a30b6e30ccf82398ae7c30e646727b10. Revert all localization checker commits until the proper fix is implemented. llvm-svn: 244394
* Revert "[analyzer] Fixup to r244389 to make this build on windows."Anna Zaks2015-08-081-1/+1
| | | | | | | | This reverts commit 57a46a75b408245cf4154a838fe13ad702065745. Revert all localization checker commits until the proper fix is implemented. llvm-svn: 244393
* [analyzer] Fixup to r244389 to make this build on windows.Anna Zaks2015-08-081-1/+1
| | | | llvm-svn: 244390
* [analyzer] Add checkers for OS X / iOS localizability issuesAnna Zaks2015-08-083-0/+568
| | | | | | | | | | | | Add checkers that detect code-level localizability issues for OS X / iOS: - A path sensitive checker that warns about uses of non-localized NSStrings passed to UI methods expecting localized strings. - A syntax checker that warns against not including a comment in NSLocalizedString macros. A patch by Kulpreet Chilana! llvm-svn: 244389
* [analyzer] Don't issue alarm in ObjCSuperCallChecker for the super class itself.Devin Coughlin2015-08-081-1/+1
| | | | | | | | | | | | | | | | | The ObjCSuperCallChecker issues alarms for various Objective-C APIs that require a subclass to call to its superclass's version of a method when overriding it. So, for example, it raises an alarm when the -viewDidLoad method in a subclass of UIViewController does not call [super viewDidLoad]. This patch fixes a false alarm where the analyzer erroneously required the implementation of the superclass itself (e.g., UIViewController) to call super. rdar://problem/18416944 Differential Revision: http://reviews.llvm.org/D11842 llvm-svn: 244386
* [Analyzer] Move FindSuperCallVisitor into an anonymous namespace.Benjamin Kramer2015-07-141-2/+0
| | | | | | No functionality change. llvm-svn: 242140
* Rewrite users of Stmt::child_begin/end into for-range loops.Benjamin Kramer2015-07-0312-52/+41
| | | | | | No functionality change intended. llvm-svn: 241355
* Switch users of the 'for (StmtRange range = stmt->children(); range; ↵Benjamin Kramer2015-07-022-6/+6
| | | | | | | | | ++range)‘ pattern to range for loops. The pattern was born out of the lack of range-based for loops in C++98 and is somewhat obscure. No functionality change intended. llvm-svn: 241300
* Clarify pointer ownership semantics by hoisting the std::unique_ptr creation ↵Aaron Ballman2015-06-2341-260/+236
| | | | | | 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-2228-49/+47
| | | | llvm-svn: 240353
* Don't use &* when get() will suffice; NFC.Aaron Ballman2015-06-221-4/+4
| | | | llvm-svn: 240279
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-2228-47/+49
| | | | | | | | | | | | 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
* Allow the cf_returns_[not_]retained attributes to appear on out-parameters.Douglas Gregor2015-06-191-5/+69
| | | | | | | | | | | | | | | | Includes a simple static analyzer check and not much else, but we'll also be able to take advantage of this in Swift. This feature can be tested for using __has_feature(cf_returns_on_parameters). This commit also contains two fixes: - Look through non-typedef sugar when deciding whether something is a CF type. - When (cf|ns)_returns(_not)?_retained is applied to invalid properties, refer to "property" instead of "method" in the error message. rdar://problem/18742441 llvm-svn: 240185
* [analyzer] Remove ObjCContainersChecker size information when a ↵Devin Coughlin2015-06-151-1/+24
| | | | | | | | | | | | | CFMutableArrayRef escapes Update ObjCContainersChecker to be notified when pointers escape so it can remove size information for escaping CFMutableArrayRefs. When such pointers escape, un-analyzed code could mutate the array and cause the size information to be incorrect. rdar://problem/19406485 llvm-svn: 239709
* [analyzer]Test commit fixing 80-column violation in comment. NFC.Devin Coughlin2015-06-041-1/+2
| | | | llvm-svn: 238993
OpenPOWER on IntegriCloud