Skip to content

[AUTOMATED] Preserve member representations in byte-copy helpers - #1247

Merged
mahaloz merged 6 commits into
Noelo-Lab:mainfrom
thotypous:fix/storage-load-transfer-types
Oct 22, 2026
Merged

mahaloz merged 6 commits into
Noelo-Lab:mainfrom
thotypous:fix/storage-load-transfer-types

Conversation

@thotypous

Copy link
Copy Markdown
Contributor

A byte-copy helper can turn an unaligned word copy into a numeric float conversion. A native input word of 1 then comes back as 1065353216 (1.0f bits).

cat > copy.c <<'C'
union block { float real[32]; unsigned integer[32]; } items;
__attribute__((naked)) unsigned transfer(unsigned index) {
 __asm__("movl 4(%esp),%eax; shll $2,%eax; movl _items+1(%eax),%edx;"
         "movl %edx,_items+64; flds _items+64; fstps _items+68;"
         "movl _items+64,%eax; retl");
}
C
clang --target=i686-w64-windows-gnu -O1 -c copy.c -o copy.obj
kuna decompile-project copy.obj -o output --option nanignore none \
 --option indexaliasguard full --option stackviews on \
 --assert 'typedef union block {float real[32];unsigned int integer[32];} block;' \
 --assert 'data 0x400028 block items' \
 --assert 'prototype _transfer unsigned int __cdecl transfer(unsigned int index)'
cat output/copy.obj.c

Before: items.real[0x10] = *(unsigned int *)__builtin_memcpy(&(unsigned int){0}, ...);

  • A statement LOAD copies into a compound literal with the rendered destination member’s same-width scalar type.
  • A STORE uses the rendered source member’s type for its compound initializer. Both paths preserve bytes instead of converting integer and float values.
  • Builds on [AUTOMATED] Preserve word bits through resolved union members #1244’s operation-facing member lookup.

Tests cover PE32 and ELF64, union and float-only declarations, strict Clang recompilation at -O0/-O2, and native ELF return values plus all 128 backing bytes across 4,096 finite patterns per configuration.

@thotypous

Copy link
Copy Markdown
Contributor Author

[AUTOMATED] Fixed the test-layout CI failure in 2325d60 by declaring the explicit #[path = "storage_load_transfers.rs"] suite registration. The current main-branch registration checker now passes against this checkout; the specification check passes too.

… differs

An iteregion diamond whose arms are byte-copy helper LOADs rendered
`dest = c ? *(unsigned int *)__builtin_memcpy(...) : ...`, so the
statement-LOAD retype never applied and the ternary still converted the
integer copy numerically into a float member. Decline the ternary when
an arm's destination member and helper type disagree on float-ness, so
each arm stays a statement LOAD that copies into the member's type.
Share the scalar filter between the LOAD and STORE paths and move the
inline comments into the function headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BEr111CDLJsQMzY3YSyWXD
@mahaloz

mahaloz commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed dac9fb2 on top of this branch. With the default iteregion ternary folding, a diamond whose two arms are byte-copy LOADs into a float member still printed items.real[0x10] = c ? *(unsigned int *)__builtin_memcpy(&(unsigned int){0},...) : .... The arms are not statement LOADs, so the retype here never applied and the integer copy was still converted numerically. The commit keeps that diamond as if/else when an arm's destination member and the helper type differ in float-ness, so each arm copies into float. It also adds a choose case to storage_load_transfers.rs (that case fails without the fix) and moves the inline comments into function headers.

Noelo-Lab#1244 landed as a squash; this re-applies only Noelo-Lab#1247's own changes on top
of main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BEr111CDLJsQMzY3YSyWXD
@mahaloz
mahaloz merged commit 84861c8 into Noelo-Lab:main Oct 22, 2026
2 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.

2 participants