Skip to content

[AUTOMATED] Keep the register width of a parameter forwarded to a call whose narrower result is returned - #2147

Open
phix33 wants to merge 1 commit into
Noelo-Lab:mainfrom
phix33:fix/forwarded-parameter-width-assertion
Open

phix33 wants to merge 1 commit into
Noelo-Lab:mainfrom
phix33:fix/forwarded-parameter-width-assertion

Conversation

@phix33

@phix33 phix33 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

On AArch64 a pointer that a function only hands on to a tail call prints as unsigned int when the callee returns 32 bits, and no 8-byte type can be asserted for it.

cat > fwd.c <<'SOURCE'
struct node { unsigned long key; unsigned int kind; unsigned int id; unsigned int flag; };
struct node *find(struct node *base, unsigned int kind, unsigned int id);

__attribute__((noinline)) unsigned int flag_of(struct node *base, unsigned int kind, unsigned int id)
{
    struct node *n = find(base, kind, id);
    return n ? n->flag : 2;
}

unsigned int enabled(struct node *base, unsigned int id)
{
    return flag_of(base, 1, id);
}
SOURCE
aarch64-linux-gnu-gcc -O2 -fPIC -shared -o fwd.so fwd.c
kuna decompile fwd.so enabled --assert-strict --assert 'typedef struct node;' --assert 'type a0 struct node *'
unsigned int enabled(unsigned int a0,unsigned int a1)
{
  return flag_of(a0,1,a1); // tail-call
}
warning: --assert "type a0 struct node *" rejected: Parameter type must occupy 4 bytes

enabled is mov w2,w1; mov w1,#1; b flag_of, so x0 reaches flag_of untouched. With this change the command exits 0 and prints void enabled(node *a0,unsigned int a1); the void is the existing loss of a tail-call result under an asserted parameter, as main prints around an 8-byte callee.

Fix

  • passthrough reads the callee's return register at each RETURN, at the callee's width. Here that is w0, the only mention of x0, so the call's argument trial was four bytes wide.
  • When every call that produces the result is a first call, each now gets a read of the whole register and its trial at claim time, before the first heritage, so nothing restarts.
  • No target gate: the result must be the low half of one general-purpose argument register. Joined pairs and float registers are left alone.
  • Where another call can precede a producing call, the function prints as before. No option.

Tests

  • kuna-passthrough-narrowret.xml over fwdwidth_a64.so and fwdwidth_arm.so (GCC, source above and variants): 17 assertions, 5 failing on main. Three CLI probes cover the strict assertion and two single-function cases.
  • Of 158,422 functions in 102 BusyBox builds on five architectures and 40 AArch64 libraries, nine change, each an AArch64 first parameter widened to its register.
  • A function the rule fires in takes two more heritage passes: +13.8% instructions on 3,000 such wrappers, flat on BusyBox.

Model: anthropic/claude-mythos-5-2

@phix33
phix33 force-pushed the fix/forwarded-parameter-width-assertion branch from 40f383d to 3c421cf Compare December 5, 2026 03:57

This branch has not been deployed

No deployments
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