Skip to content

fraig_restore: stack overflow when a representative chain has a cycle longer than two - #556

Open
marcelwa wants to merge 1 commit into
berkeley-abc:masterfrom
marcelwa:u9-haig-cycle
Open

fraig_restore: stack overflow when a representative chain has a cycle longer than two#556
marcelwa wants to merge 1 commit into
berkeley-abc:masterfrom
marcelwa:u9-haig-cycle

Conversation

@marcelwa

@marcelwa marcelwa commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

We hit a reproducible SIGSEGV in fraig_restore and would like to check our reading of the code before calling it a bug. Abc_NtkHaigResetReprs (src/base/abci/abcHaig.c) normalises the pData representative chain and handles exactly two shapes, a self-loop and a two-node cycle — the comment there calls the second one "the strange situation of double-loop" — but the very next loop in the same function calls Hop_ObjRepr on every object, and Hop_ObjRepr recurses on pObj->pData until it reaches NULL or a self-loop, so a cycle of three or more recurses until the stack is gone and the process dies with no diagnostic; we see 521105 identical Hop_ObjRepr frames entered at abcHaig.c:478, by way of fraig_restore -> Abc_NtkFraigRestore -> Abc_NtkFraigPartitioned -> Abc_NtkPartStitchChoices -> Abc_NtkHopRemoveLoops. Attached is a reproducer that is three AIGER files derived from EPFL mem_ctrl and a four-line script (read_aiger; strash; fraig_store on each, then one fraig_restore): it exits with signal 11 on master at c6e8823 after about three minutes, it completes with this patch, and dropping any one of the three files makes it go away — the ingredient that seems to matter is that one of the stored networks is the re-strashed expansion of a cover that was mapped from an earlier fraig_restore's choice network, which gives a denser equivalence structure than a plain set of synthesis variants. The patch generalises the existing normalisation from cycles of length two to cycles of any length using Floyd's algorithm and breaks a detected cycle the way the two-node case already did, by making the meeting node its own representative; it is constant space, it sits inside a loop that already visits every object, and it is inert where there is no cycle — a single-round fraig_store/fraig_restore pipeline gives byte-identical mapped netlists with and without it (adder 212 LUTs / 84 levels, cavlc 111/6, i2c 258/7). Our question is whether a cycle longer than two is supposed to be impossible at this point: if it is, the real defect is wherever the chain gets built and this patch only hides it, and we would rather know that and close this.

Attachment archive

… two

`Abc_NtkHaigResetReprs` normalises the `pData` representative chain before walking it
with `Hop_ObjRepr`, and its normalisation handles a self-loop and a two-node cycle
("the strange situation of double-loop"). A cycle of three or more survives it, and
the very next loop calls `Hop_ObjRepr` on every object; `Hop_ObjRepr` recurses on
`pObj->pData` until it reaches NULL or a self-loop, so on a longer cycle it recurses
until the stack is gone and the process dies of SIGSEGV with no diagnostic.

Observed on `mem_ctrl` from the EPFL suite under a two-round `fraig_store`/
`fraig_restore` pipeline, where the second round's candidate set contains both freshly
synthesised AIGs and the strashed expansion of a cover mapped from the first round's
choice network. 521105 identical `Hop_ObjRepr` frames, entered from
`Abc_NtkHaigResetReprs` at abcHaig.c:478 by way of `fraig_restore` ->
`Abc_NtkFraigRestore` -> `Abc_NtkFraigPartitioned` -> `Abc_NtkPartStitchChoices` ->
`Abc_NtkHopRemoveLoops`.

Floyd's algorithm finds a cycle of any length in constant space. A detected cycle is
broken the way the two-node case was broken: the meeting node becomes its own
representative. With this change the same run completes in 337 s.

(cherry picked from commit 00e4b34)
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