Skip to content

Commit ac5abbd

Browse files
CohenArthurP-E-P
authored andcommitted
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 1361615 commit ac5abbd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Diff for: gcc/rust/hir/rust-hir-dump.cc

+17-2
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 ())
322+
+ "\"]");
323+
return;
324+
}
325+
318326
std::string str = "";
319327

320328
for (const auto &segment : e.get_segments ())
@@ -405,9 +413,12 @@ void
405413
Dump::do_qualifiedpathtype (QualifiedPathType &e)
406414
{
407415
do_mappings (e.get_mappings ());
408-
visit_field ("type", e.get_type ());
416+
if (e.has_type ())
417+
visit_field ("type", e.get_type ());
418+
else
419+
put_field ("type", "none");
409420

410-
if (e.has_as_clause ())
421+
if (e.has_trait ())
411422
visit_field ("trait", e.get_trait ());
412423
}
413424

@@ -527,6 +538,8 @@ Dump::do_traitfunctiondecl (TraitFunctionDecl &e)
527538

528539
if (e.has_return_type ())
529540
visit_field ("return_type", e.get_return_type ());
541+
else
542+
put_field ("return_type", "none");
530543

531544
if (e.has_where_clause ())
532545
put_field ("where_clause", e.get_where_clause ().as_string ());
@@ -1306,6 +1319,8 @@ Dump::visit (BreakExpr &e)
13061319

13071320
if (e.has_break_expr ())
13081321
visit_field ("break_expr ", e.get_expr ());
1322+
else
1323+
put_field ("break_expr", "none");
13091324

13101325
end ("BreakExpr");
13111326
}

Diff for: gcc/rust/hir/tree/rust-hir-path.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,20 @@ class QualifiedPathType
733733

734734
Analysis::NodeMapping get_mappings () const { return mappings; }
735735

736+
bool has_type () { return type != nullptr; }
737+
bool has_trait () { return trait != nullptr; }
738+
736739
Type &get_type ()
737740
{
738741
rust_assert (type);
739742
return *type;
740743
}
741744

742-
TypePath &get_trait () { return *trait; }
745+
TypePath &get_trait ()
746+
{
747+
rust_assert (trait);
748+
return *trait;
749+
}
743750

744751
bool trait_has_generic_args () const;
745752

0 commit comments

Comments
 (0)