diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-04-14 21:41:27 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-06-22 18:20:56 +0000 |
commit | bdd1243df58e60e85101c09001d9812a789b6bc4 (patch) | |
tree | a1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/clang/lib/Analysis/ReachableCode.cpp | |
parent | 781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff) | |
parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) | |
download | src-bdd1243df58e60e85101c09001d9812a789b6bc4.tar.gz src-bdd1243df58e60e85101c09001d9812a789b6bc4.zip |
Merge llvm-project main llvmorg-16-init-18548-gb0daacf58f41
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvmorg-16-init-18548-gb0daacf58f41.
PR: 271047
MFC after: 1 month
Diffstat (limited to 'contrib/llvm-project/clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Analysis/ReachableCode.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/contrib/llvm-project/clang/lib/Analysis/ReachableCode.cpp b/contrib/llvm-project/clang/lib/Analysis/ReachableCode.cpp index 1b7d774aeb40..5cc63bb17b09 100644 --- a/contrib/llvm-project/clang/lib/Analysis/ReachableCode.cpp +++ b/contrib/llvm-project/clang/lib/Analysis/ReachableCode.cpp @@ -24,6 +24,7 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/SmallVector.h" +#include <optional> using namespace clang; @@ -73,7 +74,7 @@ static bool isBuiltinAssumeFalse(const CFGBlock *B, const Stmt *S, // (e.g. a CFGBlock containing only a goto). return false; } - if (Optional<CFGStmt> CS = B->back().getAs<CFGStmt>()) { + if (std::optional<CFGStmt> CS = B->back().getAs<CFGStmt>()) { if (const auto *CE = dyn_cast<CallExpr>(CS->getStmt())) { return CE->getCallee()->IgnoreCasts() == S && CE->isBuiltinAssumeFalse(C); } @@ -88,7 +89,7 @@ static bool isDeadReturn(const CFGBlock *B, const Stmt *S) { const CFGBlock *Current = B; while (true) { for (const CFGElement &CE : llvm::reverse(*Current)) { - if (Optional<CFGStmt> CS = CE.getAs<CFGStmt>()) { + if (std::optional<CFGStmt> CS = CE.getAs<CFGStmt>()) { if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) { if (RS == S) return true; @@ -218,7 +219,7 @@ static bool isConfigurationValue(const Stmt *S, return isConfigurationValue(cast<DeclRefExpr>(S)->getDecl(), PP); case Stmt::ObjCBoolLiteralExprClass: IgnoreYES_NO = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case Stmt::CXXBoolLiteralExprClass: case Stmt::IntegerLiteralClass: { const Expr *E = cast<Expr>(S); @@ -299,6 +300,12 @@ static bool shouldTreatSuccessorsAsReachable(const CFGBlock *B, if (isa<BinaryOperator>(Term)) { return isConfigurationValue(Term, PP); } + // Do not treat constexpr if statement successors as unreachable in warnings + // since the point of these statements is to determine branches at compile + // time. + if (const auto *IS = dyn_cast<IfStmt>(Term); + IS != nullptr && IS->isConstexpr()) + return true; } const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false); @@ -333,7 +340,7 @@ static unsigned scanFromBlock(const CFGBlock *Start, // This allows us to potentially uncover some "always unreachable" code // within the "sometimes unreachable" code. // Look at the successors and mark then reachable. - Optional<bool> TreatAllSuccessorsAsReachable; + std::optional<bool> TreatAllSuccessorsAsReachable; if (!IncludeSometimesUnreachableEdges) TreatAllSuccessorsAsReachable = false; @@ -455,7 +462,7 @@ static bool isValidDeadStmt(const Stmt *S) { const Stmt *DeadCodeScan::findDeadCode(const clang::CFGBlock *Block) { for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I!=E; ++I) - if (Optional<CFGStmt> CS = I->getAs<CFGStmt>()) { + if (std::optional<CFGStmt> CS = I->getAs<CFGStmt>()) { const Stmt *S = CS->getStmt(); if (isValidDeadStmt(S)) return S; |