From 48aa71c3a7f5b8d9eb634c53e389c74dc29f7fe2 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 6 Jan 2025 11:02:51 +0000 Subject: [PATCH] gccrs: fix ICE during HIR dump These hir nodes have optional expressions which need guarded gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::do_qualifiedpathtype): add guard (Dump::do_traitfunctiondecl): likewise (Dump::visit): likewise Signed-off-by: Philip Herron --- gcc/rust/hir/rust-hir-dump.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index a6a880121a1d..112e129ea4ab 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -404,7 +404,8 @@ Dump::do_qualifiedpathtype (QualifiedPathType &e) do_mappings (e.get_mappings ()); visit_field ("type", e.get_type ()); - visit_field ("trait", e.get_trait ()); + if (e.has_as_clause ()) + visit_field ("trait", e.get_trait ()); } void @@ -521,7 +522,8 @@ Dump::do_traitfunctiondecl (TraitFunctionDecl &e) else put_field ("function_params", "empty"); - visit_field ("return_type", e.get_return_type ()); + if (e.has_return_type ()) + visit_field ("return_type", e.get_return_type ()); if (e.has_where_clause ()) put_field ("where_clause", e.get_where_clause ().as_string ()); @@ -1295,7 +1297,8 @@ Dump::visit (BreakExpr &e) else put_field ("label", "none"); - visit_field ("break_expr ", e.get_expr ()); + if (e.has_break_expr ()) + visit_field ("break_expr ", e.get_expr ()); end ("BreakExpr"); }