https://gcc.gnu.org/g:8aac66b06e352ed869b76098dd07273d813128fc
commit 8aac66b06e352ed869b76098dd07273d813128fc Author: Jakub Dupak <d...@jakubdupak.com> Date: Thu Oct 19 11:04:29 2023 +0200 borrowck: Dump: handle infinite loops gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Detech infinite loops. Signed-off-by: Jakub Dupak <d...@jakubdupak.com> Diff: --- gcc/rust/checks/errors/borrowck/rust-bir-dump.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc index ba530983dade..66870ddeb565 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc +++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc @@ -1,5 +1,6 @@ #include <numeric> #include "rust-bir-dump.h" +#include "rust-diagnostics.h" namespace Rust { namespace BIR { @@ -76,7 +77,21 @@ simplify_cfg (Function &func, std::vector<BasicBlockId> &bb_fold_map) const BasicBlock &bb = func.basic_blocks[bb_fold_map[i]]; if (bb.statements.empty () && bb.is_goto_terminated ()) { - bb_fold_map[i] = bb.successors.at (0); + auto dst = bb.successors.at (0); + if (bb_fold_map[dst] != dst) + { + rust_error_at ( + UNKNOWN_LOCATION, + "BIR DUMP: Cannot fold CFG, because it contains an " + "infinite loop with no executable statements."); + rust_inform (UNKNOWN_LOCATION, + "Continuing with an unfolded CFG."); + // Reverting the fold map to the original state. + std::iota (bb_fold_map.begin (), bb_fold_map.end (), 0); + stabilized = true; + break; + } + bb_fold_map[i] = dst; stabilized = false; } }