]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ice with invalid borrow expression
authorPhilip Herron <herron.philip@googlemail.com>
Tue, 8 Jul 2025 21:33:02 +0000 (22:33 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:54 +0000 (16:36 +0200)
This is an invalid test case but we just need a guard for the missing
borrow expression.

Fixes Rust-GCC#3874

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): check for missing borrow
* ast/rust-expr.h: add helper

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ast/rust-ast-collector.cc
gcc/rust/ast/rust-expr.h
gcc/testsuite/rust/compile/issue-3874.rs [new file with mode: 0644]

index 0b5f27d36d2ce45de39607c8ae17d529584516c1..4fe246d7a3ada05e7e611db0c0b8c47a7df5acaa 100644 (file)
@@ -870,7 +870,8 @@ TokenCollector::visit (BorrowExpr &expr)
        push (Rust::Token::make (MUT, UNDEF_LOCATION));
     }
 
-  visit (expr.get_borrowed_expr ());
+  if (expr.has_borrow_expr ())
+    visit (expr.get_borrowed_expr ());
 }
 
 void
index 3e50c46e58deaeb0943f83063403c8229fac187d..296821131b1e2f23a4928ac54b9e29096b7b2a54 100644 (file)
@@ -395,6 +395,8 @@ public:
     return *main_or_left_expr;
   }
 
+  bool has_borrow_expr () const { return main_or_left_expr != nullptr; }
+
   bool get_is_mut () const { return mutability == Mutability::Mut; }
 
   Mutability get_mutability () const { return mutability; }
diff --git a/gcc/testsuite/rust/compile/issue-3874.rs b/gcc/testsuite/rust/compile/issue-3874.rs
new file mode 100644 (file)
index 0000000..ebce4b6
--- /dev/null
@@ -0,0 +1,4 @@
+fn wow(){
+    &#[serde]
+    // { dg-error "found unexpected token .#. in null denotation" "" { target *-*-* } .-1 }
+}