]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Check if the type has been correctly resolved
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 19 Sep 2024 12:38:48 +0000 (14:38 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:11 +0000 (15:32 +0100)
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 <pierre-emmanuel.patry@embecosm.com>
gcc/rust/resolve/rust-late-name-resolver-2.0.cc

index 9ac09456fbd0eb47e90f9a0343270e0b5ab9f49a..068d231c6fb38b4fc948c8c7c7c5a238f9278ac4 100644 (file)
@@ -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