]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Fix ICE with continue/break/return in while condition
authorHarishankar <harishankarpp7@gmail.com>
Mon, 24 Nov 2025 20:41:33 +0000 (02:11 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 23 Dec 2025 11:16:48 +0000 (12:16 +0100)
commit9551da9129b152a43657e83fa9c4a992df7863ff
tree9e33950753aedbd9f25fb12b11758bde7ae51a11
parent45dcd1ec93bef9307e3ef293925abdb6c8f5676c
gccrs: Fix ICE with continue/break/return in while condition

Fixes Rust-GCC/gccrs#3977

The predicate expression must be evaluated before type checking
to ensure side effects occur even when the predicate has never type.
This prevents skipping function calls, panics, or other side effects
in diverging predicates.

Proof of fix using -fdump-tree-gimple:

__attribute__((cdecl))
struct () test::main ()
{
  struct () D.107;

  <D.101>:
  <D.103>:
  {
    <D.104>:
    {
      <D.102>:
      goto <D.102>; // Side-effect correctly preserved
      if (0 != 0) goto <D.105>; else goto <D.106>;
      <D.106>:
      {

      }
    }
    goto <D.104>;
    <D.105>:
  }
  goto <D.103>;
  return D.107;
}

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Always
evaluate predicate expression before checking for never type
to preserve side effects in while loop conditions.
* typecheck/rust-hir-type-check-expr.cc: Update handling of break/continue.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3977.rs: New test.

Signed-off-by: Harishankar <harishankarpp7@gmail.com>
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/testsuite/rust/compile/issue-3977.rs [new file with mode: 0644]