[gcc r15-8380] gccrs: Check if the type has been correctly resolved
Arthur Cohen
cohenarthur@gcc.gnu.org
Wed Mar 19 14:41:26 GMT 2025
https://gcc.gnu.org/g:a8bebc3bdd41fb86a3b4fa534820456719eaa79f
commit r15-8380-ga8bebc3bdd41fb86a3b4fa534820456719eaa79f
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Sep 19 14:38:48 2024 +0200
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 <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
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 9ac09456fbd0..068d231c6fb3 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
More information about the Gcc-cvs
mailing list