Commit Graph

69 Commits

Author SHA1 Message Date
Alex Lorenz 46103e0ede Fix PR13910: Don't warn that __builtin_unreachable() is unreachable
Differential Revision: https://reviews.llvm.org/D25321

llvm-svn: 299951
2017-04-11 15:36:06 +00:00
Alex Lorenz 6615f2b3d6 -Wunreachable-code: 'true' and 'false' should not be treated as configuration
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
2017-04-05 14:07:21 +00:00
Alex Lorenz 569ad73d6b Avoid multiple -Wunreachable-code diagnostics that are triggered by
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
2017-01-12 10:48:03 +00:00
Tim Shen 43ee05e804 [ReachableCode] Skip over ExprWithCleanups in isConfigurationValue
Summary: Fixes pr29152.

Reviewers: rsmith, pirama, krememek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D24010

llvm-svn: 285657
2016-11-01 00:19:04 +00:00
Alexander Kornienko ab9db51042 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
llvm-svn: 240353
2015-06-22 23:07:51 +00:00
Alexander Kornienko 3d9d929e42 Fixed/added namespace ending comments using clang-tidy. NFC
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
2015-06-22 09:47:44 +00:00
Chandler Carruth 0d9593ddec [cleanup] Re-sort *all* #include lines with llvm/utils/sort_includes.py
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
2015-01-14 11:29:14 +00:00
Manuel Klimek 5fbdc93d97 Make dead return statement detection more robust against changes in the CFG.
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
2014-05-23 17:09:56 +00:00
Craig Topper 2554294321 [C++11] Use 'nullptr'. Analysis edition.
llvm-svn: 209191
2014-05-20 04:30:07 +00:00
Ted Kremenek 6f375e5604 -Wunreachable-code: refine recognition of unreachable "sigil" to cope with implicit casts in C++.
Fixes <rdar://problem/16631033>.

llvm-svn: 206360
2014-04-16 07:26:09 +00:00
Ted Kremenek ab57a1555a [-Wunreachable-code] Expand paren-suppression heuristic to C++/ObjC bools.
llvm-svn: 205074
2014-03-29 04:49:20 +00:00
Ted Kremenek ec3bbf4933 Improve -Wunreachable-code to provide a means to indicate code is 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
2014-03-29 00:35:20 +00:00
Ted Kremenek 1421037ece [-Wunreachable-code] add a specialized diagnostic for unreachable increment expressions of loops.
llvm-svn: 204430
2014-03-21 06:02:36 +00:00
Ted Kremenek d4576318b4 [-Wunreachable-code] Tweak isTrivialDoWhile() to handle implicit casts.
llvm-svn: 204376
2014-03-20 18:47:53 +00:00
Ted Kremenek f5ae0bc671 [-Wunreachable-code] Look through member accesses for 'static const bool' configuration values.
llvm-svn: 204315
2014-03-20 06:44:35 +00:00
Ted Kremenek 2766ad27e8 [-Wunreachable-code] constexpr functions can be used as configuration values.
llvm-svn: 204308
2014-03-20 06:07:35 +00:00
Ted Kremenek f3c93bb61b [-Wunreachable-code] Simplify and broad -Wunreachable-code-return, including 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
2014-03-20 06:07:30 +00:00
Benjamin Kramer 8cef8867ee Remove dead functions from unreachable code analysis.
llvm-svn: 204004
2014-03-15 10:20:49 +00:00
Ted Kremenek 9dfe400dc2 -Wunreachable-code: treat 'const bool' locals as control values.
llvm-svn: 204001
2014-03-15 06:47:45 +00:00
Ted Kremenek ad8753c00e Further refine -Wunreachable-code groups so that -Wno-unreachable-code-break 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
2014-03-15 05:47:06 +00:00
Ted Kremenek 1a8641c1e7 Start breaking -Wunreachable-code up into different diagnostic groups.
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
2014-03-15 01:26:32 +00:00
Ted Kremenek 2dd810a331 [-Wunreachable-code] Handle Objective-C bool literals in 'isConfigurationValue'.
This includes special casing 'YES' and 'NO', which are constants
defined as macros.

llvm-svn: 203380
2014-03-09 08:13:49 +00:00
Ted Kremenek c980afc578 [-Wunreachable-code] Tweak heuristic for configuration values to include 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
2014-03-08 23:20:11 +00:00
Ted Kremenek efea63450b [-Wunreachabe-code] Don't warn about unreachable destructors for temporaries.
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
2014-03-08 02:22:32 +00:00
Ted Kremenek 04bfbeea04 [-Wunreachable-code] Handle 'return' with no argument dominated by 'noreturn' function.
llvm-svn: 203333
2014-03-08 02:22:23 +00:00
Benjamin Kramer 4cadf292a5 [C++11] Revert uses of lambdas with array_pod_sort.
Looks like GCC implements the lambda->function pointer conversion differently.

