Repository navigation
[AUTOMATED] fix: keep a narrowed argument's truncation at a call - #678
Merged
Merged
Conversation
mahaloz
force-pushed
the
fix/truncarg
branch
from
September 18, 2026 18:52
ca7e547 to
c10a8a0
Compare
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…n (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…tead of stacking casts (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
… (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…d-trip harness (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ence Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ion (WIP) A one-byte value of unknown type prints as char under realtypes, which C sign-extends, so a trimmed movzbl argument still printed a sign-extending value. Promotion now sees that spelling. Also skip the cast when the expression provably fits its unsigned range, and retype a truncation read only by call arguments. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…rinted as char (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…nd's push_back argument now carries its zero-extension (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…s diff (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
… known-zero bits (WIP) A narrow call input with no zero-extension evidence (a parameter clang forwards untouched, relying on the caller's extension) keeps its promoted form; the Rust output, which has no integer promotion, is left alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…es against a base kuna under gcc and clang (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ence; Rust output has no promotion (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…no zero-extension cast (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…with a clang corpus (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…e evidence-gated cast (WIP) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…e final build A narrowed call argument is cast only where its trim dropped known-zero bits, so a narrow parameter clang forwards untouched keeps its promoted form; Rust output is left alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…er rebase Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
mahaloz
force-pushed
the
fix/truncarg
branch
from
September 18, 2026 22:22
dbeed44 to
9c45d14
Compare
mahaloz
added a commit
that referenced
this pull request
Sep 18, 2026
…ect is fixed on main by #678 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A call argument narrower than
intthat the caller zero-extends loses its truncation in the printed C. kuna prints the bare expression, or a byte it spellschar, and C then promotes it toint, so the callee (which reads the whole register) gets a different value than the binary passes.The binary passes
0x6665fromf(movzx edi,di) and0x80fromg(movzbl 0x3(%rdi),%edi). The printed calls pass0x16665and0xffffff80. Upstream Ghidra prints the same promotedf.Fix
sink((unsigned short)(a0 * 3)),sink((unsigned char)*(char *)(a0 + 3)). The code is inp9_emit/kuna_truncarg.rs.mov %dil,acc8; jmp sinki), so the value there is whatever the caller extended, andsinki(a0)stays.realtypesprints it aschar. No cast is added when the value provably fits the unsigned range ((a != 2) + 6, or a variable set to(x == 0x55) + 2). An argument that already prints as a truncating cast is retyped instead of cast twice.docs/spec/09-emission.mdand03-ssa-and-simplification.md.Tests
tests/stages/kuna-truncarg.xmlhas twelve assertions. ite-region-converter-missing-5db28e: strip -fstack-protector canary e… #1-Recover PLT/GOT import names in ELF decompilation #4 and Perf/actionpool cursor #8 fail on main. docs: exhaustive remaining-analyzer backlog (eventually do them all) #11 and infra: dev container + cross-arch toolchains #12 use clang's bytes for a forwardedsigned charand must stay uncast. The rest cover cases that must not get a cast.docs/features/truncarg/roundtrip/roundtrip.sh <kuna> <base-kuna>compiles kuna's C for eleven callers and compares every value with the binary. Main gets 309 of 719 values wrong under both gcc and clang. This branch gets 0 wrong under gcc. Under clang it gets 10 wrong, all of them values main also gets wrong (a forwardedunsigned chartypedchar). No value is newly wrong.docs/features/truncarg/corpus-diff.txt): 28 gcc/MSVC binaries and a clang -O2 corpus (nginx plus 21 objects), 20,732 functions. The only change is 3,561 unsigned casts added at call arguments. No other text or JSON field changed. The typesweep rows are identical in all 444 slices. Speed deltas (min of 15, interleaved) are +0.0%, +1.0% and +1.0% on fmt, grep and diff.🤖 Generated with Claude Code
https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG