Skip to content

[AUTOMATED] Reconcile pointer slots with integer CAST results - #1249

Merged
mahaloz merged 10 commits into
Noelo-Lab:mainfrom
thotypous:fix/integer-to-pointer-slots
Oct 22, 2026
Merged

mahaloz merged 10 commits into
Noelo-Lab:mainfrom
thotypous:fix/integer-to-pointer-slots

Conversation

@thotypous

Copy link
Copy Markdown
Contributor

An asserted pointer member can receive an integer carrier without the cast C requires. A CAST statement can also retain an integer result type after its destination is declared as a pointer.

Run only the new independent fixture against an unmodified engine:

git fetch https://github.com/thotypous/kuna.git fix/integer-to-pointer-slots
git checkout FETCH_HEAD -- decompiler/crates/kuna-decomp/src/p9_emit/printc/tests/w10_printc_cast_render/pointer_assignments.rs
sed -i '/^mod w10_printc_cast_render {/a\    #[path = "pointer_assignments.rs"]\n    mod pointer_assignments;' decompiler/crates/kuna-decomp/src/p9_emit/printc/tests.rs
cd decompiler
cargo test -p kuna-decomp --lib integer_carriers_and_cast_results_assign_to_pointer_members -- --nocapture

Before: frame.slot = value; fails Clang with incompatible integer to pointer conversion.

The fixture renders real COPY/CAST statements and recompiles them with Clang for PE32 and native 64-bit C at -O0/-O2; the native executable checks pointer preservation. Existing pointer-to-integer slot cases remain controls.

thotypous and others added 9 commits October 21, 2026 10:23
The PE32 cases compiled the sample for i686-w64-windows-gnu with
`#include <stdint.h>`, which needs a MinGW sysroot; on a host whose clang
has no such headers the three PE32 tests failed instead of exercising
kuna. Use the compiler's builtin `__UINTPTR_TYPE__` so the freestanding
sample needs no target headers.

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

A pointer addition or member address assigned to integer storage still
printed without a cast (`frame[0] = &value[1];`), which gcc 15 and clang
reject. Treat PTRADD and PTRSUB statements like pointer copies.

A copied variable whose own declaration is an integer gained a redundant
cast (`cout = (unsigned long)cstart;` with `unsigned long cstart`); skip
it when the source variable is declared as a non-pointer. A null pointer
constant copied into integer storage now prints as `0` instead of
`(long)NULL`.

Adds two derived-pointer round-trip cases to the pointer-slot test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BEr111CDLJsQMzY3YSyWXD
…headers from the test

The fallback member lookup preferred the high's mapped Symbol type for every
variable. For a scalar local or global that type can differ from the type its
declaration prints (tar _help declares `unsigned long v50` but its Symbol is
`hol *`; a named global is declared at the type its accesses print), so the
pointer cast that Noelo-Lab#1241 added (`v50 = (unsigned long)v22;`,
`current_block = (long)v6;`) was dropped again and the C stopped compiling.
Use the Symbol type only when it is a structure, array or union, where the
declaration representative covers just the field.

The printer test now uses __UINTPTR_TYPE__ instead of <stdint.h>, so the
PE32 compile does not need a mingw sysroot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BEr111CDLJsQMzY3YSyWXD
…to fix/integer-to-pointer-slots

Resolve kuna_pointerstorecast.rs: match COPY, CAST, PTRADD and PTRSUB; keep
this branch's CAST result type, widened source filter and two-way tail; keep
Noelo-Lab#1241's early return for a COPY whose input is declared a non-pointer, but
only when the source is a pointer, so it does not block the integer-to-pointer
COPY case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BEr111CDLJsQMzY3YSyWXD
Resolve the kuna-cli integration.rs module list by keeping both sides.

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 three commits:

  • 2b79a8b: the fallback member lookup now takes the mapped Symbol type only when it is a structure, array or union. A scalar local or global can have a Symbol type that differs from its printed declaration. Using it dropped casts that [AUTOMATED] Cast pointer values assigned to integer frame members #1241 adds and broke compilation: tar -O2 _help declares unsigned long v50; but printed v50 = v22; with hol *v22, and the named global current_block printed current_block = v6; against extern unsigned long current_block;. The printer test also uses __UINTPTR_TYPE__ instead of <stdint.h>, so the PE32 compile no longer needs a mingw sysroot.
  • 1301bef: merged [AUTOMATED] Cast pointer values assigned to integer frame members #1241's current head. In kuna_pointerstorecast.rs the COPY early return for a non-pointer declared input now applies only when the source is a pointer.
  • 69ec4a3: merged origin/main. The only conflict was the integration.rs module list.

Noelo-Lab#1241 landed as a squash; this re-applies only Noelo-Lab#1249'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 71596af 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