]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
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)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Thu, 19 Sep 2024 13:16:16 +0000 (13:16 +0000)
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 995c022fbed7a4145c3f66ccfe8e196de85524c8..f171f14429c30f0ed61636ed094a8f23074ee499 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