Skip to content

Fix out-of-bounds accesses caught by debug-mode assertions - #2250

Merged
cqc-alec merged 1 commit into
Quantinuum:mainfrom
cleitonaugusto:fix/2199-glibcxx-assertions
Oct 1, 2026
Merged

cqc-alec merged 1 commit into
Quantinuum:mainfrom
cleitonaugusto:fix/2199-glibcxx-assertions

Conversation

@cleitonaugusto

Copy link
Copy Markdown
Contributor

Description

The two tests disabled in debug mode for #2199 abort because of real out-of-bounds accesses, not test issues. I reproduced both on GCC 11 by building with -D_GLIBCXX_ASSERTIONS, which is the check GCC 15 turns on in debug builds.

  • Partition, "No gadgets": get_partitioned_paulis_for_largest_first_method takes &colour_vec.front() of an empty vector when there are no terms. Changed to colour_vec.data(), which is valid for an empty vector and never read since there are no vertices to colour.
  • LinePlacement, "Empty circuit, two qubit Architecture": for an empty circuit interactions_to_lines returns one empty line, which is dropped and counted as an unused node, so remove_worst_nodes is asked to remove 3 nodes from a 2-node architecture. On the last iteration find_worst_node calls min_degree on an empty graph, and std::min_element returns the end iterator, which is then dereferenced. find_worst_node now returns std::nullopt when there are no nodes left, which remove_worst_nodes already handles.

Both tests are re-enabled in debug mode (the #ifdef NDEBUG guards are removed).

Checked locally:

  • With -D_GLIBCXX_ASSERTIONS, the full C++ suite passes. Reverting either fix on its own makes its test abort again.
  • Release C++ suite and full pytket suite pass.

Bumped TKET_VERSION to 2.1.103.

Related issues

Fixes #2199.

Checklist

  • I have performed a self-review of my code.
  • I have commented hard-to-understand parts of my code.
  • I have made corresponding changes to the public API documentation. (no API change)
  • I have added tests that prove my fix is effective or that my feature works. (re-enabled the existing tests)
  • I have updated the changelog with any user-facing changes.

With libstdc++ assertions enabled (as in debug builds with GCC 15), two
tests aborted:

- get_partitioned_paulis_for_largest_first_method took
  &colour_vec.front() of an empty vector when there are no terms. Use
  colour_vec.data(), which is valid for an empty vector.
- For an empty circuit, LinePlacement asks remove_worst_nodes to remove
  more nodes than the architecture has, and find_worst_node then calls
  min_degree on an empty graph, dereferencing the end iterator. Return
  std::nullopt from find_worst_node when there are no nodes left.

Re-enable both tests in debug mode. Fixes Quantinuum#2199.
@cqc-alec
cqc-alec self-requested a review October 1, 2026 14:30

@cqc-alec cqc-alec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@cqc-alec
cqc-alec merged commit c12dc5a into Quantinuum:main Oct 1, 2026
34 checks passed
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.

Some tests abort in debug mode on ubuntu-26.04

2 participants