summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/Inputs
Commit message (Collapse)AuthorAgeFilesLines
...
* [analyzer] Suppress false positives in std::shared_ptrDevin Coughlin2016-07-062-100/+146
| | | | | | | | | | | | | | | | | | | | | The analyzer does not model C++ temporary destructors completely and so reports false alarms about leaks of memory allocated by the internals of shared_ptr: std::shared_ptr<int> p(new int(1)); p = nullptr; // 'Potential leak of memory pointed to by field __cntrl_' This patch suppresses all diagnostics where the end of the path is inside a method in std::shared_ptr. It also reorganizes the tests for suppressions in the C++ standard library to use a separate simulated header for library functions with bugs that were deliberately inserted to test suppression. This will prevent other tests from using these as models. rdar://problem/23652766 llvm-svn: 274691
* [analyzer] Nullability: Don't warn along paths where null returned from ↵Devin Coughlin2016-03-281-2/+3
| | | | | | | | | | | | | | | | non-null. Change the nullability checker to not warn along paths where null is returned from a method with a non-null return type, even when the diagnostic for this return has been suppressed. This prevents warning from methods with non-null return types that inline methods that themselves return nil but that suppressed the diagnostic. Also change the PreconditionViolated state component to be called "InvariantViolated" because it is set when a post-condition is violated, as well. rdar://problem/25393539 llvm-svn: 264647
* [analyzer] Add CIFIlter modeling to DeallocChecker.Devin Coughlin2016-03-251-0/+3
| | | | | | | | | | | | | | | | | | | | The -dealloc method in CIFilter is highly unusual in that it will release instance variables belonging to its *subclasses* if the variable name starts with "input" or backs a property whose name starts with "input". Subclasses should not release these ivars in their own -dealloc method -- doing so could result in an over release. Before this commit, the DeallocChecker would warn about missing releases for such "input" properties -- which could cause users of the analyzer to add over releases to silence the warning. To avoid this, DeallocChecker now treats CIFilter "input-prefixed" ivars as MustNotReleaseDirectly and so will not require a release. Further, it will now warn when such an ivar is directly released in -dealloc. rdar://problem/25364901 llvm-svn: 264463
* [analyzer] Nullability: add option to not report on calls to system headers.Devin Coughlin2016-03-051-0/+42
| | | | | | | | | | | | | | Add an -analyzer-config 'nullability:NoDiagnoseCallsToSystemHeaders' option to the nullability checker. When enabled, this option causes the analyzer to not report about passing null/nullable values to functions and methods declared in system headers. This option is motivated by the observation that large projects may have many nullability warnings. These projects may find warnings about nullability annotations that they have explicitly added themselves higher priority to fix than warnings on calls to system libraries. llvm-svn: 262763
* [analyzer] Teach CheckObjCDealloc about Block_release().Devin Coughlin2016-02-291-0/+3
| | | | | | It now treats Block_release(b) as a release in addition to [b release]. llvm-svn: 262272
* [analyzer] Don't treat calls to system headers as escaping in CheckObjCDealloc.Devin Coughlin2016-02-291-0/+29
| | | | | | | | | | | | | | | | | | | This prevents false negatives when a -dealloc method, for example, removes itself as as an observer with [[NSNotificationCenter defaultCenter] removeObserver:self]. It is unlikely that passing 'self' to a system header method will release 'self''s instance variables, so this is unlikely to produce false positives. A challenge here is that while CheckObjCDealloc no longer treats these calls as escaping, the rest of the analyzer still does. In particular, this means that loads from the same instance variable before and after a call to a system header will result in different symbols being loaded by the region store. To account for this, the checker now treats different ivar symbols with the same instance and ivar decl as the same for the purpose of release checking and more eagerly removes a release requirement when an instance variable is assumed to be nil. This was not needed before because when an ivar escaped its release requirement was always removed -- now the requirement is not removed for calls to system headers. llvm-svn: 262261
* [analyzer] Invalidate destination of std::copy() and std::copy_backward().Devin Coughlin2016-02-071-3/+115
| | | | | | | | | Now that the libcpp implementations of these methods has a branch that doesn't call memmove(), the analyzer needs to invalidate the destination for these methods explicitly. rdar://problem/23575656 llvm-svn: 260043
* [analyzer] Fix false warning about memory leak for QApplication::postEventAnna Zaks2016-01-061-0/+16
| | | | | | | | | | | According to Qt documentation Qt takes care of memory allocated for QEvent: http://doc.qt.io/qt-4.8/qcoreapplication.html#postEvent A patch by Evgeniy Dushistov! Differential Revision: http://reviews.llvm.org/D14170 llvm-svn: 256887
* [analyzer] Suppress reports coming from std::__independent_bits_engineAnna Zaks2016-01-061-0/+19
| | | | | | | | | | | | | The analyzer reports a shift by a negative value in the constructor. The bug can be easily triggered by calling std::random_shuffle on a vector (<rdar://problem/19658126>). (The shift by a negative value is reported because __w0_ gets constrained to 63 by the conditions along the path:__w0_ < _WDt && __w0_ >= _WDt-1, where _WDt is 64. In normal execution, __w0_ is not 63, it is 1 and there is no overflow. The path is infeasible, but the analyzer does not know about that.) llvm-svn: 256886
* [analyzer] Add VforkChecker to find unsafe code in vforked process.Yury Gribov2015-11-061-0/+10
| | | | | | | | | | | | This checker looks for unsafe constructs in vforked process: function calls (excluding whitelist), memory write and returns. This was originally motivated by a vfork-related bug in xtables package. Patch by Yury Gribov. Differential revision: http://reviews.llvm.org/D14014 llvm-svn: 252285
* [analyzer] Assume escape is possible through system functions taking void*Anna Zaks2015-10-271-0/+6
| | | | | | | | | | | | | | | | | | The analyzer assumes that system functions will not free memory or modify the arguments in other ways, so we assume that arguments do not escape when those are called. However, this may lead to false positive leak errors. For example, in code like this where the pointers added to the rb_tree are freed later on: struct alarm_event *e = calloc(1, sizeof(*e)); <snip> rb_tree_insert_node(&alarm_tree, e); Add a heuristic to assume that calls to system functions taking void* arguments allow for pointer escape. llvm-svn: 251449
* [analyzer] Fix pthread lock tests so that the API comes from a system header.Jordan Rose2014-09-101-0/+28
| | | | | | | | ...and verify that a global mutex in user code can be used without warnings. Patch by Aleksei Sidorin! llvm-svn: 217515
* Add support for the static analyzer to synthesize function implementations ↵Ted Kremenek2014-08-272-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | from external model files. Currently the analyzer lazily models some functions using 'BodyFarm', which constructs a fake function implementation that the analyzer can simulate that approximates the semantics of the function when it is called. BodyFarm does this by constructing the AST for such definitions on-the-fly. One strength of BodyFarm is that all symbols and types referenced by synthesized function bodies are contextual adapted to the containing translation unit. The downside is that these ASTs are hardcoded in Clang's own source code. A more scalable model is to allow these models to be defined as source code in separate "model" files and have the analyzer use those definitions lazily when a function body is needed. Among other things, it will allow more customization of the analyzer for specific APIs and platforms. This patch provides the initial infrastructure for this feature. It extends BodyFarm to use an abstract API 'CodeInjector' that can be used to synthesize function bodies. That 'CodeInjector' is implemented using a new 'ModelInjector' in libFrontend, which lazily parses a model file and injects the ASTs into the current translation unit. Models are currently found by specifying a 'model-path' as an analyzer option; if no path is specified the CodeInjector is not used, thus defaulting to the current behavior in the analyzer. Models currently contain a single function definition, and can be found by finding the file <function name>.model. This is an initial starting point for something more rich, but it bootstraps this feature for future evolution. This patch was contributed by Gábor Horváth as part of his Google Summer of Code project. Some notes: - This introduces the notion of a "model file" into FrontendAction and the Preprocessor. This nomenclature is specific to the static analyzer, but possibly could be generalized. Essentially these are sources pulled in exogenously from the principal translation. Preprocessor gets a 'InitializeForModelFile' and 'FinalizeForModelFile' which could possibly be hoisted out of Preprocessor if Preprocessor exposed a new API to change the PragmaHandlers and some other internal pieces. This can be revisited. FrontendAction gets a 'isModelParsingAction()' predicate function used to allow a new FrontendAction to recycle the Preprocessor and ASTContext. This name could probably be made something more general (i.e., not tied to 'model files') at the expense of losing the intent of why it exists. This can be revisited. - This is a moderate sized patch; it has gone through some amount of offline code review. Most of the changes to the non-analyzer parts are fairly small, and would make little sense without the analyzer changes. - Most of the analyzer changes are plumbing, with the interesting behavior being introduced by ModelInjector.cpp and ModelConsumer.cpp. - The new functionality introduced by this change is off-by-default. It requires an analyzer config option to enable. llvm-svn: 216550
* [analyzer] Just silence all warnings coming out of std::basic_string.Jordan Rose2014-02-071-3/+26
| | | | | | | | | This means always walking the whole call stack for the end path node, but we'll assume that's always fairly tractable. <rdar://problem/15952973> llvm-svn: 200980
* [analyzer] Pointers escape into +[NSValue valueWithPointer:]...Jordan Rose2014-01-071-2/+5
| | | | | | | | | | ...even though the argument is declared "const void *", because this is just a way to pass pointers around as objects. (Though NSData is often a better one.) PR18262 llvm-svn: 198710
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-051-2/+2
| | | | llvm-svn: 196510
* [analyzer] Better modeling of memcpy by the CStringChecker (PR16731).Anton Yartsev2013-11-171-0/+1
| | | | | | | | | | | | | | New rules of invalidation/escape of the source buffer of memcpy: the source buffer contents is invalidated and escape while the source buffer region itself is neither invalidated, nor escape. In the current modeling of memcpy the information about allocation state of regions, accessible through the source buffer, is not copied to the destination buffer and we can not track the allocation state of those regions anymore. So we invalidate/escape the source buffer indirect regions in anticipation of their being invalidated for real later. This eliminates false-positive leaks reported by the unix.Malloc and alpha.cplusplus.NewDeleteLeaks checkers for the cases like char *f() { void *x = malloc(47); char *a; memcpy(&a, &x, sizeof a); return a; } llvm-svn: 194953
* [analyzer] Silence warnings coming from allocators used by std::basic_string.Jordan Rose2013-11-151-11/+33
| | | | | | | | | | | | This is similar to r194004: because we can't reason about the data structure invariants of std::basic_string, the analyzer decides it's possible for an allocator to be used to deallocate the string's inline storage. Just ignore this by walking up the stack, skipping past methods in classes with "allocator" in the name, and seeing if we reach std::basic_string that way. PR17866 llvm-svn: 194764
* [analyzer] Suppress warnings coming out of std::basic_string.Anna Zaks2013-11-041-0/+16
| | | | | | The analyzer cannot reason about the internal invariances of the data structure (radar://15194597). llvm-svn: 194004
* [analyzer] Treat std::initializer_list as opaque rather than aborting.Jordan Rose2013-07-171-0/+28
| | | | | | | | | | | | | | Previously, the use of a std::initializer_list (actually, a CXXStdInitializerListExpr) would cause the analyzer to give up on the rest of the path. Now, it just uses an opaque symbolic value for the initializer_list and continues on. At some point in the future we can add proper support for initializer_list, with access to the elements in the InitListExpr. <rdar://problem/14340207> llvm-svn: 186519
* [analyzer] Fixup for r185609: actually do suppress warnings coming out of ↵Anna Zaks2013-07-091-1/+7
| | | | | | | | | | | std::list. list is the name of a class, not a namespace. Change the test as well - the previous version did not test properly. Fixes radar://14317928. llvm-svn: 185898
* [analyzer] Suppress reports reported in std::listAnna Zaks2013-07-041-0/+17
| | | | | | | | | | | The motivation is to suppresses false use-after-free reports that occur when calling std::list::pop_front() or std::list::pop_back() twice. The analyzer does not reason about the internal invariants of the list implementation, so just do not report any of warnings in std::list. Fixes radar://14317928. llvm-svn: 185609
* [analyzer] Malloc checker should only escape the receiver when “[O ↵Anna Zaks2013-05-311-0/+1
| | | | | | | | | init..]” is called. Jordan has pointed out that it is valuable to warn in cases when the arguments to init escape. For example, NSData initWithBytes id not going to free the memory. llvm-svn: 183062
* [analyzer] Indirect invalidation counts as an escape for leak checkers.Jordan Rose2013-05-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this example: char *p = malloc(sizeof(char)); systemFunction(&p); free(p); In this case, when we call systemFunction, we know (because it's a system function) that it won't free 'p'. However, we /don't/ know whether or not it will /change/ 'p', so the analyzer is forced to invalidate 'p', wiping out any bindings it contains. But now the malloc'd region looks like a leak, since there are no more bindings pointing to it, and we'll get a spurious leak warning. The fix for this is to notice when something is becoming inaccessible due to invalidation (i.e. an imperfect model, as opposed to being explicitly overwritten) and stop tracking it at that point. Currently, the best way to determine this for a call is the "indirect escape" pointer-escape kind. In practice, all the patch does is take the "system functions don't free memory" special case and limit it to direct parameters, i.e. just the arguments to a call and not other regions accessible to them. This is a conservative change that should only cause us to escape regions more eagerly, which means fewer leak warnings. This isn't perfect for several reasons, the main one being that this example is treated the same as the one above: char **p = malloc(sizeof(char *)); systemFunction(p + 1); // leak Currently, "addresses accessible by offsets of the starting region" and "addresses accessible through bindings of the starting region" are both considered "indirect" regions, hence this uniform treatment. Another issue is our longstanding problem of not distinguishing const and non-const bindings; if in the first example systemFunction's parameter were a char * const *, we should know that the function will not overwrite 'p', and thus we can safely report the leak. <rdar://problem/13758386> llvm-svn: 181607
* [analyzer] Don't inline the [cd]tors of C++ iterators.Jordan Rose2013-05-011-0/+6
| | | | | | | | | | | | | | | | | This goes with r178516, which instructed the analyzer not to inline the constructors and destructors of C++ container classes. This goes a step further and does the same thing for iterators, so that the analyzer won't falsely decide we're trying to construct an iterator pointing to a nonexistent element. The heuristic for determining whether something is an iterator is the presence of an 'iterator_category' member. This is controlled under the same -analyzer-config option as container constructor/destructor inlining: 'c++-container-inlining'. <rdar://problem/13770187> llvm-svn: 180890
* [analyzer] Re-enable using global regions as a symbolic base.Jordan Rose2013-04-151-0/+4
| | | | | | | | | | | | | | | | Now that we're invalidating global regions properly, we want to continue taking advantage of a particular optimization: if all global regions are invalidated together, we can represent the bindings of each region with a "derived region value" symbol. Essentially, this lazily links each global region with a single symbol created at invalidation time, rather than binding each region with a new symbolic value. We used to do this, but haven't been for a while; the previous commit re-enabled this code path, and this handles the fallout. <rdar://problem/13464044> llvm-svn: 179554
* [analyzer] Tests: move system functions into system header simulator files.Jordan Rose2013-04-151-1/+6
| | | | | | | | | | Some checkers ascribe different behavior to functions declared in system headers, so when working with standard library functions it's probably best to always have them in a standard location. Test change only (no functionality change), but necessary for the next commit. llvm-svn: 179552
* [analyzer] Allow suppressing diagnostics reported within the 'std' namespaceJordan Rose2013-04-021-0/+7
| | | | | | | | | | | | This is controlled by the 'suppress-c++-stdlib' analyzer-config flag. It is currently off by default. This is more suppression than we'd like to do, since obviously there can be user-caused issues within 'std', but it gives us the option to wield a large hammer to suppress false positives the user likely can't work around. llvm-svn: 178513
* [analyzer] Adds cplusplus.NewDelete checker that check for memory leaks, ↵Anton Yartsev2013-03-251-0/+24
| | | | | | double free, and use-after-free problems of memory managed by new/delete. llvm-svn: 177849
* [analyzer] Be more consistent about Objective-C methods that free memory.Jordan Rose2013-03-091-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, MallocChecker's pointer escape check and its post-call state update for Objective-C method calls had a fair amount duplicated logic and not-entirely-consistent checks. This commit restructures all this to be more consistent and possibly allow us to be more aggressive in warning about double-frees. New policy (applies to system header methods only): (1) If this is a method we know about, model it as taking/holding ownership of the passed-in buffer. (1a) ...unless there's a "freeWhenDone:" parameter with a zero (NO) value. (2) If there's a "freeWhenDone:" parameter (but it's not a method we know about), treat the buffer as escaping if the value is non-zero (YES) and non-escaping if it's zero (NO). (3) If the first selector piece ends with "NoCopy" (but it's not a method we know about and there's no "freeWhenDone:" parameter), treat the buffer as escaping. The reason that (2) and (3) don't explicitly model the ownership transfer is because we can't be sure that they will actually free the memory using free(), and we wouldn't want to emit a spurious "mismatched allocator" warning (coming in Anton's upcoming patch). In the future, we may have an idea of a "generic deallocation", i.e. we assume that the deallocator is correct but still continue tracking the region so that we can warn about double-frees. Patch by Anton Yartsev, with modifications from me. llvm-svn: 176744
* [analyzer] Add pointer escape type param to checkPointerEscape callbackAnna Zaks2013-02-072-0/+14
| | | | | | | | | | | | | | The checkPointerEscape callback previously did not specify how a pointer escaped. This change includes an enum which describes the different ways a pointer may escape. This enum is passed to the checkPointerEscape callback when a pointer escapes. If the escape is due to a function call, the call is passed. This changes previous behavior where the call is passed as NULL if the escape was due to indirectly invalidating the region the pointer referenced. A patch by Branden Archer! llvm-svn: 174677
* [analyzer] Explain why we have system-header-simulator*.h files.Jordan Rose2013-02-014-1/+20
| | | | | | Suggested by Csaba. Text based on an e-mail of mine on cfe-dev. llvm-svn: 174213
* [analyzer] Add symbol escapes logic to the SimpleStreamChecker.Anna Zaks2012-11-061-0/+11
| | | | llvm-svn: 167439
* clang/test/Analysis: Fix the declaration of strlen() for 32 bit targets.NAKAMURA Takumi2012-09-201-1/+3
| | | | | | | | | | - Inputs/system-header-simulator.h: Declare strlen() with size_t. - malloc-interprocedural.c: Move the definition of size_t into the header above. Then XFAIL can be pruned. llvm-svn: 164300
* Adjust some analyzer tests to place widely shared inputs inside of anChandler Carruth2012-09-123-0/+249
'Inputs' subdirectory. The general desire has been to have essentially all of the non-test input files live in such directories, with some exceptions for obvious and common patterns like 'foo.c' using 'foo.h'. This came up because our distributed test runner couldn't find some of the headers, for example with stl.cpp. No functionality changed, just shuffling around here. llvm-svn: 163674
OpenPOWER on IntegriCloud