From: Pierre-Emmanuel Patry Date: Thu, 19 Sep 2024 12:38:48 +0000 (+0200) Subject: gccrs: Check if the type has been correctly resolved X-Git-Tag: basepoints/gcc-16~1173 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8bebc3bdd41fb86a3b4fa534820456719eaa79f;p=thirdparty%2Fgcc.git gccrs: Check if the type has been correctly resolved We did not check the optional was valid, this lead to rogue dereference and undefined behaviors. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add optional check. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc index 9ac09456fbd..068d231c6fb 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -23,6 +23,7 @@ #include "rust-default-resolver.h" #include "rust-name-resolution-context.h" #include "rust-path.h" +#include "rust-system.h" #include "rust-tyty.h" #include "rust-hir-type-check.h" @@ -223,9 +224,11 @@ Late::visit (AST::TypePath &type) // typepath-like path resolution? that sounds good auto resolved = ctx.types.get (type.get_segments ().back ()->as_string ()); - - ctx.map_usage (Usage (type.get_node_id ()), - Definition (resolved->get_node_id ())); + if (resolved) + ctx.map_usage (Usage (type.get_node_id ()), + Definition (resolved->get_node_id ())); + else + rust_unreachable (); } void