Fix iterator invalidation crashes #3
+16
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
std::length_error: basic_string::_M_createcrash inep2c-optwhen compilingnfchain.cwith--target rtl--ep2-pipeline-canon -ep2-handler-repl -ep2-global-to-partitionpass pipelineRoot Cause
Operations were being erased while MLIR iterators still held references to them:
HandlerReplicationPass.cpp:funcOp->erase()was called insidemodule->walk([&](ep2::FuncOp ...)), invalidating the walker's internal iterator. The freed memory was later accessed, producing corrupted string data and thestd::length_errorcrash.GlobalToPartitionPass.cpp:global.erase()was called inside afor (auto global : moduleOp.getOps<GlobalOp>())loop, similarly invalidating the iterator.Passes.h:HandlerFullName(std::string, std::string)storedStringRefmembers pointing into temporarystd::stringparameters. Changed to acceptllvm::StringRefdirectly.Fix
Defer all operation erasures to after the iteration completes, using a collection vector.
Testing
Successfully compiled
tests/experiments_c/nfchain.c --target rtlend-to-end, producing__handler_NET_RECV_process_packet_1.svand__ep2top.sv. Previously crashed every time at theep2-handler-replpass.