Skip to content

transpile: rewrite relooper to be iterative to avoid stack overflow on large CFGs - #1995

Open
Hellboy28D wants to merge 1 commit into
immunant:masterfrom
Hellboy28D:iterative-relooper
Open

transpile: rewrite relooper to be iterative to avoid stack overflow on large CFGs#1995
Hellboy28D wants to merge 1 commit into
immunant:masterfrom
Hellboy28D:iterative-relooper

Conversation

@Hellboy28D

Copy link
Copy Markdown

Summary

The relooper in c2rust-transpile used a recursive algorithm for control-flow
reconstruction. On functions with very large/deep CFGs (e.g. thousands of
sequential basic blocks, as in the BLAKE-256 example in #1821), this could
exhaust the stack and crash the transpiler.

This PR rewrites the relooper to work iteratively, using an explicit
dominator computation instead of recursion, so structured control-flow
reconstruction no longer depends on stack depth proportional to CFG size.

Changes

  • Replaced the recursive relooper implementation in
    c2rust-transpile/src/cfg/relooper.rs with an iterative one
  • Added unit tests for the dominator computation

Testing

  • cargo test -p c2rust-transpile relooper — all 7 new dominator tests pass
  • Transpiled the BLAKE-256 C implementation from Reworked relooper regressed on some large CFGs #1821: output is
    byte-identical to the output produced by upstream master, confirming the
    rewrite preserves translation semantics
  • Transpiles previously-failing large-CFG inputs without requiring an
    increased ulimit -s

Notes

Happy to adjust the approach or add more tests based on maintainer feedback.

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