From 442a9698124b754114d910cf72c784ba7127c30a Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Mon, 13 Oct 2025 00:44:15 +0000 Subject: [PATCH] Ensure that `new_id(_suffix)()` cannot create collisions with existing `IdString`s. --- kernel/rtlil.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index a49b58cda..2610da665 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -23,6 +23,7 @@ #include "kernel/yosys_common.h" #include "kernel/yosys.h" +#include #include #include @@ -199,6 +200,16 @@ struct RTLIL::IdString if ((unsigned)ch <= (unsigned)' ') 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()); + if (p.substr(0, 6) == "$auto$") { + // Ensure new_id(_suffix) will not create collisions. + size_t autoidx_pos = p.find_last_of('$'); + int p_autoidx; + std::string_view v = p.substr(autoidx_pos + 1); + if (std::from_chars(v.begin(), v.end(), p_autoidx).ec == std::errc()) { + autoidx = std::max(autoidx, p_autoidx + 1); + } + } + #ifndef YOSYS_NO_IDS_REFCNT if (global_free_idx_list_.empty()) { log_assert(global_id_storage_.size() < 0x40000000);