Skip to content

Conversation

@halalboro
Copy link

@halalboro halalboro commented Feb 9, 2026

Summary

  • Fix std::length_error: basic_string::_M_create crash in ep2c-opt when compiling nfchain.c with --target rtl
  • The crash occurred during the --ep2-pipeline-canon -ep2-handler-repl -ep2-global-to-partition pass pipeline

Root Cause
Operations were being erased while MLIR iterators still held references to them:

  1. HandlerReplicationPass.cpp: funcOp->erase() was called inside module->walk([&](ep2::FuncOp ...)), invalidating the walker's internal iterator. The freed memory was later accessed, producing corrupted string data and the std::length_error crash.
  2. GlobalToPartitionPass.cpp: global.erase() was called inside a for (auto global : moduleOp.getOps<GlobalOp>()) loop, similarly invalidating the iterator.
  3. Passes.h: HandlerFullName(std::string, std::string) stored StringRef members pointing into temporary std::string parameters. Changed to accept llvm::StringRef directly.

Fix
Defer all operation erasures to after the iteration completes, using a collection vector.

Testing
Successfully compiled tests/experiments_c/nfchain.c --target rtl end-to-end, producing __handler_NET_RECV_process_packet_1.sv and __ep2top.sv. Previously crashed every time at the ep2-handler-repl pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant