Skip to content

[AUTOMATED] fix(cli): resolve every name/type assertion against the output it was shown - #789

Merged
mahaloz merged 5 commits into
mainfrom
fix/assert-two-local-names
Oct 1, 2026
Merged

mahaloz merged 5 commits into
mainfrom
fix/assert-two-local-names

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

The problem

Two --assert name directives on two different register locals each work alone, but in one run the second is rejected with No symbol named:, and reversing them reverses which one fails. A swap (name a b + name b a) was worse: both came back applied and nothing changed.

cat > t.s <<'EOF'
.globl two_locals, observe
.type two_locals,@function
.type observe,@function
two_locals: push %rbx; push %r12; sub $8,%rsp; xor %ebx,%ebx; mov $7,%r12d
1: add $1,%ebx; imul $3,%r12d,%r12d; add %ebx,%r12d; mov %ebx,%edi; mov %r12d,%esi
   call observe; cmp $4,%ebx; jl 1b
   lea (%rbx,%r12),%eax; add $8,%rsp; pop %r12; pop %rbx; ret
observe: ret
EOF
cc -c t.s && ld -e two_locals t.o -o t
kuna decompile t two_locals --assert 'prototype observe void observe(int index, int sum)' \
  --assert 'name index iteration' --assert 'name sum accumulator'
