================
@@ -3101,7 +3101,19 @@ void ExprEngine::processSwitch(const SwitchStmt *Switch, 
ExplodedNode *Pred,
 
     std::optional<NonLoc> CondNL = CondV.getAs<NonLoc>();
 
-    for (const CFGBlock *Block : Builder) {
+    // The reversed iteration order was arbitrarily introduced in 2008 by
+    // commit 80ebc1d1c95704b0ff0386b3a3cbc8b3ff960654 (which added support for
+    // control flow in switch statements). I don't see any advantage of this
+    // iteration order, but changing it would change the order of insertion
+    // into the work list, which would perturb the analyzer results.
+    // FIXME: With forward iterators it would be possible to replace this
+    // convoluted code with a simple range-based for loop over
+    // CFGBlock::succs().
+    using iterator = CFGBlock::const_succ_reverse_iterator;
+    iterator LastCase = getCurrBlock()->succ_rbegin() + 1;
+    iterator BeforeFirstCase = getCurrBlock()->succ_rend();
+    for (iterator I = LastCase; I < BeforeFirstCase; I++) {
+      const CFGBlock *Block = *I;
----------------
NagyDonat wrote:

This was simplified in a different way in 
https://github.com/llvm/llvm-project/pull/188096/commits/67bee70ebb80f6db00460ec03f3469ef1e204316.

I like that your suggestion doesn't need to spell out 
`llvm::iterator_range<CFGBlock::const_succ_reverse_iterator>`, but I still 
(very slightly) prefer my solution, because I feel that calling `reverse` on an 
iterator range is a bit "too magical" for C++. In Python I would write 
something like your suggestion without a second thought, but here it feels a 
bit too high-level. However, I can apply your approach if you say so. 

https://github.com/llvm/llvm-project/pull/188096
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to