]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: borrowck: Dump: handle infinite loops
authorJakub Dupak <dev@jakubdupak.com>
Thu, 19 Oct 2023 09:04:29 +0000 (11:04 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:09:29 +0000 (19:09 +0100)
gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Detech infinite loops.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
gcc/rust/checks/errors/borrowck/rust-bir-dump.cc

index ba530983dade5c0d7b3e39bac27d6011770426bc..66870ddeb565d7432c87b3f3ae8e0c30312596b1 100644 (file)
@@ -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;
            }
        }