Skip to content

Commit e27ac1f

Browse files
committed
hir-dump: Fix more segfaults in the HIR dump
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc: Check unique_ptr members are present before visiting them. * hir/tree/rust-hir-path.h: Add `has_{type, trait}` methods to QualifiedPathInType.
1 parent b5c354d commit e27ac1f

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

gcc/rust/hir/rust-hir-dump.cc

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ Dump::do_functionparam (FunctionParam &e)
315315
void
316316
Dump::do_pathpattern (PathPattern &e)
317317
{
318+
if (e.get_path_kind () == PathPattern::Kind::LangItem)
319+
{
320+
put_field ("segments", "#[lang = \""
321+
+ LangItem::ToString (e.get_lang_item_kind ())
322+
+ "\"]");
323+
return;
324+
}
325+
318326
std::string str = "";
319327

320328
for (const auto &segment : e.get_segments ())
@@ -402,9 +410,15 @@ void
402410
Dump::do_qualifiedpathtype (QualifiedPathType &e)
403411
{
404412
do_mappings (e.get_mappings ());
405-
visit_field ("type", e.get_type ());
413+
if (e.has_type ())
414+
visit_field ("type", e.get_type ());
415+
else
416+
put_field ("type", "none");
406417

407-
visit_field ("trait", e.get_trait ());
418+
if (e.has_trait ())
419+
visit_field ("trait", e.get_trait ());
420+
else
421+
put_field ("trait", "none");
408422
}
409423

410424
void
@@ -521,7 +535,10 @@ Dump::do_traitfunctiondecl (TraitFunctionDecl &e)
521535
else
522536
put_field ("function_params", "empty");
523537

524-
visit_field ("return_type", e.get_return_type ());
538+
if (e.has_return_type ())
539+
visit_field ("return_type", e.get_return_type ());
540+
else
541+
put_field ("return_type", "none");
525542

526543
if (e.has_where_clause ())
527544
put_field ("where_clause", e.get_where_clause ().as_string ());
@@ -1295,7 +1312,10 @@ Dump::visit (BreakExpr &e)
12951312
else
12961313
put_field ("label", "none");
12971314

1298-
visit_field ("break_expr ", e.get_expr ());
1315+
if (e.has_break_expr ())
1316+
visit_field ("break_expr ", e.get_expr ());
1317+
else
1318+
put_field ("break_expr", "none");
12991319

13001320
end ("BreakExpr");
13011321
}

gcc/rust/hir/tree/rust-hir-path.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,20 @@ class QualifiedPathType
641641

642642
Analysis::NodeMapping get_mappings () const { return mappings; }
643643

644+
bool has_type () { return type != nullptr; }
645+
bool has_trait () { return trait != nullptr; }
646+
644647
Type &get_type ()
645648
{
646649
rust_assert (type);
647650
return *type;
648651
}
649652

650-
TypePath &get_trait () { return *trait; }
653+
TypePath &get_trait ()
654+
{
655+
rust_assert (trait);
656+
return *trait;
657+
}
651658

652659
bool trait_has_generic_args () const;
653660

0 commit comments

Comments
 (0)