aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-04-12 13:54:11 +0100
committerGitHub <noreply@github.com>2021-04-12 13:54:11 +0100
commitdc6453b720c484f9ab92e1f1a81f890912979e08 (patch)
treed90a9c60ece3c1ffc93f5781f70562297946fd0a
parentfc15105643078b014cb8b9d499b72cdf13600a6a (diff)
parent5b35329abbcfcf14b1cec0362c44749b3b3511ed (diff)
downloadnextpnr-dc6453b720c484f9ab92e1f1a81f890912979e08.tar.gz
nextpnr-dc6453b720c484f9ab92e1f1a81f890912979e08.tar.bz2
nextpnr-dc6453b720c484f9ab92e1f1a81f890912979e08.zip
Merge pull request #673 from YosysHQ/gatecat/fix-fast-bels-ref
fast_bels: Don't return pointer that might become invalid
-rw-r--r--common/fast_bels.h32
1 files changed, 18 insertions, 14 deletions
diff --git a/common/fast_bels.h b/common/fast_bels.h
index be2852cd..0425f92a 100644
--- a/common/fast_bels.h
+++ b/common/fast_bels.h
@@ -54,6 +54,8 @@ struct FastBels
fast_bels_by_cell_type.resize(type_idx + 1);
auto &bel_data = fast_bels_by_cell_type.at(type_idx);
+ NPNR_ASSERT(bel_data.get() == nullptr);
+ bel_data = std::make_unique<FastBelsData>();
for (auto bel : ctx->getBels()) {
if (!ctx->isValidBelForCellType(cell_type, bel)) {
@@ -77,15 +79,15 @@ struct FastBels
loc.x = loc.y = 0;
}
- if (int(bel_data.size()) < (loc.x + 1)) {
- bel_data.resize(loc.x + 1);
+ if (int(bel_data->size()) < (loc.x + 1)) {
+ bel_data->resize(loc.x + 1);
}
- if (int(bel_data.at(loc.x).size()) < (loc.y + 1)) {
- bel_data.at(loc.x).resize(loc.y + 1);
+ if (int(bel_data->at(loc.x).size()) < (loc.y + 1)) {
+ bel_data->at(loc.x).resize(loc.y + 1);
}
- bel_data.at(loc.x).at(loc.y).push_back(bel);
+ bel_data->at(loc.x).at(loc.y).push_back(bel);
}
}
@@ -103,6 +105,8 @@ struct FastBels
fast_bels_by_partition_type.resize(type_idx + 1);
auto &bel_data = fast_bels_by_partition_type.at(type_idx);
+ NPNR_ASSERT(bel_data.get() == nullptr);
+ bel_data = std::make_unique<FastBelsData>();
for (auto bel : ctx->getBels()) {
if (ctx->getBelBucketForBel(bel) != partition) {
@@ -126,15 +130,15 @@ struct FastBels
loc.x = loc.y = 0;
}
- if (int(bel_data.size()) < (loc.x + 1)) {
- bel_data.resize(loc.x + 1);
+ if (int(bel_data->size()) < (loc.x + 1)) {
+ bel_data->resize(loc.x + 1);
}
- if (int(bel_data.at(loc.x).size()) < (loc.y + 1)) {
- bel_data.at(loc.x).resize(loc.y + 1);
+ if (int(bel_data->at(loc.x).size()) < (loc.y + 1)) {
+ bel_data->at(loc.x).resize(loc.y + 1);
}
- bel_data.at(loc.x).at(loc.y).push_back(bel);
+ bel_data->at(loc.x).at(loc.y).push_back(bel);
}
}
@@ -151,7 +155,7 @@ struct FastBels
auto cell_type_data = iter->second;
- *data = &fast_bels_by_cell_type.at(cell_type_data.type_index);
+ *data = fast_bels_by_cell_type.at(cell_type_data.type_index).get();
return cell_type_data.number_of_possible_bels;
}
@@ -166,7 +170,7 @@ struct FastBels
auto type_data = iter->second;
- *data = &fast_bels_by_partition_type.at(type_data.type_index);
+ *data = fast_bels_by_partition_type.at(type_data.type_index).get();
return type_data.number_of_possible_bels;
}
@@ -175,10 +179,10 @@ struct FastBels
const int minBelsForGridPick;
std::unordered_map<IdString, TypeData> cell_types;
- std::vector<FastBelsData> fast_bels_by_cell_type;
+ std::vector<std::unique_ptr<FastBelsData>> fast_bels_by_cell_type;
std::unordered_map<BelBucketId, TypeData> partition_types;
- std::vector<FastBelsData> fast_bels_by_partition_type;
+ std::vector<std::unique_ptr<FastBelsData>> fast_bels_by_partition_type;
};
NEXTPNR_NAMESPACE_END