summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis
Commit message (Collapse)AuthorAgeFilesLines
* [AST] Inline CompoundStmt contents into the parent allocation.Benjamin Kramer2017-12-241-1/+1
| | | | | | Saves a pointer on every CompoundStmt. llvm-svn: 321429
* Refactor overridden methods iteration to avoid double lookups.Benjamin Kramer2017-12-171-4/+4
| | | | | | Convert most uses to range-for loops. No functionality change intended. llvm-svn: 320954
* [c++20] P0515R3: Parsing support and basic AST construction for operator <=>.Richard Smith2017-12-142-0/+2
| | | | | | | | | | | | | | | Adding the new enumerator forced a bunch more changes into this patch than I would have liked. The -Wtautological-compare warning was extended to properly check the new comparison operator, clang-format needed updating because it uses precedence levels as weights for determining where to break lines (and several operators increased their precedence levels with this change), thread-safety analysis needed changes to build its own IL properly for the new operator. All "real" semantic checking for this operator has been deferred to a future patch. For now, we use the relational comparison rules and arbitrarily give the builtin form of the operator a return type of 'void'. llvm-svn: 320707
* [Analysis] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko2017-12-072-142/+177
| | | | | | other minor fixes (NFC). llvm-svn: 320091
* [analyzer] Teach RetainCountChecker about CoreMedia APIsDevin Coughlin2017-11-251-3/+10
| | | | | | | | | | Teach the retain-count checker that CoreMedia reference types use CoreFoundation-style reference counting. This enables the checker to catch leaks and over releases of those types. rdar://problem/33599757 llvm-svn: 318979
* [Analyzer] Stable iteration on indirect goto LabelDecl's to avoid ↵Aleksei Sidorin2017-11-211-1/+1
| | | | | | | | | | | | | | | | | | | | non-determinism (attempt 2) CFG wass built in non-deterministic order due to the fact that indirect goto labels' declarations (LabelDecl's) are stored in the llvm::SmallSet container. LabelDecl's are pointers, whose order is not deterministic, and llvm::SmallSet sorts them by their non-deterministic addresses after "small" container is exceeded. This leads to non-deterministic processing of the elements of the container. The fix is to use llvm::SmallSetVector that was designed to have deterministic iteration order. Patch by Ilya Palachev! Differential Revision: https://reviews.llvm.org/D40073 llvm-svn: 318754
* [analyzer] Model correct dispatch_once() 'done' value in BodyFarmDevin Coughlin2017-11-061-21/+16
| | | | | | | | | | | | | | | | | | | | | | | The analyzer's BodyFarm models dispatch_once() by comparing the passed-in predicate against a known 'done' value. If the predicate does not have that value, the model updates the predicate to have that value and executes the passed in block. Unfortunately, the current model uses the wrong 'done' value: 1 instead of ~0. This interferes with libdispatch's static inline function _dispatch_once(), which enables a fast path if the block has already been executed. That function uses __builtin_assume() to tell the compiler that the done flag is set to ~0 on exit. When r302880 added modeling of __builtin_assume(), this caused the analyzer to assume 1 == ~0. This in turn caused the analyzer to never explore any code after a call to dispatch_once(). This patch regains the missing coverage by updating BodyFarm to use the correct 'done' value. rdar://problem/34413048 Differential Revision: https://reviews.llvm.org/D39691 llvm-svn: 317516
* [analyzer] do not crash on libcxx03 call_once implementationGeorge Karpenkov2017-11-031-8/+16
| | | | | | | | Addresses https://bugs.llvm.org/show_bug.cgi?id=35075, rdar://35230961 Differential Revision: https://reviews.llvm.org/D39518 llvm-svn: 317293
* [analyzer] Removing unused stored field.George Karpenkov2017-11-011-1/+1
| | | | llvm-svn: 317070
* [Analyzer] Use value storage for BodyFarmGeorge Karpenkov2017-11-011-8/+5
| | | | | | Differential Revision: https://reviews.llvm.org/D39428 llvm-svn: 317065
* [Analyzer] Give more descriptive name to BdyFrm field.George Karpenkov2017-10-251-3/+3
| | | | | | Discussion at: https://reviews.llvm.org/D39220 llvm-svn: 316617
* [Analyzer] Remove spaces inside comments mentioning the parameter name,George Karpenkov2017-10-251-34/+34
| | | | | | | to aid clang-tidy comprehension. Requested by @alexfh in https://reviews.llvm.org/D39015 llvm-svn: 316539
* [Analyzer] Store BodyFarm in std::unique_ptrGeorge Karpenkov2017-10-241-7/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D39220 llvm-svn: 316536
* [Analyzer] Fix for the memory leak: fix typo in if-statement.George Karpenkov2017-10-241-1/+1
| | | | llvm-svn: 316403
* [Analyzer] Handle implicit function reference in bodyfarming std::call_onceGeorge Karpenkov2017-10-241-8/+20
| | | | | | Differential Revision: https://reviews.llvm.org/D39201 llvm-svn: 316402
* [Analyzer] Do not use static storage to for implementations created in ↵George Karpenkov2017-10-233-75/+20
| | | | | | | | BodyFarm.cpp Differential Revision: https://reviews.llvm.org/D39208 llvm-svn: 316400
* [Analyzer] Correctly handle parameters passed by reference when bodyfarming ↵George Karpenkov2017-10-201-14/+44
| | | | | | | | | | std::call_once Explicitly not supporting functor objects. Differential Revision: https://reviews.llvm.org/D39031 llvm-svn: 316249
* [Analyzer] Always use non-reference types when creating expressions in BodyFarm.George Karpenkov2017-10-171-22/+14
| | | | | | | | | | | | | | Remove an option to use a reference type (on by default!) since a non-reference type is always needed for creating expressions, functions with multiple boolean parameters are very hard to use, and in general it was just a booby trap for further crashes. Furthermore, generalize call_once test case to fix some of the crashes mentioned https://bugs.llvm.org/show_bug.cgi?id=34869 Also removes std::call_once crash. Differential Revision: https://reviews.llvm.org/D39015 llvm-svn: 316041
* [Analyzer] Support bodyfarming libstdc++ implementation of std::call_once.George Karpenkov2017-10-111-19/+25
| | | | | | Differential Revision: https://reviews.llvm.org/D38810 llvm-svn: 315508
* [Analyzer] Do not segfault on unexpected call_once implementationGeorge Karpenkov2017-10-091-16/+22
| | | | | | | | Fixes https://bugs.llvm.org/show_bug.cgi?id=34869 Differential Revision: https://reviews.llvm.org/D38702 llvm-svn: 315250
* [Analyzer] Avoid copy and modifying passed reference in ↵George Karpenkov2017-10-021-16/+18
| | | | | | | | BodyFarm::create_call_once Differential Revision: https://reviews.llvm.org/D38475 llvm-svn: 314722
* [Analysis] Remove unused makeLvalueToRValue variant.Davide Italiano2017-09-301-13/+0
| | | | llvm-svn: 314605
* [Analyzer] Synthesize function body for std::call_onceGeorge Karpenkov2017-09-301-28/+288
| | | | | | Differential Revision: https://reviews.llvm.org/D37840 llvm-svn: 314571
* [clang] Add getUnsignedPointerDiffType methodAlexander Shaposhnikov2017-09-282-5/+3
| | | | | | | | | | | | | | | | | C11 standard refers to the unsigned counterpart of the type ptrdiff_t in the paragraph 7.21.6.1p7 where it defines the format specifier %tu. In Clang (in PrintfFormatString.cpp, lines 508-510) there is a FIXME for this case, in particular, Clang didn't diagnose %tu issues at all, i.e. it didn't emit any warnings on the code printf("%tu", 3.14). In this diff we add a method getUnsignedPointerDiffType for getting the corresponding type similarly to how it's already done in the other analogous cases (size_t, ssize_t, ptrdiff_t etc) and fix -Wformat diagnostics for %tu plus the emitted fix-it as well. Test plan: make check-all Differential revision: https://reviews.llvm.org/D38270 llvm-svn: 314470
* Consolidate std::move() detection code. No behavior change.Nico Weber2017-09-282-12/+6
| | | | llvm-svn: 314427
* Recommit "Add _Float16 as a C/C++ source language type"Sjoerd Meijer2017-09-081-0/+1
| | | | | | | | This is a recommit of r312781; in some build configurations variable names are omitted, so changed the new regression test accordingly. llvm-svn: 312794
* Revert "Add _Float16 as a C/C++ source language type"Sjoerd Meijer2017-09-081-1/+0
| | | | | | | The clang-with-lto-ubuntu bot didn't like the new regression test, revert while I investigate the issue. llvm-svn: 312784
* Add _Float16 as a C/C++ source language typeSjoerd Meijer2017-09-081-0/+1
| | | | | | | | | | | This adds _Float16 as a source language type, which is a 16-bit floating point type defined in C11 extension ISO/IEC TS 18661-3. In follow up patches documentation and more tests will be added. Differential Revision: https://reviews.llvm.org/D33719 llvm-svn: 312781
* [CSA] [NFC] Move AnalysisContext.h to AnalysisDeclContext.hGeorge Karpenkov2017-09-067-7/+7
| | | | | | | | | | | | | | The implementation is in AnalysisDeclContext.cpp and the class is called AnalysisDeclContext. Making those match up has numerous benefits, including: - Easier jump from header to/from implementation. - Easily identify filename from class. Differential Revision: https://reviews.llvm.org/D37500 llvm-svn: 312671
* [AST] Add TableGen for StmtDataCollectorsJohannes Altmanninger2017-09-061-1/+1
| | | | | | | | | | | | | | Summary: This adds an option "-gen-clang-data-collectors" to the Clang TableGen that is used to generate StmtDataCollectors.inc. Reviewers: arphaman, teemperor! Subscribers: mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D37383 llvm-svn: 312634
* [analyzer] MinComplexityConstraint now early exits and only does one macro ↵Raphael Isemann2017-09-031-8/+10
| | | | | | | | | | | | | | | | | | | | | stack lookup Summary: This patch contains performance improvements for the `MinComplexityConstraint`. It reduces the constraint time when running on the SQLite codebase by around 43% (from 0.085s down to 0.049s). The patch is essentially doing two things: * It introduces a possibility for the complexity value to early exit when reaching the limit we were checking for. This means that once we noticed that the current clone is larger than the limit the user has set, we instantly exit and no longer traverse the tree or do further expensive lookups in the macro stack. * It also removes half of the macro stack lookups we do so far. Previously we always checked the start and the end location of a Stmt for macros, which was only a middle way between checking all locations of the Stmt and just checking one location. In practice I rarely found cases where it really matters if we check start/end or just the start of a statement as code with lots of macros that somehow just produce half a statement are very rare. Reviewers: NoQ Subscribers: cfe-commits, xazax.hun, v.g.vassilev Differential Revision: https://reviews.llvm.org/D34361 llvm-svn: 312440
* std::function -> llvm::function_ref. NFC.Benjamin Kramer2017-09-011-1/+2
| | | | llvm-svn: 312336
* [analyzer] Performance optimizations for the CloneCheckerRaphael Isemann2017-08-311-6/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch aims at optimizing the CloneChecker for larger programs. Before this patch we took around 102 seconds to analyze sqlite3 with a complexity value of 50. After this patch we now take 2.1 seconds to analyze sqlite3. The biggest performance optimization is that we now put the constraint for group size before the constraint for the complexity. The group size constraint is much faster in comparison to the complexity constraint as it only does a simple integer comparison. The complexity constraint on the other hand actually traverses each Stmt and even checks the macro stack, so it is obviously not able to handle larger amounts of incoming clones. The new order filters out all the single-clone groups that the type II constraint generates in a faster way before passing the fewer remaining clones to the complexity constraint. This reduced runtime by around 95%. The other change is that we also delay the verification part of the type II clones back in the chain of constraints. This required to split up the constraint into two parts - a verification and a hash constraint (which is also making it more similar to the original design of the clone detection algorithm). The reasoning for this is the same as before: The verification constraint has to traverse many statements and shouldn't be at the start of the constraint chain. However, as the type II hashing has to be the first step in our algorithm, we have no other choice but split this constrain into two different ones. Now our group size and complexity constrains filter out a chunk of the clones before they reach the slow verification step, which reduces the runtime by around 8%. I also kept the full type II constraint around - that now just calls it's two sub-constraints - in case someone doesn't care about the performance benefits of doing this. Reviewers: NoQ Reviewed By: NoQ Subscribers: klimek, v.g.vassilev, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34182 llvm-svn: 312222
* [analyzer] Make StmtDataCollector customizableJohannes Altmanninger2017-08-231-44/+68
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This moves the data collection macro calls for Stmt nodes to lib/AST/StmtDataCollectors.inc Users can subclass ConstStmtVisitor and include StmtDataCollectors.inc to define visitor methods for each Stmt subclass. This makes it also possible to customize the visit methods as exemplified in lib/Analysis/CloneDetection.cpp. Move helper methods for data collection to a new module, AST/DataCollection. Add data collection for DeclRefExpr, MemberExpr and some literals. Reviewers: arphaman, teemperor! Subscribers: mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36664 llvm-svn: 311569
* Implement CFG construction for __try / __except / __leave.Nico Weber2017-08-231-10/+148
| | | | | | | | | | | | | | | | | | | | | | | This makes -Wunreachable-code work for programs containing SEH (except for __finally, which is still missing for now). __try is modeled like try (but simpler since it can only have a single __except or __finally), __except is fairly similar to catch (but simpler, since it can't contain declarations). __leave is implemented similarly to break / continue. Use the existing addTryDispatchBlock infrastructure (which FindUnreachableCode() in ReachableCode.cpp uses via cfg->try_blocks_begin()) to mark things in the __except blocks as reachable. Re-use TryTerminatedBlock. This means we add EH edges from calls to the __try block, but not from all other statements. While this is incomplete, it matches LLVM's SEH codegen support. Also, in practice, BuildOpts.AddEHEdges is always false in practice from what I can tell, so we never even insert the call EH edges either. https://reviews.llvm.org/D36914 llvm-svn: 311561
* [CFG] Add LoopExit information to CFGPeter Szecsi2017-08-192-0/+26
| | | | | | | | | | | | | | | | This patch introduces a new CFG element CFGLoopExit that indicate when a loop ends. It does not deal with returnStmts yet (left it as a TODO). It hidden behind a new analyzer-config flag called cfg-loopexit (false by default). Test cases added. The main purpose of this patch right know is to make loop unrolling and loop widening easier and more efficient. However, this information can be useful for future improvements in the StaticAnalyzer core too. Differential Revision: https://reviews.llvm.org/D35668 llvm-svn: 311235
* Reland "Thread Safety Analysis: fix assert_capability."Josh Gao2017-08-081-2/+17
| | | | | | | | | | | Delete the test that was broken by rL309725, and add it back in a follow up commit. Also, improve the tests a bit. Reviewers: delesley, aaron.ballman Differential Revision: https://reviews.llvm.org/D36237 llvm-svn: 310402
* Revert "Thread Safety Analysis: fix assert_capability."Josh Gao2017-08-011-17/+2
| | | | | | | | This reverts commit rL309725. Broke test/Sema/attr-capabilities.c. llvm-svn: 309731
* Thread Safety Analysis: fix assert_capability.Josh Gao2017-08-011-2/+17
| | | | | | | | | | | | | | | | Summary: Previously, the assert_capability attribute was completely ignored by thread safety analysis. Reviewers: delesley, rnk Reviewed By: delesley Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36122 llvm-svn: 309725
* [clang] Fix handling of "%zd" in scanfAlexander Shaposhnikov2017-07-201-3/+2
| | | | | | | | | | | | | This diff addresses FIXMEs in lib/Analysis/ScanfFormatString.cpp for the case of ssize_t format specifier and adds tests. In particular, this change enables Clang to emit a warning on incorrect using of "%zd"/"%zn". Test plan: make check-all Differential revision: https://reviews.llvm.org/D35652 llvm-svn: 308662
* [clang] Fix handling of "%zd" format specifierAlexander Shaposhnikov2017-07-141-3/+2
| | | | | | | | | | | | | This diff addresses FIXME in lib/Analysis/PrintfFormatString.cpp and makes PrintfSpecifier::getArgType return the correct type. In particular, this change enables Clang to emit a warning on incorrect using of "%zd"/"%zn" format specifiers. Differential revision: https://reviews.llvm.org/D35427 Test plan: make check-all llvm-svn: 308067
* CFG: Add CFGElement for automatic variables that leave the scopeMatthias Gehre2017-07-122-45/+181
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This mimics the implementation for the implicit destructors. The generation of this scope leaving elements is hidden behind a flag to the CFGBuilder, thus it should not affect existing code. Currently, I'm missing a test (it's implicitly tested by the clang-tidy lifetime checker that I'm proposing). I though about a test using debug.DumpCFG, but then I would have to add an option to StaticAnalyzer/Core/AnalyzerOptions to enable the scope leaving CFGElement, which would only be useful to that particular test. Any other ideas how I could make a test for this feature? Reviewers: krememek, jordan_rose Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15031 llvm-svn: 307759
* [analyzer] Faster hashing of subsequences in CompoundStmts.Raphael Isemann2017-07-091-9/+20
| | | | | | | | | | | | | | Summary: This patches improves the hashing subsequences in CompoundStmts by incrementally hashing all subsequences with the same starting position. This results in a reduction of the time for this constraint while running over SQLite from 1.10 seconds to 0.55 seconds (-50%). Reviewers: NoQ Reviewed By: NoQ Subscribers: cfe-commits, xazax.hun, v.g.vassilev Differential Revision: https://reviews.llvm.org/D34364 llvm-svn: 307509
* [analyzer] Make StmtDataCollector part of the CloneDetection APIRaphael Isemann2017-07-091-185/+3
| | | | | | | | | | | | | | Summary: We probably want to use this useful templates in other pieces of code (e.g. the one from D34329), so we should make this public. Reviewers: NoQ Reviewed By: NoQ Subscribers: cfe-commits, xazax.hun, v.g.vassilev, johannes Differential Revision: https://reviews.llvm.org/D34880 llvm-svn: 307501
* Changed wording in commentRaphael Isemann2017-06-211-2/+1
| | | | llvm-svn: 305878
* [analyzer] Teach CloneDetection about Qt Meta-Object Compiler to filter auto ↵Leslie Zhai2017-06-201-1/+1
| | | | | | | | | | | | generated files Reviewers: v.g.vassilev, teemperor Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D34353 llvm-svn: 305774
* [analyzer] Teach CloneDetection about Qt Meta-Object CompilerLeslie Zhai2017-06-191-1/+18
| | | | | | | | | | Reviewers: v.g.vassilev, zaks.anna, NoQ, teemperor Reviewed By: v.g.vassilev, zaks.anna, NoQ, teemperor Differential Revision: https://reviews.llvm.org/D31320 llvm-svn: 305659
* Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova2017-06-033-0/+4
| | | | llvm-svn: 304641
* [coroutines] Fix fallthrough diagnostics for coroutinesEric Fiselier2017-05-251-0/+2
| | | | | | | | | | | | | | | | | | | | Summary: This patch fixes a number of issues with the analysis warnings emitted when a coroutine may reach the end of the function w/o returning. * Fix bug where coroutines with `return_value` are incorrectly diagnosed as missing `co_return`'s. * Rework diagnostic message to no longer say "non-void coroutine", because that implies the coroutine doesn't have a void return type, which it might. In this case a non-void coroutine is one who's promise type does not contain `return_void()` As a side-effect of this patch, coroutine bodies that contain an invalid coroutine promise objects are marked as invalid. Reviewers: GorNishanov, rsmith, aaron.ballman, majnemer Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33532 llvm-svn: 303831
* Fix PR13910: Don't warn that __builtin_unreachable() is unreachableAlex Lorenz2017-04-111-2/+9
| | | | | | Differential Revision: https://reviews.llvm.org/D25321 llvm-svn: 299951
OpenPOWER on IntegriCloud