summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/ReachableCode.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Avoid including Builtins.h in Preprocessor.hReid Kleckner2019-11-151-0/+1
| | | | | | Builtins are rarely if ever accessed via the Preprocessor. They are typically found on the ASTContext, so there should be no performance penalty to using a pointer indirection to store the builtin context.
* Improve -Wtautological-overlap-compareRichard Trieu2019-09-211-1/+1
| | | | | | | | | Allow this warning to detect a larger number of constant values, including negative numbers, and handle non-int types better. Differential Revision: https://reviews.llvm.org/D66044 llvm-svn: 372448
* [CFG] NFC: Remove implicit conversion from CFGTerminator to Stmt *.Artem Dergachev2019-05-241-9/+8
| | | | | | | | | | | Turn it into a variant class instead. This conversion does indeed save some code but there's a plan to add support for more kinds of terminators that aren't necessarily based on statements, and with those in mind it becomes more and more confusing to have CFGTerminators implicitly convertible to a Stmt *. Differential Revision: https://reviews.llvm.org/D61814 llvm-svn: 361586
* Fix file headers. NFCFangrui Song2019-03-011-1/+1
| | | | llvm-svn: 355176
* Revert "[Analysis] -Wunreachable-code shouldn't fire on the increment of a ↵Sam McCall2019-02-151-4/+0
| | | | | | | | foreach loop" This reverts commit r354102. llvm-svn: 354109
* [Analysis] -Wunreachable-code shouldn't fire on the increment of a foreach loopSam McCall2019-02-151-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The idea is that the code here isn't written, so doesn't indicate a bug. Similar to code expanded from macros. This means the warning no longer fires on this code: for (auto C : collection) { process(C); return; } handleEmptyCollection(); Unclear whether this is more often a bug or not in practice, I think it's a reasonable idiom in some cases. Either way, if we want to warn on "loop that doesn't loop", I think it should be a separate warning, and catch `while(1) break;` Reviewers: ilya-biryukov, ioeric Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58134 llvm-svn: 354102
* [AST] Update the comments of the various Expr::Ignore* + Related cleanupsBruno Ricci2019-02-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The description of what the various Expr::Ignore* do has drifted from the actual implementation. Inspection reveals that IgnoreParenImpCasts() is not equivalent to doing IgnoreParens() + IgnoreImpCasts() until reaching a fixed point, but IgnoreParenCasts() is equivalent to doing IgnoreParens() + IgnoreCasts() until reaching a fixed point. There is also a fair amount of duplication in the various Expr::Ignore* functions which increase the chance of further future inconsistencies. In preparation for the next patch which will factor out the implementation of the various Expr::Ignore*, do the following cleanups: Remove Stmt::IgnoreImplicit, in favor of Expr::IgnoreImplicit. IgnoreImplicit is the only function among all of the Expr::Ignore* which is available in Stmt. There are only a few users of Stmt::IgnoreImplicit. They can just use instead Expr::IgnoreImplicit like they have to do for the other Ignore*. Move Expr::IgnoreImpCasts() from Expr.h to Expr.cpp. This made no difference in the run-time with my usual benchmark (-fsyntax-only on all of Boost). While we are at it, make IgnoreParenNoopCasts take a const reference to the ASTContext for const correctness. Update the comments to match what the Expr::Ignore* are actually doing. I am not sure that listing exactly what each Expr::Ignore* do is optimal, but it certainly looks better than the current state which is in my opinion between misleading and just plain wrong. The whole patch is NFC (if you count removing Stmt::IgnoreImplicit as NFC). Differential Revision: https://reviews.llvm.org/D57266 Reviewed By: aaron.ballman llvm-svn: 353006
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Fix clang -Wimplicit-fallthrough warnings across llvm, NFCReid Kleckner2018-11-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch should not introduce any behavior changes. It consists of mostly one of two changes: 1. Replacing fall through comments with the LLVM_FALLTHROUGH macro 2. Inserting 'break' before falling through into a case block consisting of only 'break'. We were already using this warning with GCC, but its warning behaves slightly differently. In this patch, the following differences are relevant: 1. GCC recognizes comments that say "fall through" as annotations, clang doesn't 2. GCC doesn't warn on "case N: foo(); default: break;", clang does 3. GCC doesn't warn when the case contains a switch, but falls through the outer case. I will enable the warning separately in a follow-up patch so that it can be cleanly reverted if necessary. Reviewers: alexfh, rsmith, lattner, rtrieu, EricWF, bollu Differential Revision: https://reviews.llvm.org/D53950 llvm-svn: 345882
* Port getLocStart -> getBeginLocStephen Kelly2018-08-091-10/+10
| | | | | | | | | | Reviewers: teemperor! Subscribers: jholewinski, whisperity, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50350 llvm-svn: 339385
* Remove trailing spaceFangrui Song2018-07-301-11/+11
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* Teach Wreturn-type, Wunreachable-code, and alpha.deadcode.UnreachableCode to ↵Nico Weber2018-02-131-4/+21
| | | | | | | | | treat __assume(0) like __builtin_unreachable. Fixes PR29134. https://reviews.llvm.org/D43221 llvm-svn: 325052
* [CSA] [NFC] Move AnalysisContext.h to AnalysisDeclContext.hGeorge Karpenkov2017-09-061-1/+1
| | | | | | | | | | | | | | 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
* 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
* -Wunreachable-code: 'true' and 'false' should not be treated as configurationAlex Lorenz2017-04-051-1/+7
| | | | | | | | | macros Clang should emit -Wunreachable-code warnings in C mode for code that's unreachable because of a 'false' or '!true' condition. llvm-svn: 299541
* Avoid multiple -Wunreachable-code diagnostics that are triggered byAlex Lorenz2017-01-121-5/+15
| | | | | | | | | | | the same source range and use the unary operator fixit only when it actually silences the warning. rdar://24570531 Differential Revision: https://reviews.llvm.org/D28231 llvm-svn: 291757
* [ReachableCode] Skip over ExprWithCleanups in isConfigurationValueTim Shen2016-11-011-0/+2
| | | | | | | | | | | | Summary: Fixes pr29152. Reviewers: rsmith, pirama, krememek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24010 llvm-svn: 285657
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-3/+2
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-2/+3
| | | | | | | | | | | | 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
* [cleanup] Re-sort *all* #include lines with llvm/utils/sort_includes.pyChandler Carruth2015-01-141-2/+2
| | | | | | | | | | Sorry for the noise, I managed to miss a bunch of recent regressions of include orderings here. This should actually sort all the includes for Clang. Again, no functionality changed, this is just a mechanical cleanup that I try to run periodically to keep the #include lines as regular as possible across the project. llvm-svn: 225979
* Make dead return statement detection more robust against changes in the CFG.Manuel Klimek2014-05-231-21/+46
| | | | | | | | | | | | This change is a precondition to the proposed change to handle temporary dtors correctly. The idea is to explicitly search for the next return that doesn't have other paths into it (that is, if the current block is dead, the block containing the return must be dead, too). Thus, introducing non-control-flow block transitions will not break the logic. llvm-svn: 209531
* [C++11] Use 'nullptr'. Analysis edition.Craig Topper2014-05-201-2/+2
| | | | llvm-svn: 209191
* -Wunreachable-code: refine recognition of unreachable "sigil" to cope with ↵Ted Kremenek2014-04-161-1/+4
| | | | | | | | implicit casts in C++. Fixes <rdar://problem/16631033>. llvm-svn: 206360
* [-Wunreachable-code] Expand paren-suppression heuristic to C++/ObjC bools.Ted Kremenek2014-03-291-6/+11
| | | | llvm-svn: 205074
* Improve -Wunreachable-code to provide a means to indicate code is ↵Ted Kremenek2014-03-291-14/+48
| | | | | | | | | | | | | | | | | | intentionally marked dead via if((0)). Taking a hint from -Wparentheses, use an extra '()' as a sigil that a dead condition is intentionally dead. For example: if ((0)) { dead } When this sigil is found, do not emit a dead code warning. When the analysis sees: if (0) it suggests inserting '()' as a Fix-It. llvm-svn: 205069
* [-Wunreachable-code] add a specialized diagnostic for unreachable increment ↵Ted Kremenek2014-03-211-0/+20
| | | | | | expressions of loops. llvm-svn: 204430
* [-Wunreachable-code] Tweak isTrivialDoWhile() to handle implicit casts.Ted Kremenek2014-03-201-1/+1
| | | | llvm-svn: 204376
* [-Wunreachable-code] Look through member accesses for 'static const bool' ↵Ted Kremenek2014-03-201-23/+27
| | | | | | configuration values. llvm-svn: 204315
* [-Wunreachable-code] constexpr functions can be used as configuration values.Ted Kremenek2014-03-201-0/+5
| | | | llvm-svn: 204308
* [-Wunreachable-code] Simplify and broad -Wunreachable-code-return, including ↵Ted Kremenek2014-03-201-72/+22
| | | | | | | | | | | | | | | | | nontrivial returns. The exception is return statements that include control-flow, which are clearly doing something "interesting". 99% of the cases I examined for -Wunreachable-code that fired on return statements were not interesting enough to warrant being in -Wunreachable-code by default. Thus the move to include them in -Wunreachable-code-return. This simplifies a bunch of logic, including removing the ad hoc logic to look for std::string literals. llvm-svn: 204307
* Remove dead functions from unreachable code analysis.Benjamin Kramer2014-03-151-44/+0
| | | | llvm-svn: 204004
* -Wunreachable-code: treat 'const bool' locals as control values.Ted Kremenek2014-03-151-1/+6
| | | | llvm-svn: 204001
* Further refine -Wunreachable-code groups so that -Wno-unreachable-code-break ↵Ted Kremenek2014-03-151-34/+27
| | | | | | | | | | doesn't turn off all unreachable code warnings. Also relax unreachable 'break' and 'return' to not check for being preceded by a call to 'noreturn'. That turns out to not be so interesting in practice. llvm-svn: 204000
* Start breaking -Wunreachable-code up into different diagnostic groups.Ted Kremenek2014-03-151-22/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Recent work on -Wunreachable-code has focused on suppressing uninteresting unreachable code that center around "configuration values", but there are still some set of cases that are sometimes interesting or uninteresting depending on the codebase. For example, a dead "break" statement may not be interesting for a particular codebase, potentially because it is auto-generated or simply because code is written defensively. To address these workflow differences, -Wunreachable-code is now broken into several diagnostic groups: -Wunreachable-code: intended to be a reasonable "default" for most users. and then other groups that turn on more aggressive checking: -Wunreachable-code-break: warn about dead break statements -Wunreachable-code-trivial-return: warn about dead return statements that return "trivial" values (e.g., return 0). Other return statements that return non-trivial values are still reported under -Wunreachable-code (this is an area subject to more refinement). -Wunreachable-code-aggressive: supergroup that enables all these groups. The goal is to eventually make -Wunreachable-code good enough to either be in -Wall or on-by-default, thus finessing these warnings into different groups helps achieve maximum signal for more users. TODO: the tests need to be updated to reflect this extra control via diagnostic flags. llvm-svn: 203994
* [-Wunreachable-code] Handle Objective-C bool literals in 'isConfigurationValue'.Ted Kremenek2014-03-091-24/+63
| | | | | | | This includes special casing 'YES' and 'NO', which are constants defined as macros. llvm-svn: 203380
* [-Wunreachable-code] Tweak heuristic for configuration values to include ↵Ted Kremenek2014-03-081-6/+11
| | | | | | | | | arithmetic operations involving sizeof(), but not raw integers. This case was motivated by a false positive with the llvm::AlignOf<> specialization in LLVM. llvm-svn: 203363
* [-Wunreachabe-code] Don't warn about unreachable destructors for temporaries.Ted Kremenek2014-03-081-3/+5
| | | | | | | | This can possibly be refined later, but right now the experience is so incomprehensible for a user to understand what is going on this isn't a useful warning. llvm-svn: 203336
* [-Wunreachable-code] Handle 'return' with no argument dominated by ↵Ted Kremenek2014-03-081-6/+11
| | | | | | 'noreturn' function. llvm-svn: 203333
* [C++11] Revert uses of lambdas with array_pod_sort.Benjamin Kramer2014-03-071-7/+10
| | | | | | Looks like GCC implements the lambda->function pointer conversion differently. llvm-svn: 203293
* [C++11] Convert sort predicates into lambdas.Benjamin Kramer2014-03-071-10/+7
| | | | | | No functionality change. llvm-svn: 203289
* [-Wunreachable-code] Treat constant globals as configuration values in ↵Ted Kremenek2014-03-071-2/+14
| | | | | | | | | unreachable code heuristics. This one could possibly be refined even further; e.g. looking at the initializer and see if it is truly a configuration value. llvm-svn: 203283
* Fix recent regressions in -Wreturn-type caused by heuristics to ↵Ted Kremenek2014-03-071-248/+274
| | | | | | | | | | | | | | | | | -Wunreachable-code. I had forgotten that the same reachability code is used by both -Wreturn-type and -Wunreachable-code, so the heuristics applied to the latter were indirectly impacting the former. To address this, the reachability code is more refactored so that whiled the logic at its core is shared, the intention of the clients are better captured and segregated in helper APIs. Fixes PR19074, and also some false positives reported offline to me by Nick Lewycky. llvm-svn: 203209
* [-Wunreachable-code] Correctly expand artificial reachability to pruned '&&' ↵Ted Kremenek2014-03-071-4/+12
| | | | | | and '||' branches involving configuration values. llvm-svn: 203194
* [-Wunreachable-code] Teach reachable code analysis heuristics about more ↵Ted Kremenek2014-03-071-0/+2
| | | | | | literal types. llvm-svn: 203193
* [-Wunreachable-code] Refine treating all branches of 'switch' as reachable, ↵Ted Kremenek2014-03-061-18/+4
| | | | | | which includes those with all cases covered but with no 'default:'. llvm-svn: 203094
* [-Wunreachable-code] don't warn about dead 'return <string literal>' ↵Ted Kremenek2014-03-061-2/+52
| | | | | | | | | | | | | dominated by a 'noreturn' call, where literal becomes an std::string. I have mixed feelings about this one. It's used all over the codebase, and is analogous to the current heuristic for ordinary C string literals. This requires some ad hoc pattern matching of the AST. While the test case mirrors what we see std::string in libc++, it's not really testing the libc++ headers. llvm-svn: 203091
* [-Wunreachable-code] Handle idiomatic do...while() with an uninteresting ↵Ted Kremenek2014-03-061-7/+4
| | | | | | | | | | condition. Sometimes do..while() is used to create a scope that can be left early. In such cases, the unreachable 'while()' test is not usually interesting unless it actually does something that is observable. llvm-svn: 203051
* [-Wunreachable-code] Handle idiomatic do...while() with an uninteresting ↵Ted Kremenek2014-03-061-7/+17
| | | | | | | | | | condition. Sometimes do..while() is used to create a scope that can be left early. In such cases, the unreachable 'while()' test is not usually interesting unless it actually does something that is observable. llvm-svn: 203036
* [-Wunreachable-code] generalize pruning out warning on trivial returns.Ted Kremenek2014-03-051-9/+6
| | | | | | | | Previously we only pruned dead returns preceded by a call to a 'noreturn' function. After looking at the results of the LLVM codebase, there are many others that should be pruned as well. llvm-svn: 203029
* [-Wunreachable-code] include some enum constants in "configuration value" ↵Ted Kremenek2014-03-051-0/+5
| | | | | | heuristic llvm-svn: 203026
OpenPOWER on IntegriCloud