public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Preserve inside_loop context when compiling match
@ 2022-06-08 12:42 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:42 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0472834ddf177038d343b193acab70b2859656f8

commit 0472834ddf177038d343b193acab70b2859656f8
Author: David Faust <david.faust@oracle.com>
Date:   Tue May 3 15:12:24 2022 -0700

    Preserve inside_loop context when compiling match

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.h     |  2 +-
 gcc/testsuite/rust/execute/torture/match_loop1.rs | 51 +++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 5633751c5a0..f1dff2cb0f2 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -1027,7 +1027,7 @@ public:
 
 	// check the kase type
 	TyTy::BaseType *kase_block_ty
-	  = TypeCheckExpr::Resolve (kase.get_expr ().get (), false);
+	  = TypeCheckExpr::Resolve (kase.get_expr ().get (), inside_loop);
 	kase_block_tys.push_back (kase_block_ty);
       }
 
diff --git a/gcc/testsuite/rust/execute/torture/match_loop1.rs b/gcc/testsuite/rust/execute/torture/match_loop1.rs
new file mode 100644
index 00000000000..d3aab6bc0bf
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/match_loop1.rs
@@ -0,0 +1,51 @@
+// { dg-output "E::One\nE::Two\nbreak!\n" }
+
+extern "C" {
+    fn printf(s: *const i8, ...);
+}
+
+enum E {
+    One,
+    Two,
+    Other
+}
+
+fn foo () {
+    let mut x = E::One;
+
+    loop {
+        match x {
+            E::One => {
+                let a = "E::One\n\0";
+                let b = a as *const str;
+                let c = b as *const i8;
+                printf (c);
+
+                x = E::Two;
+            }
+            E::Two => {
+                let a = "E::Two\n\0";
+                let b = a as *const str;
+                let c = b as *const i8;
+                printf (c);
+
+                x = E::Other;
+            }
+            _ => {
+                let a = "break!\n\0";
+                let b = a as *const str;
+                let c = b as *const i8;
+                printf (c);
+
+                break;
+            }
+        }
+    }
+}
+
+
+fn main () -> i32 {
+    foo ();
+
+    0
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:42 [gcc/devel/rust/master] Preserve inside_loop context when compiling match Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).