From: Jakub Dupak Date: Thu, 19 Oct 2023 09:04:29 +0000 (+0200) Subject: gccrs: borrowck: Dump: handle infinite loops X-Git-Tag: basepoints/gcc-15~2053 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c65919e19ca670b200718c0c37d24a9111fe4b9;p=thirdparty%2Fgcc.git gccrs: 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 --- 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 #include "rust-bir-dump.h" +#include "rust-diagnostics.h" namespace Rust { namespace BIR { @@ -76,7 +77,21 @@ simplify_cfg (Function &func, std::vector &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; } }