Skip to content

Commit

Permalink
Check if the type has been correctly resolved
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
P-E-P committed Sep 19, 2024
1 parent 67bc0f6 commit 522576d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 522576d

Please sign in to comment.