summaryrefslogtreecommitdiff
path: root/lib/Analysis/ReachableCode.cpp
Commit message (Collapse)AuthorAge
* Make dead return statement detection more robust against changes in the CFG.Manuel Klimek2014-05-23
| | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209531 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Use 'nullptr'. Analysis edition.Craig Topper2014-05-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209191 91177308-0d34-0410-b5e6-96231b3b80d8
* -Wunreachable-code: refine recognition of unreachable "sigil" to cope with ↵Ted Kremenek2014-04-16
| | | | | | | | implicit casts in C++. Fixes <rdar://problem/16631033>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206360 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Expand paren-suppression heuristic to C++/ObjC bools.Ted Kremenek2014-03-29
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205074 91177308-0d34-0410-b5e6-96231b3b80d8
* Improve -Wunreachable-code to provide a means to indicate code is ↵Ted Kremenek2014-03-29
| | | | | | | | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205069 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] add a specialized diagnostic for unreachable increment ↵Ted Kremenek2014-03-21
| | | | | | expressions of loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204430 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Tweak isTrivialDoWhile() to handle implicit casts.Ted Kremenek2014-03-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204376 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Look through member accesses for 'static const bool' ↵Ted Kremenek2014-03-20
| | | | | | configuration values. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204315 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] constexpr functions can be used as configuration values.Ted Kremenek2014-03-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204308 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Simplify and broad -Wunreachable-code-return, including ↵Ted Kremenek2014-03-20
| | | | | | | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204307 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove dead functions from unreachable code analysis.Benjamin Kramer2014-03-15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204004 91177308-0d34-0410-b5e6-96231b3b80d8
* -Wunreachable-code: treat 'const bool' locals as control values.Ted Kremenek2014-03-15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204001 91177308-0d34-0410-b5e6-96231b3b80d8
* Further refine -Wunreachable-code groups so that -Wno-unreachable-code-break ↵Ted Kremenek2014-03-15
| | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204000 91177308-0d34-0410-b5e6-96231b3b80d8
* Start breaking -Wunreachable-code up into different diagnostic groups.Ted Kremenek2014-03-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203994 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Handle Objective-C bool literals in 'isConfigurationValue'.Ted Kremenek2014-03-09
| | | | | | | This includes special casing 'YES' and 'NO', which are constants defined as macros. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203380 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Tweak heuristic for configuration values to include ↵Ted Kremenek2014-03-08
| | | | | | | | | arithmetic operations involving sizeof(), but not raw integers. This case was motivated by a false positive with the llvm::AlignOf<> specialization in LLVM. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203363 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachabe-code] Don't warn about unreachable destructors for temporaries.Ted Kremenek2014-03-08
| | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203336 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Handle 'return' with no argument dominated by ↵Ted Kremenek2014-03-08
| | | | | | 'noreturn' function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203333 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Revert uses of lambdas with array_pod_sort.Benjamin Kramer2014-03-07
| | | | | | Looks like GCC implements the lambda->function pointer conversion differently. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203293 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Convert sort predicates into lambdas.Benjamin Kramer2014-03-07
| | | | | | No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203289 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Treat constant globals as configuration values in ↵Ted Kremenek2014-03-07
| | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203283 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix recent regressions in -Wreturn-type caused by heuristics to ↵Ted Kremenek2014-03-07
| | | | | | | | | | | | | | | | | -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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203209 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Correctly expand artificial reachability to pruned '&&' ↵Ted Kremenek2014-03-07
| | | | | | and '||' branches involving configuration values. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203194 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Teach reachable code analysis heuristics about more ↵Ted Kremenek2014-03-07
| | | | | | literal types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203193 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Refine treating all branches of 'switch' as reachable, ↵Ted Kremenek2014-03-06
| | | | | | which includes those with all cases covered but with no 'default:'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203094 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] don't warn about dead 'return <string literal>' ↵Ted Kremenek2014-03-06
| | | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203091 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Handle idiomatic do...while() with an uninteresting ↵Ted Kremenek2014-03-06
| | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203051 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Handle idiomatic do...while() with an uninteresting ↵Ted Kremenek2014-03-06
| | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203036 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] generalize pruning out warning on trivial returns.Ted Kremenek2014-03-05
| | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203029 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] include some enum constants in "configuration value" ↵Ted Kremenek2014-03-05
| | | | | | heuristic git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203026 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] generalize configuration value checking to all ↵Ted Kremenek2014-03-05
| | | | | | comparison operators. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203016 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Don't warn about dead code guarded by a "configuration ↵Ted Kremenek2014-03-05
| | | | | | | | | | | | | | | value". Some unreachable code is only "sometimes unreachable" because it is guarded by a configuration value that is determined at compile time and is always constant. Sometimes those represent real bugs, but often they do not. This patch causes the reachability analysis to cover such branches even if they are technically unreachable in the CFG itself. There are some conservative heuristics at play here to determine a "configuration value"; these are intended to be refined over time. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202912 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] handle cases where a dead 'return' may have a valid ↵Ted Kremenek2014-03-04
| | | | | | | | predecessor. Fies PR19040. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202892 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] always treat 'case:' and 'default:' cases as reachable.Ted Kremenek2014-02-27
| | | | | | | | | | | This is a heuristic. Many switch statements, although they look covered over an enum, may actually handle at runtime more values than in the enum. This is overly conservative, as there are some cases that clearly can be ruled as being clearly unreachable, e.g. 'switch (42) { case 1: ... }'. We can refine this later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202436 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Don't warn about trivially unreachable return ↵Ted Kremenek2014-02-27
| | | | | | statements preceded by 'noreturn' functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202352 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Don't warn about unreachable 'default:' cases.Ted Kremenek2014-02-27
| | | | | | They are covered by -Wcovered-switch-default. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202349 91177308-0d34-0410-b5e6-96231b3b80d8
* [-Wunreachable-code] Prune out unreachable warnings where a 'break' is ↵Ted Kremenek2014-02-27
| | | | | | | | | | | | | | | preceded by a call to a 'noreturn' function. For example: unreachable(); break; This code is idiomatic and defensive. The fact that 'break' is unreachable here is not interesting. This occurs frequently in LLVM/Clang itself. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202328 91177308-0d34-0410-b5e6-96231b3b80d8
* Make sort predicate match the qsort convention.Benjamin Kramer2013-09-22
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191177 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix array_pod_sort predicates after LLVM change.Benjamin Kramer2013-09-22
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191176 91177308-0d34-0410-b5e6-96231b3b80d8
* Properly track l-paren of a CXXFucntionalCastExpr.Eli Friedman2013-08-15
| | | | | | | | | | In addition to storing more useful information in the AST, this fixes a semantic check in template instantiation which checks whether the l-paren location is valid. Fixes PR16903. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188495 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove the CFGElement "Invalid" state.David Blaikie2013-02-23
| | | | | | | | | | | | | Use Optional<CFG*> where invalid states were needed previously. In the one case where that's not possible (beginAutomaticObjDtorsInsert) just use a dummy CFGAutomaticObjDtor. Thanks for the help from Jordan Rose & discussion/feedback from Ted Kremenek and Doug Gregor. Post commit code review feedback on r175796 by Ted Kremenek. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175938 91177308-0d34-0410-b5e6-96231b3b80d8
* Replace CFGElement llvm::cast support to be well-defined.David Blaikie2013-02-21
| | | | | | See r175462 for another example/more details. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175796 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko2013-01-12
| | | | | | | brought into 'clang' namespace by clang/Basic/LLVM.h git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172323 91177308-0d34-0410-b5e6-96231b3b80d8
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-04
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169237 91177308-0d34-0410-b5e6-96231b3b80d8
* Dont cast away const needlessly. Found by gcc48 -Wcast-qual.Roman Divacky2012-09-06
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163325 91177308-0d34-0410-b5e6-96231b3b80d8
* Unweaken vtables as per ↵David Blaikie2011-12-20
| | | | | | http://llvm.org/docs/CodingStandards.html#ll_virtual_anch git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146959 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename AnalysisContext to AnalysisDeclContext. Not only is this name more ↵Ted Kremenek2011-10-24
| | | | | | accurate, but it frees up the name AnalysisContext for other uses. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142782 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach -Wunreachable-code about dead code caused by macro expansions. This ↵Ted Kremenek2011-08-25
| | | | | | should suppress false positives resulting from 'assert' and friends. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138576 91177308-0d34-0410-b5e6-96231b3b80d8
* Start reworking -Wunreachable-code. The original analysis had serious flaws ↵Ted Kremenek2011-08-23
| | | | | | | | | | with how it handled SCC's of dead code, or simply having false negatives by overly suppressing warnings. WIP. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138410 91177308-0d34-0410-b5e6-96231b3b80d8
* remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner2011-07-23
| | | | | | | | | LLVM.h imports them into the clang namespace. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135852 91177308-0d34-0410-b5e6-96231b3b80d8