Skip to content

[AUTOMATED] feat(types): decode the rest of <data_organization> so scalar widths are knowable per target - #301

Merged
mahaloz merged 1 commit into
mainfrom
feat/dataorgsizes
Aug 16, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/dataorgsizes

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What

Architecture::decode_data_organization matched only integer_size / long_size / pointer_size / char_size / wchar_size. Everything else in the cspec's <data_organization> fell through its _ => {} arm:

tag vendored cspecs declaring it read before
<double_size> 61 no
<float_size> 60 no
<long_double_size> 56 no
<short_size> 54 no
<long_long_size> 51 no

So nothing downstream could tell one data model from another by more than a single long == 8 bool — and that is not enough to name a C type. An 8-byte integer is long under LP64 and long long under ILP32 or LLP64, and the fleet carries both: x86-64-gcc.cspec declares long_size 8, x86-64-win.cspec declares 4 with 8-byte pointers.

This PR adds the five widths as TypeFactory state, the matching decode arms, and setup_sizes fallbacks. It reads nothing back — it is the prerequisite for a per-architecture C type speller, split out so that change can be reviewed purely as a spelling change.

Notes for review

  • Trait accessors are defaulted (get_size_of_short() -> 2 etc.) so the several test-only TypeFactory stubs (p4_calls/modelrules/tests.rs, p4_calls/fspec/tests.rs) keep compiling; TypeFactoryImpl overrides each with the decoded value.
  • The fallbacks are the common case, not the exception. 37 of the 107 vendored cspecs carry no <data_organization> element at all — every PowerPC 32-bit one among them. A spec that declares no long double means the target aliases it to double (MSVC, ARM32), which is the fallback applied.
  • <long_double_size> is a value width, not sizeof. The x86 cspecs record 10 for the x87 extended format and annotate the storage width in a comment (<!-- aligned-length=16 -->). Consumers must treat it as an approximation to name, never as a layout guarantee — no sizeof assertion on a 10-byte float can hold on any target.
  • The existing size_of_long fallback is deliberately untouched. setup_sizes sets long = 8 whenever int == 4, which is wrong for MIPS32 and all six PPC32 cspecs. But get_size_of_long is read by type inference, not only by rendering, so correcting it changes decompiled output on those targets and belongs in its own measured PR.

Verification

Inert by construction — nothing reads the new fields. Confirmed rather than assumed: decompile-all output diffed against the pre-change build on four data models — fmt_x86_64 (85 lines), i386_pie_nl (3,800), fmt_arm (123), mips_gp_le32 (112) — 0 differing lines each.

New gate verify_dataorg_sizes pins the decoded tuple per data model, including the three cases a hard-coded 2/4/8 table gets wrong:

  • x86-64 SysV → (char 1, short 2, int 4, long 8, long long 8, ptr 8, float 4, double 8, long double 10) — LP64 with an x87 long double
  • i386 ELF → (1, 2, 4, 4, 8, 4, 4, 8, 10) — ILP32, so 8 bytes must spell long long
  • AArch64 / ARM32 → LP64 and ILP32 respectively

plus an invariant that no width ever decodes to 0 and long double >= double on every fixture.

Gates

  • make test — 675/675 PARITY OK
  • make test-stages — PARITY OK
  • make check-spec — green
  • make rust-test — run locally (internal PRs skip the workspace suite)

No option, no catalog row, no count bumps, no DIV row (nothing diverges yet).

🤖 Generated with Claude Code

https://claude.ai/code/session_01JyfU1KXNMWieY7HkFx2YbN

…alar widths are knowable per target

`Architecture::decode_data_organization` matched only integer_size / long_size /
pointer_size / char_size / wchar_size; `<short_size>` (54 vendored cspecs),
`<long_long_size>` (51), `<float_size>` (60), `<double_size>` (61) and
`<long_double_size>` (56) fell through its `_ => {}` arm. Nothing could ask for
them, so nothing downstream could tell an LP64 target from an LLP64 one by
anything other than a single `long == 8` bool -- which is not enough to name a
C type: an 8-byte integer is `long` under LP64 and `long long` under ILP32 or
LLP64, and the fleet carries both (x86-64 gcc long_size 8; x86-64 Windows
long_size 4 with 8-byte pointers).

Adds the five widths as TypeFactory state with defaulted trait accessors (so the
test-only TypeFactory stubs keep compiling), the matching cspec decode arms, and
`setup_sizes` fallbacks for the 37 of 107 cspecs that carry no
<data_organization> element at all -- every PowerPC 32-bit one among them. A
spec that declares no long double aliases it to double (MSVC, ARM32), which is
the fallback applied.

The existing `size_of_long` fallback (`long = 8 whenever int == 4`, wrong for
MIPS32 and every PPC32) is deliberately left alone: `get_size_of_long` is read
by type inference, not just by rendering, so correcting it changes decompiled
output and belongs in its own measured PR.

Inert by construction -- nothing reads the new fields yet. Verified: 0 differing
lines of `decompile-all` output on fmt_x86_64, i386_pie_nl, fmt_arm and
mips_gp_le32 against the pre-change build. No option, no catalog row, no count
bumps.

New gate `verify_dataorg_sizes` pins the decoded tuple per data model, including
the three cases a hard-coded 2/4/8 table gets wrong: LP64, ILP32, and the x87
long double (10 on x86 ELF, where no sizeof can ever match it).

Gates: make test 675/675 PARITY OK, make test-stages PARITY OK, make check-spec
green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01JyfU1KXNMWieY7HkFx2YbN
@mahaloz
mahaloz merged commit d9d3c85 into main Aug 16, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/dataorgsizes branch August 16, 2026 00:02
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