Skip to content

[Super Z] Fix 3 critical bugs (MEMSET/MEMCMP/ADDI), 58 new tests (39→97)#2

Open
SuperInstance wants to merge 1 commit intomainfrom
superz/bugfixes-and-tests
Open

[Super Z] Fix 3 critical bugs (MEMSET/MEMCMP/ADDI), 58 new tests (39→97)#2
SuperInstance wants to merge 1 commit intomainfrom
superz/bugfixes-and-tests

Conversation

@SuperInstance
Copy link
Copy Markdown
Owner

@SuperInstance SuperInstance commented Apr 12, 2026

Summary

Critical bug fixes and comprehensive test expansion for the FLUX C runtime:

3 Critical Bugs Fixed

  1. MEMSET memcpy offset — Second memcpy read from offset 0 instead of offset 4
  2. MEMCMP memcpy offset — Both addresses read from offset 0 (always compared against itself)
  3. ADDI (0x19) missing dispatch — Defined in enum but fell to INVALID_OPCODE

58 New Tests (39→97)

  • Float arithmetic (17): FADD/FSUB/FMUL/FDIV/FNEG/FABS/FMIN/FMAX/FEQ/FLT/FLE/FGT/FGE
  • Extended ops (22): ADDI, LOAD/STORE, SWAP/DUP, div-by-zero, bitwise, TEST/SETCC
  • Region ops (19): REGION_CREATE/DESTROY, heap read/write, BOX/UNBOX

Test Results: 97/97 — ALL PASSING


Super Z — Quartermaster Scout


Staging: Open in Devin

Bug fixes in src/vm.c:
- Fix MEMSET: removed redundant memcpy(&n,data,4) that duplicated
  the address offset before the correct memcpy(&n,data+4,4)
- Fix MEMCMP: changed memcpy(&b,data,4) to memcpy(&b,data+4,4)
  so 'b' reads from correct offset instead of copying same addr as 'a'
- Add ADDI (0x19) dispatch: opcode was defined in enum but fell to
  default INVALID_OPCODE error; now properly adds signed imm16 to GPR[rd]

Other fixes:
- Add missing #include <stdlib.h> in src/main.c for malloc/free
- Update Makefile with new test targets and clean rules

New test files (58 tests total):
- tests/test_float.c (17 tests): FADD, FSUB, FMUL, FDIV, FNEG, FABS,
  FMIN, FMAX, FEQ, FLT, FLE, FGT, FGE, FDIV-by-zero, cast roundtrip,
  chained float operations
- tests/test_extended.c (22 tests): ADDI (positive, negative, zero,
  chained, large imm), LOAD/STORE, SWAP, DUP, div-by-zero, mod-by-zero,
  MOV, TEST, OR, XOR, NOT, SHR, CMP_LT/GT/NE, LOAD8/STORE8
- tests/test_regions.c (19 tests): REGION_CREATE/DESTROY, heap
  read/write, CHECK_BOUNDS, BOX/UNBOX, CHECK_TYPE, RESOURCE ops,
  JLT/JGT, SETCC, LOOP, YIELD, DEBUG_BREAK

All 97 tests pass (22+5+12+17+22+19=97).
Copy link
Copy Markdown

@beta-devin-ai-integration beta-devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Staging: Open in Devin

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