Skip to content

Inline double parameter bound from memory: LOAD every 64-bit lvalue argument - #27

Merged
matgla merged 1 commit into
mobfrom
fix/inline-double-deref-arg-pair
Nov 20, 2026
Merged

matgla merged 1 commit into
mobfrom
fix/inline-double-deref-arg-pair

Conversation

@matgla

@matgla matgla commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Fixes an internal compiler error at -O1/-O2/-Os:

error: mach_make_hi_half: 64-bit REG operand has invalid r1=31 (r0=0) — register allocator must produce a valid pair

Minimal reproducer:

void g(double);
static void wn(double n) { g(n); }
void wv(const double *v) { wn(*v); }

Found while compiling cake (json.c, json_write_number(file, value->number)).

Cause

An inline expansion (here -finline-functions-called-once) binds each parameter with a STORE of the argument. A 64-bit lvalue argument (*p, s->d) left that STORE with a DEREF source, which the 64-bit STORE lowering can't split via mach_make_hi_half. call.c already loaded long long lvalue arguments into a temp first; double / long double skipped that step. The inline return path (stmt/block.c) already loads every lvalue, so the parameter binding was the only gap.

Fix

The pre-LOAD condition now uses tcc_is_64bit_type() instead of == VT_LLONG.

Tests

  • New bug_inline_double_deref_arg covers *p, struct member, p[i], long double, mixed int + double, and a parameter the callee modifies. It also checks the long long, float and by-value double cases, which already worked. Before the fix it failed at -O1/-O2/-Os; with the fix it passes at -O0/-O1/-O2/-Os.
  • make test-ir -j16: 18,203 passed (incl. mibench), 0 failed.
  • All 23 cake translation units compile at -O1/-O2/-Os.

🤖 Generated with Claude Code

…ue argument before its STORE

An inline expansion binds each parameter with a STORE of the argument.  A
64-bit lvalue argument (`*p`, `s->d`) left the STORE with a DEREF source,
which the 64-bit STORE lowering cannot split (mach_make_hi_half: invalid
r1=31 ICE at -O1/-O2/-Os).  call.c loaded long long arguments into a temp
first; double and long double now get the same LOAD.  Reached through
-finline-functions-called-once, e.g. cake's json_write_number(file,
value->number).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matgla
matgla merged commit 5fc05bc into mob Nov 20, 2026
3 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.

1 participant