summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis
Commit message (Collapse)AuthorAgeFilesLines
...
* [analyzer] Insert checker options into AnalyzerOption::ConfigTableKristof Umann2019-05-172-2/+54
| | | | | | | | | | | | | The more entries we have in AnalyzerOptions::ConfigTable, the more helpful debug.ConfigDumper is. With this patch, I'm pretty confident that it'll now emit the entire state of the analyzer, minus the frontend flags. It would be nice to reserve the config table specifically to checker options only, as storing the regular analyzer configs is kinda redundant. Differential Revision: https://reviews.llvm.org/D57922 llvm-svn: 361006
* [Analysis] Only run plugins tests if plugins are actually enabledPetr Hosek2019-05-171-2/+2
| | | | | | | | | | | | | | When plugins aren't enabled, don't try to run plugins tests. Don't enable plugins unconditionally based on the platform, instead check if LLVM shared library is actually being built which may not be the case for every host configuration, even if the host itself supports plugins. This addresses test failures introduced by r360891/D59464. Differential Revision: https://reviews.llvm.org/D62050 llvm-svn: 360991
* [analyzer] Add a test plugin for checker option handlingKristof Umann2019-05-165-0/+73
| | | | | | Differential Revision: https://reviews.llvm.org/D59465 llvm-svn: 360910
* Reland "[analyzer] Add an example plugin for checker dependency handling"Kristof Umann2019-05-169-2/+144
| | | | | | | | | | | Buildbots complained that they couldn't find the newly added plugins. The solution was to move the check-clang cmake target closer to the bottom of the file, after the new dependencies are added. Differential Revision: https://reviews.llvm.org/D59464 llvm-svn: 360891
* Revert "[analyzer] Add a test for plugins using checker dependencies"Kristof Umann2019-05-159-144/+2
| | | | | | Buildbots don't seem to find the new plugin. llvm-svn: 360805
* [analyzer] Add a test for plugins using checker dependenciesKristof Umann2019-05-159-2/+144
| | | | | | | | | | Also, I moved the existing analyzer plugin to test/ as well, in order not to give the illusion that the analyzer supports plugins -- it's capable of handling them, but does not _support_ them. Differential Revision: https://reviews.llvm.org/D59464 llvm-svn: 360799
* [analyzer] RetainCount: Fix os_returns_retained_on_zero with weird return types.Artem Dergachev2019-05-151-0/+13
| | | | | | | | | The checker was crashing when it was trying to assume a structure to be null or non-null so that to evaluate the effect of the annotation. Differential Revision: https://reviews.llvm.org/D61958 llvm-svn: 360790
* [analyzer] MIGChecker: Add support for os_ref_retain().Artem Dergachev2019-05-151-0/+20
| | | | | | | | | | Suppress MIG checker false positives that occur when the programmer increments the reference count before calling a MIG destructor, and the MIG destructor literally boils down to decrementing the reference count. Differential Revision: https://reviews.llvm.org/D61925 llvm-svn: 360737
* [analyzer] Fix a crash when doing RVO from within blocks.Artem Dergachev2019-05-071-0/+18
| | | | | | | | | | When looking for the location context of the call site, unwrap block invocation contexts because they are attached to the current AnalysisDeclContext while what we need is the previous AnalysisDeclContext. Differential Revision: https://reviews.llvm.org/D61545 llvm-svn: 360202
* [analyzer][UninitializedObjectChecker] PR41741: Regard all scalar types as ↵Kristof Umann2019-05-051-6/+35
| | | | | | | | | | | | | | | | | | | | primitive. https://bugs.llvm.org/show_bug.cgi?id=41741 Pretty much the same as D61246 and D61106, this time for __complex__ types. Upon further investigation, I realized that we should regard all types Type::isScalarType returns true for as primitive, so I merged isMemberPointerType(), isBlockPointerType() and isAnyComplexType()` into that instead. I also stumbled across yet another bug, https://bugs.llvm.org/show_bug.cgi?id=41753, but it seems to be unrelated to this checker. Differential Revision: https://reviews.llvm.org/D61569 llvm-svn: 359998
* [analyzer] Don't display implementation checkers under ↵Kristof Umann2019-05-011-0/+11
| | | | | | | | | | | | | | | | | | | | | | | -analyzer-checker-help, but do under the new flag -analyzer-checker-help-hidden During my work on analyzer dependencies, I created a great amount of new checkers that emitted no diagnostics at all, and were purely modeling some function or another. However, the user shouldn't really disable/enable these by hand, hence this patch, which hides these by default. I intentionally chose not to hide alpha checkers, because they have a scary enough name, in my opinion, to cause no surprise when they emit false positives or cause crashes. The patch introduces the Hidden bit into the TableGen files (you may remember it before I removed it in D53995), and checkers that are either marked as hidden, or are in a package that is marked hidden won't be displayed under -analyzer-checker-help. -analyzer-checker-help-hidden, a new flag meant for developers only, displays the full list. Differential Revision: https://reviews.llvm.org/D60925 llvm-svn: 359720
* [analyzer][tests][NFC] Add EOF newlines, normalize reference expected filesHubert Tong2019-05-013-2/+3
| | | | | | | | | | | Reference expected files not ending with a newline are normalized to have said newlines. Additionally `plist-macros-with-expansion.cpp.plist` is modified to add a line that is ignored by `%diff_plist`, but not by the more sensitive pattern proposed by http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html for `%normalize_plist`. llvm-svn: 359692
* [analyzer][tests] Use diff_plist, correct order of arguments for missed ↵Hubert Tong2019-05-015-5/+5
| | | | | | | | | | | | | cases; NFC For various files under `clang/test/Analysis`, D52036 applied `%diff_plist` to replace `diff` invocations with certain options and D56340 swapped the order of the arguments so that the reference file comes first. The tests that used `tail` to filter the test output were not modified accordingly. This patch applies the corresponding update to those tests. llvm-svn: 359691
* [analyzer][UninitializedObjectChecker] PR41611: Regard vector types as primitiveKristof Umann2019-04-302-2/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | https://bugs.llvm.org/show_bug.cgi?id=41611 Similarly to D61106, the checker ran over an llvm_unreachable for vector types: struct VectorSizeLong { VectorSizeLong() {} __attribute__((__vector_size__(16))) long x; }; void __vector_size__LongTest() { VectorSizeLong v; } Since, according to my short research, "The vector_size attribute is only applicable to integral and float scalars, although arrays, pointers, and function return values are allowed in conjunction with this construct." [src: https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Vector-Extensions.html#Vector-Extensions] vector types are safe to regard as primitive. Differential Revision: https://reviews.llvm.org/D61246 llvm-svn: 359539
* [analyzer] Treat functions without run-time branches as "small".Artem Dergachev2019-04-301-0/+18
| | | | | | | | | | | | | | | | | | Currently we always inline functions that have no branches, i.e. have exactly three CFG blocks: ENTRY, some code, EXIT. This makes sense because when there are no branches, it means that there's no exponential complexity introduced by inlining such function. Such functions also don't trigger various fundamental problems with our inlining mechanism, such as the problem of inlined defensive checks. Sometimes the CFG may contain more blocks, but in practice it still has linear structure because all directions (except, at most, one) of all branches turned out to be unreachable. When this happens, still treat the function as "small". This is useful, in particular, for dealing with C++17 if constexpr. Differential Revision: https://reviews.llvm.org/D61051 llvm-svn: 359531
* [analyzer] SmartPtrModeling: Fix a null dereference.Artem Dergachev2019-04-301-0/+10
| | | | | | | | | Don't crash when trying to model a call in which the callee is unknown in compile time, eg. a pointer-to-member call. Differential Revision: https://reviews.llvm.org/D61285 llvm-svn: 359530
* [analyzer] RetainCount: Add a suppression for "the Matching rule".Artem Dergachev2019-04-261-0/+23
| | | | | | | | | | | | | | | | In the OSObject universe there appears to be another slightly popular contract, apart from "create" and "get", which is "matching". It optionally consumes a "table" parameter and if a table is passed, it fills in the table and returns it at +0; otherwise, it creates a new table, fills it in and returns it at +1. For now suppress false positives by doing a conservative escape on all functions that end with "Matching", which is the naming convention that seems to be followed by all such methods. Differential Revision: https://reviews.llvm.org/D61161 llvm-svn: 359264
* [analyzer] RetainCount: Allow offsets in return values.Artem Dergachev2019-04-261-0/+32
| | | | | | | | | | | | | | | | | | Because RetainCountChecker has custom "local" reasoning about escapes, it has a separate facility to deal with tracked symbols at end of analysis and check them for leaks regardless of whether they're dead or not. This facility iterates over the list of tracked symbols and reports them as leaks, but it needs to treat the return value specially. Some custom allocators tend to return the value with an offset, storing extra metadata at the beginning of the buffer. In this case the return value would be a non-base region. In order to avoid false positives, we still need to find the original symbol within the return value, otherwise it'll be unable to match it to the item in the list of tracked symbols. Differential Revision: https://reviews.llvm.org/D60991 llvm-svn: 359263
* [analyzer] Fix crash when returning C++ objects from ObjC messages-to-nil.Artem Dergachev2019-04-261-0/+24
| | | | | | | | | | | the assertion is in fact incorrect: there is a cornercase in Objective-C++ in which a C++ object is not constructed with a constructor, but merely zero-initialized. Namely, this happens when an Objective-C message is sent to a nil and it is supposed to return a C++ object. Differential Revision: https://reviews.llvm.org/D60988 llvm-svn: 359262
* [analyzer] Add FIXMEs for alpha.unix.cstring.OutOfBounds false positives.Artem Dergachev2019-04-251-0/+1
| | | | | | | Caused by incorrect strlcat() modeling in r332303, cf. https://bugs.llvm.org/show_bug.cgi?id=37687#c8 llvm-svn: 359237
* [analyzer][UninitializedObjectChecker] PR41590: Regard _Atomic types as ↵Kristof Umann2019-04-251-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | primitive https://bugs.llvm.org/show_bug.cgi?id=41590 For the following code snippet, UninitializedObjectChecker crashed: struct MyAtomicInt { _Atomic(int) x; MyAtomicInt() {} }; void entry() { MyAtomicInt b; } The problem was that _Atomic types were not regular records, unions, dereferencable or primitive, making the checker hit the llvm_unreachable at lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp:347. The solution is to regard these types as primitive as well. The test case shows that with this addition, not only are we able to get rid of the crash, but we can identify x as uninitialized. Differential Revision: https://reviews.llvm.org/D61106 llvm-svn: 359230
* Add missing diagnostic for anonymous struct/union definitions that don'tRichard Smith2019-04-241-1/+1
| | | | | | introduce any names. llvm-svn: 359051
* [analyzer] Fix macro names in diagnostics within bigger macros.Artem Dergachev2019-04-231-1/+26
| | | | | | | | | If macro "CHECK_X(x)" expands to something like "if (x != NULL) ...", the "Assuming..." note no longer says "Assuming 'x' is equal to CHECK_X". Differential Revision: https://reviews.llvm.org/D59121 llvm-svn: 359037
* [analyzer][CrossTU] Extend CTU to VarDecls with initializerRafael Stahl2019-04-235-2/+149
| | | | | | | | | | | | | | | | | | | | | | Summary: The existing CTU mechanism imports `FunctionDecl`s where the definition is available in another TU. This patch extends that to VarDecls, to bind more constants. - Add VarDecl importing functionality to CrossTranslationUnitContext - Import Decls while traversing them in AnalysisConsumer - Add VarDecls to CTU external mappings generator - Name changes from "external function map" to "external definition map" Reviewers: NoQ, dcoughlin, xazax.hun, george.karpenkov, martong Reviewed By: xazax.hun Subscribers: Charusso, baloghadamsoftware, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, george.karpenkov, mgorny, whisperity, szepet, rnkovacs, a.sidorin, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D46421 llvm-svn: 358968
* [analyzer] Unbreak body farms in presence of multiple declarations.Artem Dergachev2019-04-231-7/+14
| | | | | | | | | | | | | | When growing a body on a body farm, it's essential to use the same redeclaration of the function that's going to be used during analysis. Otherwise our ParmVarDecls won't match the ones that are used to identify argument regions. This boils down to trusting the reasoning in AnalysisDeclContext. We shouldn't canonicalize the declaration before farming the body because it makes us not obey the sophisticated decision-making process of AnalysisDeclContext. Differential Revision: https://reviews.llvm.org/D60899 llvm-svn: 358946
* [analyzer] PR41335: Fix crash when no-store event is in a body-farmed function.Artem Dergachev2019-04-231-0/+20
| | | | | | | | | | | Stuffing invalid source locations (such as those in functions produced by body farms) into path diagnostics causes crashes. Fix a typo in a nearby function name. Differential Revision: https://reviews.llvm.org/D60808 llvm-svn: 358945
* [analyzer] PR41269: Add a bit of C++ smart pointer modeling.Artem Dergachev2019-04-233-6/+39
| | | | | | | | | | | | | Implement cplusplus.SmartPtrModeling, a new checker that doesn't emit any warnings but models methods of smart pointers more precisely. For now the only thing it does is make `(bool) P` return false when `P` is a freshly moved pointer. This addresses a false positive in the use-after-move-checker. Differential Revision: https://reviews.llvm.org/D60796 llvm-svn: 358944
* [analyzer] Move UninitializedObjectChecker out of alphaKristof Umann2019-04-198-27/+27
| | | | | | | | | Moved UninitializedObjectChecker from the 'alpha.cplusplus' to the 'optin.cplusplus' package. Differential Revision: https://reviews.llvm.org/D58573 llvm-svn: 358797
* Reapply "[analyzer] Introduce a simplified API for adding custom path notes."Artem Dergachev2019-04-191-0/+8
| | | | | | | | This reapplies commit r357323, fixing memory leak found by LSan. Differential Revision: https://reviews.llvm.org/D58367 llvm-svn: 358781
* [analyzer][NFC] Reimplement checker optionsKristof Umann2019-04-192-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TL;DR: * Add checker and package options to the TableGen files * Added a new class called CmdLineOption, and both Package and Checker recieved a list<CmdLineOption> field. * Added every existing checker and package option to Checkers.td. * The CheckerRegistry class * Received some comments to most of it's inline classes * Received the CmdLineOption and PackageInfo inline classes, a list of CmdLineOption was added to CheckerInfo and PackageInfo * Added addCheckerOption and addPackageOption * Added a new field called Packages, used in addPackageOptions, filled up in addPackage Detailed description: In the last couple months, a lot of effort was put into tightening the analyzer's command line interface. The main issue is that it's spectacularly easy to mess up a lenghty enough invocation of the analyzer, and the user was given no warnings or errors at all in that case. We can divide the effort of resolving this into several chapters: * Non-checker analyzer configurations: Gather every analyzer configuration into a dedicated file. Emit errors for non-existent configurations or incorrect values. Be able to list these configurations. Tighten AnalyzerOptions interface to disallow making such a mistake in the future. * Fix the "Checker Naming Bug" by reimplementing checker dependencies: When cplusplus.InnerPointer was enabled, it implicitly registered unix.Malloc, which implicitly registered some sort of a modeling checker from the CStringChecker family. This resulted in all of these checker objects recieving the name "cplusplus.InnerPointer", making AnalyzerOptions asking for the wrong checker options from the command line: cplusplus.InnerPointer:Optimisic istead of unix.Malloc:Optimistic. This was resolved by making CheckerRegistry responsible for checker dependency handling, instead of checkers themselves. * Checker options: (this patch included!) Same as the first item, but for checkers. (+ minor fixes here and there, and everything else that is yet to come) There were several issues regarding checker options, that non-checker configurations didn't suffer from: checker plugins are loaded runtime, and they could add new checkers and new options, meaning that unlike for non-checker configurations, we can't collect every checker option purely by generating code. Also, as seen from the "Checker Naming Bug" issue raised above, they are very rarely used in practice, and all sorts of skeletons fell out of the closet while working on this project. They were extremely problematic for users as well, purely because of how long they were. Consider the following monster of a checker option: alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=false While we were able to verify whether the checker itself (the part before the colon) existed, any errors past that point were unreported, easily resulting in 7+ hours of analyses going to waste. This patch, similarly to how dependencies were reimplemented, uses TableGen to register checker options into Checkers.td, so that Checkers.inc now contains entries for both checker and package options. Using the preprocessor, Checkers.inc is converted into code in CheckerRegistry, adding every builtin (checkers and packages that have an entry in the Checkers.td file) checker and package option to the registry. The new addPackageOption and addCheckerOption functions expose the same functionality to statically-linked non-builtin and plugin checkers and packages as well. Emitting errors for incorrect user input, being able to list these options, and some other functionalies will land in later patches. Differential Revision: https://reviews.llvm.org/D57855 llvm-svn: 358752
* [analyzer] Fix an assertion failure if plugins added dependenciesKristof Umann2019-04-191-0/+17
| | | | | | | | | | | | | | | | | | | Ideally, there is no reason behind not being able to depend on checkers that come from a different plugin (or on builtin checkers) -- however, this is only possible if all checkers are added to the registry before resolving checker dependencies. Since I used a binary search in my addDependency method, this also resulted in an assertion failure (due to CheckerRegistry::Checkers not being sorted), since the function used by plugins to register their checkers (clang_registerCheckers) calls addDependency. This patch resolves this issue by only noting which dependencies have to established when addDependency is called, and resolves them at a later stage when no more checkers are added to the registry, by which point CheckerRegistry::Checkers is already sorted. Differential Revision: https://reviews.llvm.org/D59461 llvm-svn: 358750
* [analyzer] Make default bindings to variables actually work.Artem Dergachev2019-04-181-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Default RegionStore bindings represent values that can be obtained by loading from anywhere within the region, not just the specific offset within the region that they are said to be bound to. For example, default-binding a character \0 to an int (eg., via memset()) means that the whole int is 0, not just that its lower byte is 0. Even though memset and bzero were modeled this way, it didn't work correctly when applied to simple variables. Eg., in int x; memset(x, 0, sizeof(x)); we did produce a default binding, but were unable to read it later, and 'x' was perceived as an uninitialized variable even after memset. At the same time, if we replace 'x' with a variable of a structure or array type, accessing fields or elements of such variable was working correctly, which was enough for most cases. So this was only a problem for variables of simple integer/enumeration/floating-point/pointer types. Fix loading default bindings from RegionStore for regions of simple variables. Add a unit test to document the API contract as well. Differential Revision: https://reviews.llvm.org/D60742 llvm-svn: 358722
* [analyzer] NFC: MoveChecker: Refactor tests to use -verify=prefix.Artem Dergachev2019-04-181-432/+209
| | | | | | | | This -verify=prefix feature is quite underrated. Differential Revision: https://reviews.llvm.org/D60732 llvm-svn: 358719
* Fix test on PS4 which defaults to gnu99 which does not emit the expected ↵Douglas Yung2019-04-181-3/+15
| | | | | | warnings. llvm-svn: 358626
* [analyzer] PR41185: Fix regression where __builtin_* functions weren't ↵Kristof Umann2019-04-173-9/+49
| | | | | | | | | | | | | | | | | | | | | recognized For the following code snippet: void builtin_function_call_crash_fixes(char *c) { __builtin_strncpy(c, "", 6); __builtin_memset(c, '\0', (0)); __builtin_memcpy(c, c, 0); } security.insecureAPI.DeprecatedOrUnsafeBufferHandling caused a regression, as it didn't recognize functions starting with __builtin_. Fixed exactly that. I wanted to modify an existing test file, but the two I found didn't seem like perfect candidates. While I was there, I prettified their RUN: lines. Differential Revision: https://reviews.llvm.org/D59812 llvm-svn: 358609
* [analyzer] Escape pointers stored into top-level parameters with destructors.Artem Dergachev2019-04-131-0/+23
| | | | | | | | | | | | | | | | | | | | | | Writing stuff into an argument variable is usually equivalent to writing stuff to a local variable: it will have no effect outside of the function. There's an important exception from this rule: if the argument variable has a non-trivial destructor, the destructor would be invoked on the parent stack frame, exposing contents of the otherwise dead argument variable to the caller. If such argument is the last place where a pointer is stored before the function exits and the function is the one we've started our analysis from (i.e., we have no caller context for it), we currently diagnose a leak. This is incorrect because the destructor of the argument still has access to the pointer. The destructor may deallocate the pointer or even pass it further. Treat writes into such argument regions as "escapes" instead, suppressing spurious memory leak reports but not messing with dead symbol removal. Differential Revision: https://reviews.llvm.org/D60112 llvm-svn: 358321
* [analyzer] NoStoreFuncVisitor: Suppress reports with no-store in system headers.Artem Dergachev2019-04-052-0/+39
| | | | | | | | | | | | | | | | | The idea behind this heuristic is that normally the visitor is there to inform the user that a certain function may fail to initialize a certain out-parameter. For system header functions this is usually dictated by the contract, and it's unlikely that the header function has accidentally forgot to put the value into the out-parameter; it's more likely that the user has intentionally skipped the error check. Warnings on skipped error checks are more like security warnings; they aren't necessarily useful for all users, and they should instead be introduced on a per-API basis. Differential Revision: https://reviews.llvm.org/D60107 llvm-svn: 357810
* Revert "[analyzer] Toning down invalidation a bit".Artem Dergachev2019-04-035-10/+23
| | | | | | | | | | | | | | | This reverts commit r352473. The overall idea is great, but it seems to cause unintented consequences when not only Region Store invalidation but also pointer escape mechanism was accidentally affected. Based on discussions in https://reviews.llvm.org/D58121#1452483 and https://reviews.llvm.org/D57230#1434161 Differential Revision: https://reviews.llvm.org/D57230 llvm-svn: 357620
* Fix typos in tests. NFC.Xing GUO2019-04-031-1/+1
| | | | | | | | | | | | | | Reviewers: Higuoxing Reviewed By: Higuoxing Subscribers: kubamracek, cfe-commits, #sanitizers, llvm-commits Tags: #clang, #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D60183 llvm-svn: 357577
* [analyzer] When failing to evaluate a __builtin_constant_p, presume it's false.Artem Dergachev2019-04-031-4/+5
| | | | | | | | | | | | | | | | | | | | | __builtin_constant_p(x) is a compiler builtin that evaluates to 1 when its argument x is a compile-time constant and to 0 otherwise. In CodeGen it is simply lowered to the respective LLVM intrinsic. In the Analyzer we've been trying to delegate modeling to Expr::EvaluateAsInt, which is allowed to sometimes fail for no apparent reason. When it fails, let's conservatively return false. Modeling it as false is pretty much never wrong, and it is only required to return true on a best-effort basis, which every user should expect. Fixes VLAChecker false positives on code that tries to emulate static asserts in C by constructing a VLA of dynamic size -1 under the assumption that this dynamic size is actually a constant in the sense of __builtin_constant_p. Differential Revision: https://reviews.llvm.org/D60110 llvm-svn: 357557
* [analyzer] MIGChecker: Add support for more deallocator APIs.Artem Dergachev2019-03-291-3/+25
| | | | | | Differential Revision: https://reviews.llvm.org/D59914 llvm-svn: 357335
* Revert "[analyzer] Introduce a simplified API for adding custom path notes."Artem Dergachev2019-03-291-8/+0
| | | | | | | | | | This reverts commit r357323. ASan leaks found by a buildbot :) Differential Revision: https://reviews.llvm.org/D58367 llvm-svn: 357332
* [analyzer] PR41239: Fix a crash on invalid source location in ↵Artem Dergachev2019-03-291-1/+11
| | | | | | | | | | | | | | | | | NoStoreFuncVisitor. It turns out that SourceManager::isInSystemHeader() crashes when an invalid source location is passed into it. Invalid source locations are relatively common: not only they come from body farms, but also, say, any function in C that didn't come with a forward declaration would have an implicit forward declaration with invalid source locations. There's a more comfy API for us to use in the Static Analyzer: CallEvent::isInSystemHeader(), so just use that. Differential Revision: https://reviews.llvm.org/D59901 llvm-svn: 357329
* [analyzer] Move taint API from ProgramState to a separate header. NFC.Artem Dergachev2019-03-291-0/+14
| | | | | | | | | | It is now an inter-checker communication API, similar to the one that connects MallocChecker/CStringChecker/InnerPointerChecker: simply a set of setters and getters for a state trait. Differential Revision: https://reviews.llvm.org/D59861 llvm-svn: 357326
* [analyzer] PR37501: Disable assertion for logical op short circuit evaluation.Artem Dergachev2019-03-291-2/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The transfer function for the CFG element that represents a logical operation computes the value of the operation and does nothing else. The element appears after all the short circuit decisions were made, so they don't need to be made again at this point. Because our expression evaluation is imprecise, it is often hard to discriminate between: (1) we don't know the value of the RHS because we failed to evaluate it and (2) we don't know the value of the RHS because it didn't need to be evaluated. This is hard because it depends on our knowledge about the value of the LHS (eg., if LHS is true, then RHS in (LHS || RHS) doesn't need to be computed) but LHS itself may have been evaluated imprecisely and we don't know whether it is true or not. Additionally, the Analyzer wouldn't necessarily even remember what the value of the LHS was because theoretically it's not really necessary to know it for any future evaluations. In order to work around these issues, the transfer function for logical operations consists in looking at the ExplodedGraph we've constructed so far in order to figure out from which CFG direction did we arrive here. Such post-factum backtracking that doesn't involve looking up LHS and RHS values is usually possible. However sometimes it fails because when we deduplicate exploded nodes with the same program point and the same program state we may end up in a situation when we reached the same program point from two or more different directions. By removing the assertion, we admit that the procedure indeed sometimes fails to work. When it fails, we also admit that we don't know the value of the logical operator. Differential Revision: https://reviews.llvm.org/D59857 llvm-svn: 357325
* [analyzer] Introduce a simplified API for adding custom path notes.Artem Dergachev2019-03-291-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Almost all path-sensitive checkers need to tell the user when something specific to that checker happens along the execution path but does not constitute a bug on its own. For instance, a call to operator delete in C++ has consequences that are specific to a use-after-free bug. Deleting an object is not a bug on its own, but when the Analyzer finds an execution path on which a deleted object is used, it'll have to explain to the user when exactly during that path did the deallocation take place. Historically such custom notes were added by implementing "bug report visitors". These visitors were post-processing bug reports by visiting every ExplodedNode along the path and emitting path notes whenever they noticed that a change that is relevant to a bug report occurs within the program state. For example, it emits a "memory is deallocated" note when it notices that a pointer changes its state from "allocated" to "deleted". The "visitor" approach is powerful and efficient but hard to use because such preprocessing implies that the developer first models the effects of the event (say, changes the pointer's state from "allocated" to "deleted" as part of operator delete()'s transfer function) and then forgets what happened and later tries to reverse-engineer itself and figure out what did it do by looking at the report. The proposed approach tries to avoid discarding the information that was available when the transfer function was evaluated. Instead, it allows the developer to capture all the necessary information into a closure that will be automatically invoked later in order to produce the actual note. This should reduce boilerplate and avoid very painful logic duplication. On the technical side, the closure is a lambda that's put into a special kind of a program point tag, and a special bug report visitor visits all nodes in the report and invokes all note-producing closures it finds along the path. For now it is up to the lambda to make sure that the note is actually relevant to the report. For instance, a memory deallocation note would be irrelevant when we're reporting a division by zero bug or if we're reporting a use-after-free of a different, unrelated chunk of memory. The lambda can figure these thing out by looking at the bug report object that's passed into it. A single checker is refactored to make use of the new functionality: MIGChecker. Its program state is trivial, making it an easy testing ground for the first version of the API. Differential Revision: https://reviews.llvm.org/D58367 llvm-svn: 357323
* [Analyzer] Constraint Manager - Calculate Effective Range for DifferencesAdam Balogh2019-03-281-0/+14
| | | | | | | | | | | | | | | | | | | | | Since rL335814, if the constraint manager cannot find a range set for `A - B` (where `A` and `B` are symbols) it looks for a range for `B - A` and returns it negated if it exists. However, if a range set for both `A - B` and `B - A` is stored then it only returns the first one. If we both use `A - B` and `B - A`, these expressions behave as two totally unrelated symbols. This way we miss some useful deductions which may lead to false negatives or false positives. This tiny patch changes this behavior: if the symbolic expression the constraint manager is looking for is a difference `A - B`, it tries to retrieve the range for both `A - B` and `B - A` and if both exists it returns the intersection of range `A - B` and the negated range of `B - A`. This way every time a checker applies new constraints to the symbolic difference or to its negated it always affects both the original difference and its negated. Differential Revision: https://reviews.llvm.org/D55007 llvm-svn: 357167
* [CFG] [analyzer] pr41142: C++17: Skip transparent InitListExprs in ExprEngine.Artem Dergachev2019-03-261-5/+19
| | | | | | | | | | | | | | | | | | | r356634 didn't fix all the problems caused by r356222 - even though simple constructors involving transparent init-list expressions are now evaluated precisely, many more complicated constructors aren't, for other reasons. The attached test case is an example of a constructor that will never be evaluated precisely - simply because there isn't a constructor there (instead, the program invokes run-time undefined behavior by returning without a return statement that should have constructed the return value). Fix another part of the problem for such situations: evaluate transparent init-list expressions transparently, so that to avoid creating ill-formed "transparent" nonloc::CompoundVals. Differential Revision: https://reviews.llvm.org/D59622 llvm-svn: 356969
* [CFG] [analyzer] pr41142: C++17: Skip transparent InitListExprs in constructors.Artem Dergachev2019-03-212-0/+38
| | | | | | | | | | | | | | When searching for construction contexts, i.e. figuring out which statements define the object that is constructed by each construct-expression, ignore transparent init-list expressions because they don't add anything to the context. This allows the Static Analyzer to model construction, destruction, materialization, lifetime extension correctly in more cases. Also fixes a crash caused by incorrectly evaluating initial values of variables initialized with such expressions. Differential Revision: https://reviews.llvm.org/D59573 llvm-svn: 356634
* [Sema] Add some compile time _FORTIFY_SOURCE diagnosticsErik Pilkington2019-03-184-7/+22
| | | | | | | | | | | | | | | | | | | | | | | These diagnose overflowing calls to subset of fortifiable functions. Some functions, like sprintf or strcpy aren't supported right not, but we should probably support these in the future. We previously supported this kind of functionality with -Wbuiltin-memcpy-chk-size, but that diagnostic doesn't work with _FORTIFY implementations that use wrapper functions. Also unlike that diagnostic, we emit these warnings regardless of whether _FORTIFY_SOURCE is actually enabled, which is nice for programs that don't enable the runtime checks. Why not just use diagnose_if, like Bionic does? We can get better diagnostics in the compiler (i.e. mention the sizes), and we have the potential to diagnose sprintf and strcpy which is impossible with diagnose_if (at least, in languages that don't support C++14 constexpr). This approach also saves standard libraries from having to add diagnose_if. rdar://48006655 Differential revision: https://reviews.llvm.org/D58797 llvm-svn: 356397
OpenPOWER on IntegriCloud