commit 96de8d734d0490c3e537ec6950c325e51015df59
parent 44b5521e6ab0bdb348582ec7fe080e7ff6e36704
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Sat, 6 Jun 2026 03:52:37 -0700
Fix C inline asm output type stack
Diffstat:
2 files changed, 3 insertions(+), 22 deletions(-)
diff --git a/doc/plan/TODO.md b/doc/plan/TODO.md
@@ -5,28 +5,6 @@ fixed, remove it instead of checking it off or keeping a closed entry.
Add new deferred fixes below as they are discovered.
-## x86-64 inline asm: `long` `"=r"` output stores as 4 bytes
-
-`KIT_TEST_ARCH=x64 KIT_OPT_LEVELS="0 1" KIT_PARSE_PARALLEL=0
-test/parse/run.sh cg_x64_inline_asm_mov R` fails in both O0 and O1 emit with
-`[1]:4:11: fatal: KitCg: store value type/size mismatch: access size 4, value
-size 8`.
-
-Minimal existing repro:
-
-```c
-int test_main(void) {
- long out;
- __asm__ volatile("movq %1, %0" : "=r"(out) : "r"(42));
- return out == 42 ? 42 : 1;
-}
-```
-
-The same failure masks new inline-asm constraint tests if they use `long` or
-`long long` outputs. The constraint classification is now arch-specific; this
-looks like the C frontend / CG store path is choosing a 4-byte output-lvalue
-access for an 8-byte asm result.
-
## x86-64 inline asm: `-g -O1` + a 4-operand register idiom → `too many memory asm operands` (compiler abort)
A register-pinned inline-asm syscall (4 operands: `rax`/`rdi`/`rsi`/`rdx` via GNU
diff --git a/lang/c/parse/cg_adapter.c b/lang/c/parse/cg_adapter.c
@@ -1211,4 +1211,7 @@ void pcg_inline_asm(Parser* p, const char* tmpl, const AsmConstraint* outs,
a.clobbers = cl;
a.nclobbers = nclob;
if (pcg_emit_enabled(p)) kit_cg_inline_asm(p->cg, a);
+ /* Mirror kit_cg_inline_asm's stack effect on the parser's typed shadow stack. */
+ for (u32 i = 0; i < nin; ++i) pcg_drop_type(p);
+ for (u32 i = 0; i < nout; ++i) pcg_push_type(p, outs[i].type);
}