[COMMITTED 20/43] gccrs: Address review feedback for straight-line BIR drop analysis
arthur.cohen@opensrcsec.com
arthur.cohen@opensrcsec.com
Thu Sep 10 08:19:33 GMT 2026
From: Lishin <lishin1008@gmail.com>
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-drop-analysis.cc
(BasicBlockIdHash): New helper.
(DropAnalysis::analyze): Use unordered_set for visited block tracking.
* checks/errors/borrowck/rust-bir-drop-analysis.h: Include rust-bir.h
directly and remove Function forward declaration.
* checks/errors/borrowck/rust-bir-place.h
(IndexVec::IndexVec): Add comment for sized constructor.
Signed-off-by: Lishin <lishin1008@gmail.com>
---
.../errors/borrowck/rust-bir-drop-analysis.cc | 16 +++++++++++++++-
.../errors/borrowck/rust-bir-drop-analysis.h | 3 +--
gcc/rust/checks/errors/borrowck/rust-bir-place.h | 1 +
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc
index c0de04fac2d..006b07f22a1 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc
@@ -19,14 +19,28 @@
#include "rust-bir-drop-analysis.h"
#include "rust-bir.h"
+#include <unordered_set>
+
namespace Rust {
namespace BIR {
+namespace {
+
+struct BasicBlockIdHash
+{
+ size_t operator() (BasicBlockId id) const
+ {
+ return std::hash<uint32_t> () (id.value);
+ }
+};
+
+} // namespace
+
void
DropAnalysis::analyze (Function &function)
{
std::vector<BasicBlockId> block_order;
- std::set<BasicBlockId> visited;
+ std::unordered_set<BasicBlockId, BasicBlockIdHash> visited;
BasicBlockId current = ENTRY_BASIC_BLOCK;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h
index eb63f1e1eda..c6298985a54 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h
@@ -19,11 +19,10 @@
#ifndef RUST_BIR_DROP_ANALYSIS_H
#define RUST_BIR_DROP_ANALYSIS_H
+#include "rust-bir.h"
namespace Rust {
namespace BIR {
-struct Function;
-
/*
Classifies scheduled whole-local BIR Drop statements according to
whether their place is initialized at the drop point.
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index d11ded9c9da..46b1f5dc896 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -209,6 +209,7 @@ template <typename I, typename T> class IndexVec
public:
IndexVec () = default;
+ // Creates `size` elements, instead of only reserving space.
IndexVec (size_t size) : internal_vector (size) {}
T &at (I pid) { return internal_vector[pid.value]; }
--
2.50.1
More information about the Gcc-rust
mailing list