]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix crash in hir dump with missing guards
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 25 Nov 2024 20:16:42 +0000 (20:16 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:33:03 +0000 (12:33 +0100)
gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add missing null checks

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/hir/rust-hir-dump.cc

index 1b48b294008ccd4b70bfc5a405f2d1fcdc26aa82..be785b9ebec20364307eadf0fc7c8b2d7a3fe44c 100644 (file)
@@ -1892,7 +1892,8 @@ Dump::visit (TraitItemFunc &e)
 
   do_traitfunctiondecl (e.get_decl ());
 
-  visit_field ("block_expr", e.get_block_expr ());
+  if (e.has_definition ())
+    visit_field ("block_expr", e.get_block_expr ());
 
   end ("TraitItemFunc");
 }
@@ -2007,7 +2008,8 @@ Dump::visit (ExternalFunctionItem &e)
 
   put_field ("has_variadics", std::to_string (e.is_variadic ()));
 
-  visit_field ("return_type", e.get_return_type ());
+  if (e.has_return_type ())
+    visit_field ("return_type", e.get_return_type ());
 
   end ("ExternalFunctionItem");
 }
@@ -2254,8 +2256,10 @@ Dump::visit (LetStmt &e)
 
   put_field ("variable_pattern", e.get_pattern ().as_string ());
 
-  visit_field ("type", e.get_type ());
-  visit_field ("init_expr", e.get_init_expr ());
+  if (e.has_type ())
+    visit_field ("type", e.get_type ());
+  if (e.has_init_expr ())
+    visit_field ("init_expr", e.get_init_expr ());
 
   end ("LetStmt");
 }