diff --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp index 6699a0fc9d79e..5520633da68ae 100644 --- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp +++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp @@ -70,7 +70,7 @@ static llvm::BitVector findReachableBlocks(const CFG &Cfg) { llvm::Expected ControlFlowContext::build(const Decl *D, Stmt &S, ASTContext &C) { CFG::BuildOptions Options; - Options.PruneTriviallyFalseEdges = false; + Options.PruneTriviallyFalseEdges = true; Options.AddImplicitDtors = true; Options.AddTemporaryDtors = true; Options.AddInitializers = true; diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 750d095af451a..c8161c8f40fc9 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -2644,7 +2644,7 @@ TEST(TransferTest, VarDeclInDoWhile) { void target(int *Foo) { do { int Bar = *Foo; - } while (true); + } while (false); (void)0; /*[[p]]*/ } @@ -2675,6 +2675,24 @@ TEST(TransferTest, VarDeclInDoWhile) { }); } +TEST(TransferTest, UnreachableAfterWhileTrue) { + std::string Code = R"( + void target() { + while (true) {} + (void)0; + /*[[p]]*/ + } + )"; + runDataflow( + Code, + [](const llvm::StringMap> &Results, + ASTContext &ASTCtx) { + // The node after the while-true is pruned because it is trivially + // known to be unreachable. + ASSERT_TRUE(Results.empty()); + }); +} + TEST(TransferTest, AggregateInitialization) { std::string BracesCode = R"( struct A {