]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix ICE on break with a label and a value
authorLucas Ly Ba <lucas.ly-ba@outlook.com>
Sat, 27 Jun 2026 19:15:51 +0000 (21:15 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 8 Jul 2026 15:22:49 +0000 (17:22 +0200)
A `break 'label value` expression looks up a temporary variable
associated with the labeled loop to hold the value, but labeled loops
never registered that temporary, leading to an ICE in the code
generator. Register the loop result temporary against the label.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Associate the loop
result temporary with the loop label.

gcc/testsuite/ChangeLog:

* rust/compile/break-label-loop.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
gcc/rust/backend/rust-compile-expr.cc
gcc/testsuite/rust/compile/break-label-loop.rs [new file with mode: 0644]

index 7fabc25a5f8b28049685700e1428bea7cd8c4f7c..79fe6c49e857e921f00fceb1338700d0a1b35199 100644 (file)
@@ -794,6 +794,10 @@ CompileExpr::visit (HIR::LoopExpr &expr)
       ctx->add_statement (label_decl);
       ctx->insert_label_decl (
        loop_label.get_lifetime ().get_mappings ().get_hirid (), label);
+      // Associate the loop's result temporary with the label so that a
+      // `break 'label value` can locate it (see visit (HIR::BreakExpr)).
+      ctx->insert_var_decl (
+       loop_label.get_lifetime ().get_mappings ().get_hirid (), tmp);
     }
 
   tree loop_begin_label
diff --git a/gcc/testsuite/rust/compile/break-label-loop.rs b/gcc/testsuite/rust/compile/break-label-loop.rs
new file mode 100644 (file)
index 0000000..60169e3
--- /dev/null
@@ -0,0 +1,10 @@
+// `break 'label loop {}` used to ICE in the code generator because the
+// labeled loop never registered its result temporary against the label.
+#![feature(no_core)]
+#![no_core]
+
+pub fn foo() {
+    'a: loop {
+        break 'a loop {};
+    }
+}