Index: lib/Analysis/CFG.cpp =================================================================== --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -2983,20 +2983,19 @@ return nullptr; } - if (!KnownVal.isFalse()) { - // Add an intermediate block between the BodyBlock and the - // ExitConditionBlock to represent the "loop back" transition. Create an - // empty block to represent the transition block for looping back to the - // head of the loop. - // FIXME: Can we do this more efficiently without adding another block? - Block = nullptr; - Succ = BodyBlock; - CFGBlock *LoopBackBlock = createBlock(); - LoopBackBlock->setLoopTarget(D); + // Add an intermediate block between the BodyBlock and the + // ExitConditionBlock to represent the "loop back" transition. Create an + // empty block to represent the transition block for looping back to the + // head of the loop. + // FIXME: Can we do this more efficiently without adding another block? + Block = nullptr; + Succ = BodyBlock; + CFGBlock *LoopBackBlock = createBlock(); + LoopBackBlock->setLoopTarget(D); + if (!KnownVal.isFalse()) // Add the loop body entry as a successor to the condition. addSuccessor(ExitConditionBlock, LoopBackBlock); - } else addSuccessor(ExitConditionBlock, nullptr); } Index: test/Analysis/unreachable-code-path.c =================================================================== --- test/Analysis/unreachable-code-path.c +++ test/Analysis/unreachable-code-path.c @@ -158,3 +158,14 @@ } } } + +// Ensure that ExplodedGraph and unoptimized CFG match. +void test12(int x) { + switch (x) { + case 1: + break; // not unreachable + case 2: + do { } while (0); + break; + } +}