Skip to content

sort() SIGSEGV: array_keys() result holds cell keys under a string[] return claim (whole-program only) #609

Closed

Description

@blacktrs

Symptom

sort() on the result of AnalyzeIndex::implementersOf() segfaults in manticore_sort$mono$p0_vec_str: the element word is NaN-boxed (0xfff4…) and is dereferenced as a string pointer.

frame #0 manticore_sort$mono$p0_vec_str + 5788   (ldr x9, [x8, #-0x8]!  x8 = 0xfff4007839079c98)
frame #1 manticore___closure_144                   (tests/semantic/index_incremental.php, check 'dependents_and_implementers')
frame #2 __mir_erinv_…
frame #3 manticore_SemTest_index_incremental_check

Cause (so far)

implementersOf() (/** @return string[] */) builds its result with array_keys($seen), and the IR fills it through __mir_array_key_cell_at, so the elements are CELLS. The caller trusts the string[] claim and calls the vec<str> specialisation of sort. Either the return must convert the elements to the claimed representation, or sort must not take the vec_str path for a buffer whose hint is cell.

Repro

Whole-program only: the same class and call sequence compiled alone pass. On the LSP stack (br lsp-server, rebased on main a04798c, with #608):

bash tests/semantic/run.sh -k index_incremental

A minimal repro will be attached when there is one.

Regression: this test passed on the stack before the rebase (main 3b44bde).

Activity

  1. added
    bug
    crash
    on Nov 9, 2026
  2. blacktrs commented on Nov 9, 2026

    @blacktrs
    ContributorAuthor

    Root cause: the stdlib bootstrap twin __mc_sort_native was compiled into the program, and Monomorphize repointed the call to __mc_sort_native$mono$p0_vec_str, so the emitter never asked the builtin. The twin returns false, and sort()'s PHP fallback read the cell words as strings. Single-file repro and fix: #611.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions