Skip to content

Reject a nullptr in the FSM solver's state register and transition logic - #695

Merged
joern274 merged 2 commits into
masterfrom
fix/solve-fsm-nullptr-gates
Nov 27, 2026
Merged

joern274 merged 2 commits into
masterfrom
fix/solve-fsm-nullptr-gates

Conversation

@julianspeith

Copy link
Copy Markdown
Contributor

Problem

solve_fsm checks that the state register and the transition logic are not empty, but not what they contain.

  • A nullptr in the state register crashes HAL. This happens, for example, when a None is passed from Python. generate_state_bfs dereferences each flip-flop while building the next-state functions, so this segfaults no matter where in the list the nullptr is:

    cfg = solve_fsm.Configuration(netlist).with_state_register(ffs + [None]).with_transition_logic(logic)
    solve_fsm.solve_fsm(cfg)   # segfault
  • A nullptr in the transition logic doesn't crash, but the error doesn't point to it. It is only caught four levels down, when the subgraph function cache is built:

    failed to solve FSM: unable to generate the Boolean functions of the state.
     failed to generate boolean functions of state: could not generate subgraph function for state net 37.
     could not get subgraph function of net 'net_37' with ID 37
     could not create subgraph function cache
     subgraph contains a gate that is a 'nullptr'
    

Change

solve_fsm checks both lists up front, after the existing checks for empty lists. It returns an error that names the list and the index of the nullptr, the same way it already reports a nullptr net in an output:

failed to solve FSM: the flip-flop at index 2 of the state register is a nullptr.
failed to solve FSM: the gate at index 0 of the transition logic is a nullptr.

Testing

  • check_invalid_configuration now passes a nullptr at the start and at the end of each list, and checks that the error names the right index.
    • Without the fix, runTest-solve_fsm segfaults.
    • With the fix, all 8 tests pass.
  • From Python, on the fsm example with the debug build: a None at the start or end of the state register, or of the transition logic, now gives the errors above instead of crashing. The valid configuration still solves.
  • This PR merges cleanly with Fix the FSM solver for flip-flops that depend on their own state and for wide state registers #694, which also changes solve_fsm.cpp, its tests and the changelog. The merged result builds and passes all 11 tests.

🤖 Generated with Claude Code

solve_fsm checked that the state register and the transition logic are
not empty, but not what they contain. A nullptr in the state register,
e.g. a None passed from Python, was dereferenced while building the
next-state functions and crashed HAL. A nullptr in the transition logic
did not crash, but was only caught four levels down, by the subgraph
function cache, with an error that did not say where it came from.

Check both lists up front and name the index of the nullptr in the
error, as is already done for the nets of an output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AriKHaji
AriKHaji self-requested a review November 27, 2026 14:32
@joern274
joern274 merged commit 65f13a2 into master Nov 27, 2026
5 checks passed
@joern274
joern274 deleted the fix/solve-fsm-nullptr-gates branch November 27, 2026 15:20
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.

3 participants