aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/rust-hir-dump.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-12-20 18:00:48 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-24 13:07:10 +0100
commit2ab119672d428d5e00f333c652bf7a23847ac922 (patch)
treedc8d7fa12a3f7a8ad83b6d64f33035413d05f8d5 /gcc/rust/hir/rust-hir-dump.cc
parent051e54e5fcf0b0b852fef0c7f0e53e62b19a4176 (diff)
downloadgcc-2ab119672d428d5e00f333c652bf7a23847ac922.zip
gcc-2ab119672d428d5e00f333c652bf7a23847ac922.tar.gz
gcc-2ab119672d428d5e00f333c652bf7a23847ac922.tar.bz2
gccrs: 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.
Diffstat (limited to 'gcc/rust/hir/rust-hir-dump.cc')
-rw-r--r--gcc/rust/hir/rust-hir-dump.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 6861277..d495841 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -315,6 +315,14 @@ Dump::do_functionparam (FunctionParam &e)
void
Dump::do_pathpattern (PathPattern &e)
{
+ if (e.get_path_kind () == PathPattern::Kind::LangItem)
+ {
+ put_field ("segments", "#[lang = \""
+ + LangItem::ToString (e.get_lang_item ())
+ + "\"]");
+ return;
+ }
+
std::string str = "";
for (const auto &segment : e.get_segments ())
@@ -405,9 +413,12 @@ void
Dump::do_qualifiedpathtype (QualifiedPathType &e)
{
do_mappings (e.get_mappings ());
- visit_field ("type", e.get_type ());
+ if (e.has_type ())
+ visit_field ("type", e.get_type ());
+ else
+ put_field ("type", "none");
- if (e.has_as_clause ())
+ if (e.has_trait ())
visit_field ("trait", e.get_trait ());
}
@@ -527,6 +538,8 @@ Dump::do_traitfunctiondecl (TraitFunctionDecl &e)
if (e.has_return_type ())
visit_field ("return_type", e.get_return_type ());
+ else
+ put_field ("return_type", "none");
if (e.has_where_clause ())
put_field ("where_clause", e.get_where_clause ().as_string ());
@@ -1306,6 +1319,8 @@ Dump::visit (BreakExpr &e)
if (e.has_break_expr ())
visit_field ("break_expr ", e.get_expr ());
+ else
+ put_field ("break_expr", "none");
end ("BreakExpr");
}