diff --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp --- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp +++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp @@ -70,7 +70,7 @@ 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 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -2644,7 +2644,7 @@ void target(int *Foo) { do { int Bar = *Foo; - } while (true); + } while (false); (void)0; /*[[p]]*/ } @@ -2675,6 +2675,24 @@ }); } +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 {