aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/ReachableCode.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-01[Analysis] Use range-based for loops (NFC) (#146466)Kazu Hirata1-3/+2
2025-05-31[Analysis] Remove unused includes (NFC) (#142255)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-02-22Revert "Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and ↵yronglin1-19/+18
default init expression" (#127338)" (#128205) This reverts commit d235b72178adc710bf704078fbe0cd687642f3e0.
2025-02-17Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default ↵yronglin1-18/+19
init expression" (#127338) This PR reapply https://github.com/llvm/llvm-project/pull/117437. The issue has been fixed by the 2nd commit, we need to ignore parens in CXXDefaultArgExpr when build CFG, because CXXDefaultArgExpr::getExpr stripped off the top level FullExpr and ConstantExpr, ParenExpr may occurres in the top level. --------- Signed-off-by: yronglin <yronglin777@gmail.com>
2025-02-03Revert "[Analyzer][CFG] Correctly handle rebuilt default arg and default ↵Hans Wennborg1-19/+18
init expression (#117437)" This caused assertion failures: clang/lib/Analysis/CFG.cpp:822: void (anonymous namespace)::CFGBuilder::appendStmt(CFGBlock *, const Stmt *): Assertion `!isa<Expr>(S) || cast<Expr>(S)->IgnoreParens() == S' failed. See comment on the PR. This reverts commit 44aa618ef67d302f5ab77cc591fb3434fe967a2e.
2025-02-01[Analyzer][CFG] Correctly handle rebuilt default arg and default init ↵yronglin1-18/+19
expression (#117437) Clang currently support extending lifetime of object bound to reference members of aggregates, that are created from default member initializer. This PR address this change and updaye CFG and ExprEngine. This PR reapply https://github.com/llvm/llvm-project/pull/91879. Fixes https://github.com/llvm/llvm-project/issues/93725. --------- Signed-off-by: yronglin <yronglin777@gmail.com>
2024-11-15[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use ↵Sirraide1-6/+8
DynamicRecursiveASTVisitor (#115144) This pr refactors all recursive AST visitors in `Sema`, `Analyze`, and `StaticAnalysis` to inherit from DRAV instead. This is over half of the visitors that inherit from RAV directly. See also #115132, #110040, #93462 LLVM Compile-Time Tracker link for this branch: https://llvm-compile-time-tracker.com/compare.php?from=5adb5c05a2e9f31385fbba8b0436cbc07d91a44d&to=b58e589a86c06ba28d4d90613864d10be29aa5ba&stat=instructions%3Au
2024-02-05[coroutine] Suppress unreachable-code warning on coroutine statements. (#77454)Haojian Wu1-4/+47
This fixes #69219. Consider an example: ``` CoTask my_coroutine() { std::abort(); co_return 1; // unreachable code warning. } ``` Clang emits a CFG-based unreachable warning on the `co_return` statement (precisely the `1` subexpr). If we remove this statement, the program semantic is changed (my_coroutine is not a coroutine anymore). This patch fixes this issue by never considering coroutine statements as dead statements.
2023-03-14[clang][Sema] Avoid duplicate diagnostics for unreachable fallthrough attributeTakuya Shimizu1-3/+9
This patch checks whether -Wunreachable-code-fallthrough is enabled when clang encounters unreachable fallthrough attributes and, if so, suppresses code will never be executed warning to avoid duplicate warnings. Fixes https://github.com/llvm/llvm-project/issues/60416 Differential Revision: https://reviews.llvm.org/D145842
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-4/+4
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-15[clang][diagnostics] Don't warn about unreachable code in constexpr ifAlan Zhao1-0/+6
The point of a constexpr if statement is to determine which branch to take at compile time, so warning on unreachable code is meaningless in these situations. Fixes #57123. Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D131818
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2022-06-20[clang] Don't use Optional::getValue (NFC)Kazu Hirata1-1/+1
2022-06-20[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
2021-11-07[AST, Analysis] Use llvm::reverse (NFC)Kazu Hirata1-4/+2
2021-10-10clang: Add range-based CFG::try_blocks()Nico Weber1-4/+2
..and use it. No behavior change.
2021-10-10clang: Convert two loops to for-eachNico Weber1-7/+6
And rewrap a line at 80 columns while here. No behavior change.
2020-06-25Change while to do-whileSeija Kijin1-2/+2
Differential Revision: https://reviews.llvm.org/D70603
2019-11-15Avoid including Builtins.h in Preprocessor.hReid Kleckner1-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.
2019-09-21Improve -Wtautological-overlap-compareRichard Trieu1-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
2019-05-24[CFG] NFC: Remove implicit conversion from CFGTerminator to Stmt *.Artem Dergachev1-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
2019-03-01Fix file headers. NFCFangrui Song1-1/+1
llvm-svn: 355176
2019-02-15Revert "[Analysis] -Wunreachable-code shouldn't fire on the increment of a ↵Sam McCall1-4/+0
foreach loop" This reverts commit r354102. llvm-svn: 354109
2019-02-15[Analysis] -Wunreachable-code shouldn't fire on the increment of a foreach loopSam McCall1-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
2019-02-03[AST] Update the comments of the various Expr::Ignore* + Related cleanupsBruno Ricci1-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
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-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
2018-11-01Fix clang -Wimplicit-fallthrough warnings across llvm, NFCReid Kleckner1-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
2018-08-09Port getLocStart -> getBeginLocStephen Kelly1-10/+10
Reviewers: teemperor! Subscribers: jholewinski, whisperity, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50350 llvm-svn: 339385
2018-07-30Remove trailing spaceFangrui Song1-11/+11
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-02-13Teach Wreturn-type, Wunreachable-code, and alpha.deadcode.UnreachableCode to ↵Nico Weber1-4/+21
treat __assume(0) like __builtin_unreachable. Fixes PR29134. https://reviews.llvm.org/D43221 llvm-svn: 325052
2017-09-06[CSA] [NFC] Move AnalysisContext.h to AnalysisDeclContext.hGeorge Karpenkov1-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
2017-04-11Fix PR13910: Don't warn that __builtin_unreachable() is unreachableAlex Lorenz1-2/+9
Differential Revision: https://reviews.llvm.org/D25321 llvm-svn: 299951
2017-04-05-Wunreachable-code: 'true' and 'false' should not be treated as configurationAlex Lorenz1-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
2017-01-12Avoid multiple -Wunreachable-code diagnostics that are triggered byAlex Lorenz1-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
2016-11-01[ReachableCode] Skip over ExprWithCleanups in isConfigurationValueTim Shen1-0/+2
Summary: Fixes pr29152. Reviewers: rsmith, pirama, krememek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24010 llvm-svn: 285657
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-3/+2
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-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
2015-01-14[cleanup] Re-sort *all* #include lines with llvm/utils/sort_includes.pyChandler Carruth1-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
2014-05-23Make dead return statement detection more robust against changes in the CFG.Manuel Klimek1-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
2014-05-20[C++11] Use 'nullptr'. Analysis edition.Craig Topper1-2/+2
llvm-svn: 209191
2014-04-16-Wunreachable-code: refine recognition of unreachable "sigil" to cope with ↵Ted Kremenek1-1/+4
implicit casts in C++. Fixes <rdar://problem/16631033>. llvm-svn: 206360
2014-03-29[-Wunreachable-code] Expand paren-suppression heuristic to C++/ObjC bools.Ted Kremenek1-6/+11
llvm-svn: 205074
2014-03-29Improve -Wunreachable-code to provide a means to indicate code is ↵Ted Kremenek1-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
2014-03-21[-Wunreachable-code] add a specialized diagnostic for unreachable increment ↵Ted Kremenek1-0/+20
expressions of loops. llvm-svn: 204430
2014-03-20[-Wunreachable-code] Tweak isTrivialDoWhile() to handle implicit casts.Ted Kremenek1-1/+1
llvm-svn: 204376
2014-03-20[-Wunreachable-code] Look through member accesses for 'static const bool' ↵Ted Kremenek1-23/+27
configuration values. llvm-svn: 204315
2014-03-20[-Wunreachable-code] constexpr functions can be used as configuration values.Ted Kremenek1-0/+5
llvm-svn: 204308
2014-03-20[-Wunreachable-code] Simplify and broad -Wunreachable-code-return, including ↵Ted Kremenek1-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
2014-03-15Remove dead functions from unreachable code analysis.Benjamin Kramer1-44/+0
llvm-svn: 204004