From b17e69852ea999547305b19e9c8da385f6c31e1e Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 27 Sep 2022 09:50:06 +0100 Subject: Fix missing dead code analysis ICE on local enum definition When resolving local enum's within a Block the name resolution info is not at the top of the stack so this patch introduces a new mappings class for miscellaneous name resolutions which can be used during path analaysis. Fixes #1272 --- gcc/rust/resolve/rust-name-resolver.cc | 20 ++++++++++++++++++++ gcc/rust/resolve/rust-name-resolver.h | 6 ++++++ 2 files changed, 26 insertions(+) (limited to 'gcc/rust/resolve') diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index fb70874..ba8c1a8 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -499,5 +499,25 @@ Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId) return true; } +void +Resolver::insert_resolved_misc (NodeId refId, NodeId defId) +{ + auto it = misc_resolved_items.find (refId); + rust_assert (it == misc_resolved_items.end ()); + + misc_resolved_items[refId] = defId; +} + +bool +Resolver::lookup_resolved_misc (NodeId refId, NodeId *defId) +{ + auto it = misc_resolved_items.find (refId); + if (it == misc_resolved_items.end ()) + return false; + + *defId = it->second; + return true; +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 014628a..3716bb0 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -126,6 +126,9 @@ public: void insert_resolved_macro (NodeId refId, NodeId defId); bool lookup_resolved_macro (NodeId refId, NodeId *defId); + void insert_resolved_misc (NodeId refId, NodeId defId); + bool lookup_resolved_misc (NodeId refId, NodeId *defId); + // proxy for scoping Scope &get_name_scope () { return name_scope; } Scope &get_type_scope () { return type_scope; } @@ -202,6 +205,9 @@ private: std::map resolved_labels; std::map resolved_macros; + // misc + std::map misc_resolved_items; + // keep track of the current module scope ids std::vector current_module_stack; }; -- cgit v1.1