int two_locals(void)
{
  int iteration; // ebx
  int sum; // r12d
...
warning: --assert "name sum accumulator" rejected: No symbol named: sum

The fix

  • Naming a register local no longer clears the analysis, which emptied the variables every later directive looks its identifier up in. Both surfaces rebuild the IR from the scope for the second pass anyway.
  • An identifier now means the variable printed under it in the output the run started from, so directives on different locals work in any order and name a b + name b a swaps. An identifier that output does not contain may name what an earlier directive renamed a local to (name v1 rc then type rc unsigned int).
  • When an identifier is both a printed name and a name an earlier directive gave another local, the directive is rejected as ambiguous and names both locals: name v5 v4 then type v4 int gives Ambiguous name: v4 is both the local printed as v4 and the local printed as v5 (now v4). The exception is a name whose new name was also printed, as in a swap or rotation; it renames the local printed under the identifier.
  • The vN default for an untouched local now skips any name a name-locked Symbol holds. Before, after name v1 v3 + name v3 v1 an untouched third local also took v1 and the printer pushed the caller's v1 to v1_1.
  • The console rename/retype commands and the in-process (--json) path share one resolver.
  • Two register locals sharing a register at different widths (char *s // rax, uint4 v1 // eax) cannot both get a symbol: the second pass folds them into one variable (s._0_4_ = 0). The later directive is rejected and names the earlier one.

Behaviour changes beyond the fix:

  • After name v5 v4, main applied a later type v4 int or name v4 x to the local just renamed v4 (unless both were stack slots, where it rejected it); that batch is now rejected. name v1 v2 + name v2 v3, with v3 also printed, renames the local printed as v2, where main renamed the first local twice.
  • On the stack, name v2 credbuf then type v2 char[8] now retypes credbuf instead of being rejected.
  • Without any directive, a DWARF parameter or local named like a default (v1) is a name-locked Symbol too, so it keeps its name and the defaults skip it. Main printed uint1 v1; uint8 v1_1; for bash's size_t v1; now it is uint8 v1;. This renames locals in 5 of 3,107 bash O0 functions (names only); ls and sort at O2 and sdiff at O0 are byte-identical.
  • The calleenamedlocals stage's rename v2 v1 no longer collides (the caller's v1 stays on the slot it named); its collision coverage now renames both slots to w.

The tests

  • kuna-cli/tests/local_name_batch.rs on a new fixture (localnamebatch_x86_64, source beside it): the reported pair in both orders, three renames, stack, register and mixed pairs, swaps and a rotation among three locals, rename-then-retype, and the width, ambiguity and overlap rejections, each run through the text and --json surfaces. Everything except the stack-pair control fails on main. A DWARF fixture (dwarfvnames_x86_64, C source beside it) checks that a source v1 keeps its name.
  • tests/cli/two-register-local-names-in-one-batch.json: the reported case; fails on main.
  • calleenamedlocals Analysis-tier: MIPS16 ISA_MODE decode-mode painting #18/Analysis-tier: cross-arch _start→main idiom (AArch64/ARM/RISC-V) #19 (stages baseline re-recorded, two keys added) fail on main.

Fixes #784

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU

@mahaloz
mahaloz force-pushed the fix/assert-two-local-names branch 2 times, most recently from 97030d3 to 035c518 Compare October 1, 2026 19:38
@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Oct 1, 2026
mahaloz and others added 5 commits October 1, 2026 21:14
…utput it was shown

Two `--assert name` directives on two different register locals, each
accepted alone, rejected the second with `No symbol named:` in either
order: mapping the first local's Symbol cleared the analysis, which
emptied the HighVariables the next directive looks its identifier up in.

The pass is now left intact (both surfaces rebuild the IR from the scope
for the second pass anyway), and the Funcdata records every Symbol a
batch renamed, retyped or created, keyed by the identifier the pass
printed. An identifier first means the variable printed under it, so
directives on different locals no longer depend on their order and
`name a b` + `name b a` is a swap instead of a silent no-op; failing that
it means the variable an earlier directive gave that name. The console
`rename`/`retype` commands and the in-process plane share one resolver.

Fixes #784

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017cAUeUBnQ9xRA9oRJNGWjw
…ster in one batch

Giving two register locals that share a register at different widths
(`char *s // rax`, `uint4 v1 // eax`) a Symbol each made the second pass
fold them into one variable (`s._0_4_ = 0`). The later directive is now
rejected and names the one it lost to, which also lets the scope
container check go back to its original form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017cAUeUBnQ9xRA9oRJNGWjw
…enamed away and given away

Two holes in the batch rules:

- `name v2 tmp`, `name v1 v2`, `type v2 ...`: the printed reading of `v2`
  picked the local already renamed to `tmp`, silently. When the variable
  printed under an identifier was renamed away earlier in the batch and an
  earlier directive gave that identifier to another local, the directive
  is now rejected naming both.
- The vN allocator ignored name-locked Symbols, so after `name v1 v3` +
  `name v3 v1` an untouched local also took `v1` and the printer pushed
  the caller's `v1` to `v1_1`. Every default now skips a name a
  name-locked local Symbol holds; with no such Symbol the numbering is
  unchanged (byte-identical over 2,336 corpus functions).

calleenamedlocals' s4 relied on that collision: it now renames both slots
to `w` for the collision coverage, and asserts that `rename v2 v1` alone
leaves the caller's `v1` on the slot it named (#18, #19; stages baseline
re-recorded, two keys added). The console rename/retype commands get the
current function through one helper instead of a discarded read_symbol.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017cAUeUBnQ9xRA9oRJNGWjw
… another local

After `name v5 v4`, a later `type v4 int` or `name v4 x` named two locals:
the one printed as v4 and the one just renamed to v4. The printed one was
picked silently, where main had applied the directive to the renamed one.
Both readings now reject as ambiguous, naming both locals. A `name` whose new
name the pass also printed still takes the printed reading, so swaps and
rotations keep working.

Adds a stack+register pair to the batch fixture, and a DWARF fixture showing
that a source local or parameter named `v1` keeps its name now that default
numbering skips name-locked Symbols.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
`name v1 v2` then `name v2 v2` named both locals `v2` through the swap
exemption; it is now rejected as ambiguous like any other reuse.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
@mahaloz
mahaloz force-pushed the fix/assert-two-local-names branch from 9f8f7cf to dc60805 Compare October 1, 2026 21:18
@mahaloz
mahaloz merged commit f5333b8 into main Oct 1, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/assert-two-local-names branch October 1, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AUTOMATED] Two independent register-local name assertions invalidate the second lookup

1 participant