Skip to content

Commit b067518

Browse files
committed
Ensure that new_id(_suffix)() cannot create collisions with existing IdStrings.
1 parent aa99660 commit b067518

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kernel/rtlil.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "kernel/yosys_common.h"
2424
#include "kernel/yosys.h"
2525

26+
#include <charconv>
2627
#include <string_view>
2728
#include <unordered_map>
2829

@@ -208,6 +209,16 @@ struct RTLIL::IdString
208209
if ((unsigned)ch <= (unsigned)' ')
209210
log_error("Found control character or space (0x%02x) in string '%s' which is not allowed in RTLIL identifiers\n", ch, std::string(p).c_str());
210211

212+
if (p.substr(0, 6) == "$auto$") {
213+
// Ensure new_id(_suffix) will not create collisions.
214+
size_t autoidx_pos = p.find_last_of('$');
215+
int p_autoidx;
216+
std::string_view v = p.substr(autoidx_pos + 1);
217+
if (std::from_chars(v.begin(), v.end(), p_autoidx).ec == std::errc()) {
218+
autoidx = std::max(autoidx, p_autoidx + 1);
219+
}
220+
}
221+
211222
#ifndef YOSYS_NO_IDS_REFCNT
212223
if (global_free_idx_list_.empty()) {
213224
log_assert(global_id_storage_.size() < 0x40000000);

0 commit comments

Comments
 (0)