Skip to content

v1.0.5: bsearch execution stops after function call (inter-TU issue) #190

Description

@CTalkobt

Problem

After fixing optimizer regression in #183, emulator testing reveals bsearch still fails with a different root cause. Program execution stops immediately after the bsearch() call.

Reproduction

Test code:

#include <stdlib.h>

volatile unsigned char *test = (unsigned char *)0x4000;

int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
    test[0] = 0x11;           // ✓ WRITES CORRECTLY
    int arr[] = {10, 20, 30, 40, 50};
    void *found = bsearch(&arr[2], arr, 5, sizeof(int), cmp);
    test[1] = found ? 0xAA : 0xFF;  // ✗ NEVER EXECUTES
    test[2] = 0xFE;           // ✗ NEVER EXECUTES
    return 0;
}

Emulator result: 11 00 00 at $4000 (only first write executed, program stops)

Analysis

  • Optimizer return-value-load regression is FIXED (verified in binary)
  • Direct memory writes work correctly
  • bsearch call appears to crash/hang or not return properly
  • Suggests calling convention mismatch or inter-TU linking corruption

Related Issues

Labels

bugfix, v1.0.5, calling-convention, inter-TU-linking

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions