aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-03-28 18:59:33 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-31 21:07:27 +0200
commitc5d96fd5279fee47f455bd760fb0d1198a782e1e (patch)
tree2d8dfc329cec4d50df7b6884ac954d569bda852f
parent2d8f37c9a59ca5dd98dc77fc13fb83328adcf317 (diff)
downloadgcc-c5d96fd5279fee47f455bd760fb0d1198a782e1e.zip
gcc-c5d96fd5279fee47f455bd760fb0d1198a782e1e.tar.gz
gcc-c5d96fd5279fee47f455bd760fb0d1198a782e1e.tar.bz2
gccrs: Fix SEGV when type path resolver fails outright
When we resolve paths we resolve to Types first we walk each segment to the last module which has no type but then in the event that the child of a module is not found we have a null root_tyty which needs to be caught and turned into an ErrorType node. Fixes Rust-GCC#3613 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): catch nullptr root_tyty gcc/testsuite/ChangeLog: * rust/compile/issue-3613.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.cc7
-rw-r--r--gcc/testsuite/rust/compile/issue-3613.rs18
2 files changed, 25 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index e56fa39..54f50ec 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -360,6 +360,13 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
seg->as_string ().c_str ());
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
}
+ else if (root_tyty == nullptr)
+ {
+ rust_error_at (seg->get_locus (),
+ "unknown reference for resolved name: %qs",
+ seg->as_string ().c_str ());
+ return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
+ }
return root_tyty;
}
diff --git a/gcc/testsuite/rust/compile/issue-3613.rs b/gcc/testsuite/rust/compile/issue-3613.rs
new file mode 100644
index 0000000..f2e1092
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3613.rs
@@ -0,0 +1,18 @@
+mod m1 {
+ pub enum Baz4 {
+ foo1,
+ foo2,
+ }
+}
+
+fn bar(x: m1::foo) {
+ // { dg-error "unknown reference for resolved name: .foo." "" { target *-*-* } .-1 }
+ match x {
+ m1::foo::foo1 => {}
+ // { dg-error "failed to type resolve root segment" "" { target *-*-* } .-1 }
+ m1::NodePosition::foo2 => {}
+ // { dg-error "failed to type resolve root segment" "" { target *-*-* } .-1 }
+ }
+}
+
+pub fn main() {}