[gcc r14-7668] gccrs: Fix ICE for reference patterns in match statements

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 17:52:09 GMT 2024


https://gcc.gnu.org/g:e22e94ddb62cc83c0f1c8b81472aa0a05c1f8850

commit r14-7668-ge22e94ddb62cc83c0f1c8b81472aa0a05c1f8850
Author: Dave Evans <dave@dmetwo.org>
Date:   Thu Jun 8 19:18:42 2023 -0500

    gccrs: Fix ICE for reference patterns in match statements
    
    gcc/rust/ChangeLog:
    
            * backend/rust-compile-expr.cc (check_match_scrutinee): Add REF type to rust_assert.
            (CompileExpr::visit): Add REF type for scrutinee_kind in MatchExpr visitor.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-1813.rs: New test.
    
    Signed-off-by: Dave Evans <dave@dmetwo.org>

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc    | 9 ++++++++-
 gcc/testsuite/rust/compile/issue-1813.rs | 9 +++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 5152c99362f..9daad0ad7f3 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1274,7 +1274,8 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx)
   rust_assert ((TyTy::is_primitive_type_kind (scrutinee_kind)
 		&& scrutinee_kind != TyTy::TypeKind::NEVER)
 	       || scrutinee_kind == TyTy::TypeKind::ADT
-	       || scrutinee_kind == TyTy::TypeKind::TUPLE);
+	       || scrutinee_kind == TyTy::TypeKind::TUPLE
+	       || scrutinee_kind == TyTy::TypeKind::REF);
 
   if (scrutinee_kind == TyTy::TypeKind::ADT)
     {
@@ -1362,6 +1363,12 @@ CompileExpr::visit (HIR::MatchExpr &expr)
 	  scrutinee_first_record_expr, 0,
 	  expr.get_scrutinee_expr ()->get_locus ());
     }
+  else if (scrutinee_kind == TyTy::TypeKind::REF)
+    {
+      tree indirect
+	= indirect_expression (match_scrutinee_expr, expr.get_locus ());
+      match_scrutinee_expr_qualifier_expr = indirect;
+    }
   else if (scrutinee_kind == TyTy::TypeKind::TUPLE)
     {
       // match on tuple becomes a series of nested switches, with one level
diff --git a/gcc/testsuite/rust/compile/issue-1813.rs b/gcc/testsuite/rust/compile/issue-1813.rs
new file mode 100644
index 00000000000..6d35d45b170
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1813.rs
@@ -0,0 +1,9 @@
+fn main() {
+    let a = 15u8;
+    let a = &a;
+    match a {
+        &15 => {}
+        &14 => {}
+        _ => {}
+    }
+}


More information about the Gcc-cvs mailing list