llvm-svn: 203293
2014-03-07 21:51:58 +00:00
Benjamin Kramer 15ae783e14 [C++11] Convert sort predicates into lambdas.
No functionality change.

llvm-svn: 203289
2014-03-07 21:35:40 +00:00
Ted Kremenek 94d1617a1f [-Wunreachable-code] Treat constant globals as configuration values in 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
2014-03-07 20:51:13 +00:00
Ted Kremenek 7d47cace55 Fix recent regressions in -Wreturn-type caused by heuristics to -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
2014-03-07 07:14:36 +00:00
Ted Kremenek 782f003c62 [-Wunreachable-code] Correctly expand artificial reachability to pruned '&&' and '||' branches involving configuration values.
llvm-svn: 203194
2014-03-07 02:25:53 +00:00
Ted Kremenek c10830b308 [-Wunreachable-code] Teach reachable code analysis heuristics about more literal types.
llvm-svn: 203193
2014-03-07 02:25:50 +00:00
Ted Kremenek 6999d02587 [-Wunreachable-code] Refine treating all branches of 'switch' as reachable, which includes those with all cases covered but with no 'default:'.
llvm-svn: 203094
2014-03-06 08:09:00 +00:00
Ted Kremenek ec2dc73e86 [-Wunreachable-code] don't warn about dead 'return <string literal>' 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
2014-03-06 06:50:46 +00:00
Ted Kremenek 7549f0f9bf [-Wunreachable-code] Handle idiomatic do...while() with an uninteresting 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
2014-03-06 01:09:45 +00:00
Ted Kremenek 1de2e14f2f [-Wunreachable-code] Handle idiomatic do...while() with an uninteresting 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
2014-03-06 00:17:44 +00:00
Ted Kremenek 0a69cabd35 [-Wunreachable-code] generalize pruning out warning on trivial returns.
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
2014-03-05 23:46:07 +00:00
Ted Kremenek 01a39b601f [-Wunreachable-code] include some enum constants in "configuration value" heuristic
llvm-svn: 203026
2014-03-05 23:38:41 +00:00
Ted Kremenek 3cdbc39a6e [-Wunreachable-code] generalize configuration value checking to all comparison operators.
llvm-svn: 203016
2014-03-05 22:32:39 +00:00
Ted Kremenek 6d9bb56cd3 [-Wunreachable-code] Don't warn about dead code guarded by a "configuration 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.

llvm-svn: 202912
2014-03-05 00:01:17 +00:00
Ted Kremenek eb862849a1 [-Wunreachable-code] handle cases where a dead 'return' may have a valid predecessor.
Fies PR19040.

llvm-svn: 202892
2014-03-04 21:41:38 +00:00
Ted Kremenek 08da97819a [-Wunreachable-code] always treat 'case:' and 'default:' cases as reachable.
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.

llvm-svn: 202436
2014-02-27 21:56:47 +00:00
Ted Kremenek 5441c18824 [-Wunreachable-code] Don't warn about trivially unreachable return statements preceded by 'noreturn' functions.
llvm-svn: 202352
2014-02-27 06:32:32 +00:00
Ted Kremenek 35883155bb [-Wunreachable-code] Don't warn about unreachable 'default:' cases.
They are covered by -Wcovered-switch-default.

llvm-svn: 202349
2014-02-27 05:42:07 +00:00
Ted Kremenek cc893386bc [-Wunreachable-code] Prune out unreachable warnings where a 'break' is 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.

llvm-svn: 202328
2014-02-27 00:24:08 +00:00
Benjamin Kramer b8f33f1690 Make sort predicate match the qsort convention.
llvm-svn: 191177
2013-09-22 15:02:02 +00:00
Benjamin Kramer 04bf187e12 Fix array_pod_sort predicates after LLVM change.
llvm-svn: 191176
2013-09-22 14:10:29 +00:00
Eli Friedman 89fe0d5842 Properly track l-paren of a CXXFucntionalCastExpr.
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.

llvm-svn: 188495
2013-08-15 22:02:56 +00:00
David Blaikie 00be69ab5c Remove the CFGElement "Invalid" state.
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.

llvm-svn: 175938
2013-02-23 00:29:34 +00:00
David Blaikie 2a01f5d426 Replace CFGElement llvm::cast support to be well-defined.
See r175462 for another example/more details.

llvm-svn: 175796
2013-02-21 20:58:29 +00:00
Dmitri Gribenko f857950d39 Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h

llvm-svn: 172323
2013-01-12 19:30:44 +00:00