cpu: pass bounded frame-slot pointers to internal callees in cpu_switch_aot #3121
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3121
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3121"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ammmae0x on GitHub · 2026-11-27 16:07 UTC · original
Ammmae0x:cpu/switch-frame-ptr-callees→main· +1905 −11 · 6 files · 5 commits · merged 2026-11-29 17:48 UTCChange
Extend
tools/cpu_switch_aot.pyso bounded, non-recursive internal callees that read or write a single fixed-width scalar (1, 2, 4, or 8 bytes) through an argument register (RCX/RDX/R8/R9) without pointer escape can receive a proven frame-slot address viaLEA reg, [rsp+disp]or[rbp+disp](under a proven frame anchor). Refs #317.analyze_pointer_param,_step_ptr_instruction,_check_ptr_mem,PointerParam): tracks non-escaping 64-bit scalar pointer flow across copies, nested non-recursive internal callees, and control-flow joins; computes(width, reads_before_write, must_write, may_write)across all normal exits (RETand tail jumps), rejecting escapes (return inRAX, memory/stack stores, pointer arithmetic, displaced/indexedLEAor memory operands, 32-bit[ecx]addressing, registerBT*,MOVS/STOS,SIGN_EXTENSIONS, one-operandMUL/DIV, 32-bit/16-bitCMOVcctruncation,COND_WRITEsuch asBSF/BSRon a live pointer destination, 8/16-bit partial overwrites, recursive/cyclic callees, mixed widths, and unaccessed pointer parameters).Frame,prove_frame): only treatsRBP-basedLEAas a frame pointer when a frame anchor is proven (preserving non-anchorRBPinteger arithmetic); validates pointed bytes stay within[frame.offsets[ip] + HOME_SIZE + 8*len(stack_args), frame.end), never overlap return address or callee home space/stack args, and never alias across multiple pointer arguments; enforces caller initialization before anyreads_before_writecallee and marks written bytes defined aftermust_write(or preserves/clears saved-register markers conservatively onmay_write).HostImport --stack-outputis unchanged.tests/cpu/switch_frame_ptr.asm,tests/cpu/switch_frame_ptr.def,tests/cpu/switch_frame_ptr_check.py,tests/cmake/cpu_switch_frame_ptr.cmake,docs/experiments.md): adds 4 differential exports (out_u32_rsp,rmw_u64_rbp,all_widths_and_regs,non_anchor_rbp_arith) across 313 input pairs at both/Odand/O2, 2 compiled C++ mutants, 2 Python guard mutations, and 49 refusal negative controls (44 exercising the new pointer-parameter/aliasing/bounds/saved-slot/incoming-slot rules and 5 caught by main's existing frame/tail/anchor checks).Guard -> Red Control Table
READS)neg_escape_store_mem(plus_store_stack,neg_ptr_arith)neg_callee_tail_ptr_livelen(live_args) > 1)neg_nested_multi_livenested is None)neg_nested_int_calleeLEAzero-displacement / zero-index guardneg_lea_disp_calleeLEA64-bit base guard (RegisterExt.is_gpr64(ins.memory_base))neg_lea_ecx_calleemerged[r] = 2) +_check_ptr_memstate-1 requirementneg_join_maybe_ptr_calleecheck_memdisplacement / index / 64-bit base /BIT_TESTSguardsneg_mem_disp_callee,neg_mem_index_callee,neg_mem_ecx_callee,neg_bit_test_reg_calleeCMOVccmemory-form 32-bit truncation (w_reg != 8)neg_cmov32_mem_calleeSTRING_TRANSFERS(STOS/MOVS),SIGN_EXTENSIONS,MUL/DIV,<4Bpartial writesneg_stos_ptr_rax,neg_sign_ext_callee,neg_mul_ptr_callee,neg_bsf_cond_write_escapemay_writeclearing saved-register slot markersneg_may_write_saved_regmin_offsetstack-argument size & incoming stack-slot demand propagationneg_callee_stack_arg_overlap,neg_incoming_stack_slot_uninitneg_multi_arg_alias_same,neg_multi_arg_alias_overlapVerification
Verified on commit
2a685c06inliaisonworktree on Windows x64 (MSVC 19.50.35727.0):ctest --preset dev -N-> 2929 tests including#2497: cpu_switch_frame_ptr.cmake --build --preset dev&release(affected 7 test targets) -> exit 0 (0 errors, 0 warnings).ctest --preset dev --no-tests=error -R "^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$" -E "cpu_native_archive_" --output-on-failure-> 7/7 passed (exit 0).ctest --preset release --no-tests=error -R "^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$" -E "cpu_native_archive_" --output-on-failure-> 7/7 passed (exit 0).out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py,tests/docs_links_check.py(154 md / 676 links),tests/bidi_controls_check.py(2537 files) -> all exit 0.Evidence and follow-up
All fixtures (
tests/cpu/switch_frame_ptr.asm,.def,_check.py) are source-owned under this repository; no external binaries or game files are used.Checklist
AI-assisted.
Repair: @pigalot review on
2a685c06(headc66aa6be)Merged
origin/main5de0b114cleanly (merge commit9af6f85a;git merge-tree --write-tree origin/main HEADexits 0)._step_ptr_instruction'sLEAcopy branch now requiresRegisterExt.is_gpr64(ins.memory_base), solea reg, [ecx](67 4C 8D 09) is refused instead of tracked as an exact state-1 copy. New controlneg_lea_ecx_calleenext toneg_mem_ecx_callee.neg_join_maybe_ptr_callee(test edx, edx/jz/mov rcx, r8, then a store throughrcx) dereferences a pointer that is only possibly the parameter (state 2 at the join). Weakening the join tomerged[r] = 1and dropping_check_ptr_mem's state-1 requirement each accept it independently. The store usesedx, the fixture's stored-value register: witheaxthe callee is refused asundefined register raxinstead, sinceeaxis undefined at callee entry.LEAbranch and_check_ptr_memare equivalent (any index refuses the copy/deref anyway — verified on Linux: removing either alone changes nothing).LEA32-bit destination, the state-1 requirement in theLEAcopy, 8/16-bitLEAdestination, a pointer live at a host-import/unresolved call or as a jump-table index, the volatile drop after a nested call, memory-formCMOVccgiving state 2, and the 16-bitMUL/DIVRDX, segment-prefix and access-kind checks in_check_ptr_memstill have no dedicated control — follow-up candidates, no behavior change in this push.c66aa6be:lea r9, [ecx]and the join encodings cross-checked with keystone (LLVM MC) and iced-x86 (67 4C 8D 09; join85 D2 74 03 4C 89 C1 89 11 31 C0 C3); a synthetic-PE translation harness refuses all four controls (neg_lea_ecx_callee,neg_join_maybe_ptr_callee, plusneg_mem_ecx_callee/neg_lea_disp_calleeregressions) withescapes or is unsupportedand kills spot-mutants A (drop LEAis_gpr64), B (merged[r] = 2->1) and C (drop_check_ptr_mem!= 1), each accepting only its own control;form_coverage_check.py,docs_links_check.py(175 md / 713 links),bidi_controls_check.py(2669 files) andgit diff --checkall exit 0.llvm-ml-19 -m64assembly of the fixture on Linux is still pending (toolchain install needs approval); Windowsml64assembly plus the fullcpu_switch_frame_ptrdifferential run are covered by theWIN-VERIFYrun below.Windows Verification
c66aa6be397db9ea7d15f89fb510e5e5b091ce49dev:ctest --preset dev --no-tests=error -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$' --output-on-failure->7 passed, 0 failed(4.88s;cpu_switch_frame_ptr1.30s)release:ctest --preset release --no-tests=error -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$' --output-on-failure->7 passed, 0 failed(4.45s;cpu_switch_frame_ptr1.22s)form_coverage_check.py,docs_links_check.py(175 Markdown files, 713 links), andbidi_controls_check.py(2669 files) passed.AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-27 18:11 UTC · original
Hi @Ammmae0x, thanks for this. The frame-slot pointer analysis is careful, and the parts I could reproduce held up.
On a Linux cross build (llvm-ml + lld-link for the fixture, clang-cl for the lifted C++, run under Wine):
I also tried a dozen hand-written probe exports against the analysis, and it refused every one that should be refused.
A few things before this is ready:
analyze_pointer_param/resolve_pointer_calls/prove_frameone at a time. 34 of 51 deletions leavecpu_switch_frame_ptrfully green: same refusals, same guard-mutation results, and byte-identical positive C++. That includes the central "any register read of the pointer escapes" check.store_mem_callee,store_stack_calleeandptr_arith_calleenever dereference the pointer, so the no-access fallback refuses them anyway.ret_rax_calleedoes? That way the guard it names is the only reason it is refused.[ptr+disp]/[idx]/[ecx]operands;MOVS/STOS, sign extensions,MUL/DIV, and 8/16-bit partial writes;may_writeover a saved-register slot, and a read of a saved-register slot;mov [rcx], edx; mov [r8], rcx) I measured native ≠ lifted once the guard is removed, so each matters.neg_multi_arg_alias_same/_overlapleave R8/R9 unset, so without the alias check they are still refused, ascallee argument r9 is undefined.neg_tail_jump,neg_tail_rbp,neg_var_index_lea,neg_multi_arg_copy_alias,neg_unproven_rbp) are refused by main's translator with the same message. They are fine as "still refused" checks, but they don't exercise the new code, so the body's "26 refusal negative controls" overstates the new coverage.LEA RCX, [RSP+20h]) … stay rejected", and thatLEA RAX, [RSP+8]is rejected because the frame address would escape. Both are no longer true for bounded internal callees. Please:cpu_switch_frame_ptrwith the reproduction command and the measured result (AGENTS.md › Pull requests asks for this).prpreset doesn't build or runcpu_switch_frame_ptr(or the othercpu_aot_*regression tests besidescpu_aot_fuzz_smoke), and the /O2 job is skipped on pull requests. So the green checks don't cover this test. Could you paste the fullctest --preset dev --no-tests=error -R "^cpu_switch_frame_ptr$" -Voutput from your Windows run, including the test's own printed lines? Whether to add it to theprpreset is the maintainers' call.prove_frame, the call-step comment says the rest of the frame "is kept", but the new loop just below now changes the pointed-to bytes.Framedocstring describesaccessesas bytes each instruction accesses, but pointer LEAs are now recorded there without accessing anything.lift_functiononly describes stack arguments passed by value.if not accesses: return Noneis already covered bylen(widths) != 1, and theframe_ptr_params = {}reset inProgram.calleeis already implied byfunction.recursive. Keep them with a comment saying they are deliberate redundancy, or drop them.analyze_pointer_paramreads as^Gnalyze_pointer_param, and fourtests/...paths lost their\tto a tab character.Thanks again; with the controls tightened, this will be much easier to trust and keep.
This comment was AI-assisted.
@KelboLive on GitHub · 2026-11-27 18:51 UTC · original · approved these changes
Significant and well-executed extension of
cpu_switch_aot.pyfor bounded frame-slot pointer passing. ThePointerParamanalysis correctly tracks width, read-before-write ordering, write certainty, and escape detection across all control-flow exits. Frame bounds validation ensures pointed bytes stay within the caller's stack frame without overlapping return addresses or callee home space. Multi-argument aliasing guards, recursive/cycle rejection, and initialization proofs are all correct. The differential fixture with 313 input pairs at /Od and /O2, plus 26 refusal negative controls and mutation audit, provides thorough verification. Approved.@KelboLive on GitHub · 2026-11-28 00:04 UTC · original
This is a significant extension to cpu_switch_aot.py. JohnConnorNPC's 6-point review covers the most important issues (guard pinning, control reasons, docs update, CI evidence, comments, small things). I'll add a few additional observations:
1.
analyze_pointer_paramcomplexity (~250 lines). The function is dense and handles many instruction types inline. Consider extractingstep_ptrinto its own helper with a docstring explaining the state machine (the 3 states: 0=dead, 1=proven pointer, 2=possibly-pointer). This would make future maintenance much easier.2. Hardcoded instruction sets. The function references
BIT_TESTS,CMOVCC,STRING_TRANSFERS,SIGN_EXTENSIONS— these are defined elsewhere in the file but not imported or documented at the call site. Please add a comment listing what each set covers, or verify they're already well-documented nearby.3. PR body accuracy. The body claims "26 refusal negative controls" but JohnConnorNPC notes that 5 of those (
neg_tail_jump,neg_tail_rbp,neg_var_index_lea,neg_multi_arg_copy_alias,neg_unproven_rbp) are refused by main's translator before the new code runs. The actual new-code coverage is 21 controls, not 26. Please correct this in the body.4.
may_writeover saved-register slots. JohnConnorNPC flags this as a missing guard. Looking at the code: whenparam.may_writeis true and the slot holds saved nonvolatile bytes (not all ones), the current code clears it to zero on post-call marking. But there's no pre-call check that prevents a pointer into a saved-register slot from being passed — thereads_before_writeguard only catches reads, not writes. A callee could write through such a pointer without triggering any refusal. This seems like a real gap worth flagging explicitly in the controls.5. Tail-jump handling. In
step_ptr, tail jumps check if argument registers are live and return "escape". But the fixtureneg_tail_jumpusesjmp write_u32_out(not through the normal call path), so it's caught by main's translator before reaching the new code. A proper test would be a tail jump to an internal callee where the pointer is in RCX — that should exercise the new escape check directly.6. Redundancy guards. JohnConnorNPC notes
if not accesses: return Noneis covered bylen(widths) != 1, andfunction.frame_ptr_params = {}reset is implied byfunction.recursive. These are harmless but add noise. If kept, add a comment like "# deliberate redundancy for clarity" as suggested.@JohnConnorNPC on GitHub · 2026-11-28 08:18 UTC · original
Thanks for this. This follows up the earlier review comment. I re-checked on head
129fcc38, which is still the only commit, so none of the items from either review comment are in yet. Two things still block it:tools/cpu_switch_aot.py. For each copy I ran the check's Python half (check_refusals_and_guard_mutationsplustranslateof the four exports) against the fixture DLL built from this head.step_ptr's register-read escape turned intopass, all 26 controls are still refused, both guard mutations still behave as expected, and the generated C++ is byte-identical.may_write(replacement = existing), allowing[ptr+disp]incheck_mem(droppingins.memory_displacement != 0), and the memory-form 32-bitCMOVccescape (if w_reg != 8→if False).offset < min_offset, the must-write meet (and→or) or the pre-call read check goes red, as it should.LEA RCX, [RSP+20h]) … stay rejected". It also has nocpu_switch_frame_ptrentry (see AGENTS.md › Pull requests).Smaller points:
3. With the alias check deleted,
neg_multi_arg_alias_samegoes red only because of the message match:expected 'aliased frame-slot pointers', got callee argument r9 is undefined. Setting R8/R9 in those controls would make them fail for their own reason.4. On item 4 of the 00:04 UTC comment: by my reading of
prove_frame, a write through the pointer into a saved-register slot that is later restored from is already refused. The post-call rule replaces the saved markers (b"\1"orbytes(param.width)), so thePOPdoesn't count as a restore and the RET check rejects it. That rule is unpinned, though: thereplacement = existingmutant above stays green.5. CI still doesn't run the new test. The Windows job reports
100% tests passed out of 41, and its log has nocpu_switch_frame_ptrline.The PR still merges cleanly into current main
1f07b2c1(git merge-tree --write-treerc 0). On the merged tree the check's Python half passes, with 26 refusals and the same generated C++.This comment was AI-assisted.
@Ammmae0x on GitHub · 2026-11-28 11:07 UTC · original
Addressed all items from JohnConnorNPC and KelboLive in
2a685c06(merged withupstream/mainec71c290):store_mem_callee,store_stack_callee, andptr_arith_calleeto dereference[rcx]before escaping so removing the general register-read escape accepts them directly instead of hitting the no-access fallback.r8/r9inneg_multi_arg_alias_sameandneg_multi_arg_alias_overlapso the aliasing check is the sole refusal reason.neg_callee_tail_ptr_live,neg_nested_int_callee,neg_nested_multi_live,neg_nested_cmov_ptr,neg_lea_disp_callee,neg_lea_index_callee,neg_mem_disp_callee,neg_mem_index_callee,neg_mem_ecx_callee,neg_stos_ptr_rax,neg_movs_ptr_rsi,neg_sign_ext_callee,neg_mul_ptr_callee,neg_partial_write_callee,neg_xor8_partial_callee,neg_bit_test_reg_callee,neg_cmov32_mem_callee,neg_may_write_saved_reg,neg_read_saved_reg,neg_callee_stack_arg_overlap,neg_incoming_stack_slot_uninit) — 47 total (42 new-code controls + 5 existing main-translator controls). Verified 18/18 guard-removal mutations killed.tools/cpu_switch_aot.py):_check_ptr_memand_step_ptr_instructionwith a docstring documenting the 3-state lattice (0=dead,1=proven,2=possibly-pointer) and theBIT_TESTS/CMOVCC/STRING_TRANSFERS/SIGN_EXTENSIONSsets.Framedocstring,prove_framecall-step comment, andlift_functioncall-site comment; documented deliberate redundancy onif not accesses:andmember.frame_ptr_params = {}.docs/experiments.md(direct-call/frame paragraphs + newcpu_switch_frame_ptrsection with reproduction command and results) and fixed theanalyze_pointer_param/tests/...typos and guard-to-control table in the PR body.ctest --preset dev --no-tests=error -R "^cpu_switch_frame_ptr$" -Voutput:Also verified
dev&releasebuilds/tests across all 7 affectedcpu_aot_*/cpu_switch_frame_ptrtargets (7/7passed in both presets).AI-assisted.
@pigalot on GitHub · 2026-11-29 06:46 UTC · original · requested changes
Independently reviewed
2a685c06integrated overmain212d4b5f(tree3eebf76f). The trial merge is clean andgit diff --checkis clean.I read
_check_ptr_mem,_step_ptr_instruction,analyze_pointer_param,Frame.resolve_pointer_callsand theprove_framechanges against the rules the PR body states, and checked JohnConnorNPC's items from 27 and 28 November at this head. One input the body says is refused is accepted, so I'm requesting changes for that; the rest is coverage.1.
lea reg, [ecx]is accepted as an exact copy of the pointer (blocking)._check_ptr_memrefuses a 32-bit base (neg_mem_ecx_callee), but theLEAcopy branch in_step_ptr_instructiononly checks the destination width, the index and the displacement. With an address-size prefix the copy is the low 32 bits of the pointer, and it is still tracked as state 1.cpu_switch_frame_ptr.dllwithlea r9, [rcx+4]inlea_disp_callee(4C 8D 49 04, one occurrence) replaced bylea r9, [ecx](67 4C 8D 09), thentranslate(copy, ["neg_lea_disp_callee"]).r9 = ...static_cast<std::uint32_t>(rcx)...; store<std::uint32_t>((r9), ...);and the caller passes
reinterpret_cast<word>(frame + 32). So the translation stores through a truncated host address, andprove_framemarks the slot as written by the callee.mov [ecx], edx. The unpatched export is refused (frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585).and RegisterExt.is_gpr64(ins.memory_base)to the condition that setscur[dst] = 1refuses the patched copy, and the test's Python half stays green. Please add a control for it next toneg_mem_ecx_callee.2. Earlier review items. All of JohnConnorNPC's named items are addressed at this head:
neg_escape_store_memis accepted and the test fails.neg_multi_arg_alias_same/_overlapnow fail for their own reason (accepted when the alias check is removed).docs/experiments.mdhas the corrected paragraphs and thecpu_switch_frame_ptrentry; the body states 42 + 5 controls; the comments and the two deliberate redundancies are documented.-Voutput is in the author's comment. CI still does not run this test, which stays the maintainers' call.3. Mutation results. I removed or weakened one guard at a time in a copy of
tools/cpu_switch_aot.py(66 mutants) and ran the check's Python half against the built fixture:translateof the four exports compared with the builtcpu_switch_frame_ptr_lifted.cpp,check_structure, andcheck_refusals_and_guard_mutations. A survivor produces byte-identical C++, so the compiled half cannot tell it apart either.Killed, 45:
RETwith the pointer in RAX,LEAdisplacement,LEAown index, bothCMOVccwidth checks,CMOVccregister form giving state 2, string-instruction registers, 8-bitXOR r, r, sign extensions,MUL/DIVRAX,COND_WRITE, 8/16-bit partial write;_check_ptr_mem: 64-bit base, own index, displacement, registerBT*;and→or),reads_before_write(two variants),must_write(all→any),may_write;min_offset(two variants), alias check (two variants), bounds viaFrame.access(two variants), the candidate walk's register-use stop, the candidate index check, the incoming-slot read demand, post-callmust_writemarking,replacement = existing, the pre-call read check,reads.pop, the anchor gate,lifter.slot→lifter.reg;resolve_pointer_callsraise andmember.recursive. These two, and the candidate walk, are killed by the message match only: with every recursion guard removed,neg_recursive_cycleis still refused asescapes or is unsupported.Surviving, 15 (the test stays fully green):
merged[r] = 2→1), and the state-1 requirement for a dereference in_check_ptr_mem. No control dereferences a pointer that is only possibly the parameter, for exampletest edx, edx / jz L / mov rcx, r8 / L: mov [rcx], eax. These two decide whethermust_writecan be trusted, so I'd like one control for them in the same push as item 1;LEA(lea rax, [rdx+rcx]) and in a memory operand (mov eax, [rdx+rcx]);LEAcopy with a 32-bit destination (w_reg == 8), the state-1 requirement in theLEAcopy, and the 8/16-bitLEAdestination check;callee is None), and as a jump-table index;mov rax, rcx / call g / mov [rax], edxwould then count as a write through the pointer);CMOVccgiving state 2, the 16-bitMUL/DIVRDX check, the segment-prefix check and the access-kind check in_check_ptr_mem.Equivalent, 6:
if not accesses, therecursivegate at the top ofanalyze_pointer_param,function.recursiveinlift_function, theinternal and not function.recursivegate, and theframe_ptr_params = {}reset alone or withmember.recursive. Each is covered by one of the others, as the comments say.One more mutant (the dispatch-sequence load check) did not apply because my pattern was wrong, so I have no result for it.
4. What I ran.
Built everything in
devandrelease, thenctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$':7 passed in Debug and 7 in Release
/O2, no skips.cpu_switch_frame_ptrprintedverified 4 exports x 313 inputsfor/Odand/O2, both C++ mutants caught, both guard mutations confirmed and 47 refusals.ctest --test-dir out/build/dev --no-tests=error -j 4 -R '^cpu_' -E 'cpu_native_archive_': 315 selected, 314 passed, 0 failed, 1 skipped (cpu_aot_sysdesc), reported separately from the passes.The 281
*_lifted.cppfiles thatmainalready generates are byte-identical after the change, in both presets (SHA-1 before and after the rebuild).On
main212d4b5fthe test is not registered (tests/cmake/cpu_switch_frame_ptr.cmakedoes not exist there).tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pyexit 0.No title run: the change is confined to the offline CPU translator and its fixture.
Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10. The
^cpu_selection includescpu_shim_shadow_hardware; it ran without the debug layer, so I don't report it as a GPU result.CI:
Build and test on Windowspassed on2a685c06; it does not runcpu_switch_frame_ptr.This reply was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-29 13:24 UTC · original
Re-review of head
2a685c06, trial-merged ontomainc04e0dd6(git merge-tree --write-treeexits 0,git diff --checkclean). I built the fixture on Linux (llvm-ml-19 -m64+lld-link-19 /DLL /NOENTRY /NODEFAULTLIB /DEF:) and ran the check's Python half: translate of the four exports,check_structure, then the refusals and guard mutations. I did no MSVC build and no native/lifted run.Since my comments on
129fcc38:218b68a1is a clean merge ofmain(git show --remerge-diffprints nothing).RESULT GREEN-PY refused=47 guards=2, which matches the 42 + 5 controls in the description._step_ptr_instruction/_check_ptr_memand ran each on a fresh copy. All eight now fail, each on its own control. The four that used to survive:neg_escape_store_mem: unexpectedly acceptedmay_writekeeps saved markers:neg_may_write_saved_reg: unexpectedly accepted[ptr+disp]allowed:neg_mem_disp_callee: unexpectedly acceptedCMOVcc:neg_cmov32_mem_callee: unexpectedly acceptedThe alias deletion now fails as
neg_multi_arg_alias_same: unexpectedly accepted, instead of failing on an undefinedr9.cpu_switch_frame_ptrentry is added.MOV,XCHG,PUSH,TEST/CMPand arithmetic on the tracked register all take the register-read escape. Lifted internal callees take only the four argument registers (static word fn_1000(word rcx, word rdx, word r8, word r9)), so a nested callee can't see a pointer that its caller keeps in a nonvolatile register. The argument-register check at a nested call is enough there.MUST: none new from me. The blocking
lea reg, [ecx]case in the current changes request reproduces here. The fixture copy with4c8d4904→674c8d09(one occurrence) is accepted forneg_lea_disp_callee, and the emitted source containsstatic_cast<std::uint32_t>(rcx). The unpatched DLL is refused at RVA 0x1585. I won't repeat the fix or the survivor list.SHOULD / NIT: none beyond the current review.
Held until a new head addresses the changes request on
2a685c06.AI-assisted.
@Ammmae0x on GitHub · 2026-11-29 15:10 UTC · original
Addressed
@pigalot'sCHANGES_REQUESTEDreview on2a685c06inc66aa6be:lea reg, [ecx]): AddedRegisterExt.is_gpr64(ins.memory_base)to_step_ptr_instruction'sLEAcopy branch intools/cpu_switch_aot.py, plusneg_lea_ecx_calleenext toneg_mem_ecx_callee.neg_join_maybe_ptr_callee(test edx, edx / jz / mov rcx, r8, thenmov dword ptr [rcx], edx) so weakeningmerged[r] = 2 -> 1and droppingcur.get(base, 0) != 1in_check_ptr_memeach fail on their own.c66aa6be):ml64assembled both new controls andcpu_switch_frame_ptrpassed differential (/Od,/O2), C++/guard mutants, and all 49 refusal checks in bothdev(7/7,4.88s) andrelease(7/7,4.45s), plus repo Python checks (175docs /2669files).AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-29 15:36 UTC · original
Re-review at
c66aa6be, covering the delta since2a685c06: the merge9af6f85aandc66aa6be. I trial-merged ontomaincf0c30af(git merge-tree --write-treeexits 0). I built the fixture from this head on Linux withllvm-ml-19 -m64andlld-link-19 /DLL /NOENTRY /NODEFAULTLIB /DEF:, then ran the check's Python half: translate of the four exports,check_structure, the refusals and the guard mutations. I did no MSVC build and no native/lifted run.Python half:
RESULT GREEN-PY refused=49 guards=2on the head and on the merged tree, and the merged tree's four-export source matches the head's. 49 agrees with the updateddocs/experiments.mdcount (44 + 5).The change request's blocking item (
lea reg, [ecx]) is fixed. I applied the same patch to the new DLL:lea r9, [rcx+4](4C 8D 49 04, 1 occurrence) becamelea r9, [ecx](67 4C 8D 09), and I translatedneg_lea_disp_callee.c66aa6be:REFUSED frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585.RegisterExt.is_gpr64(ins.memory_base)term removed: the patched copy isACCEPTED, withstatic_cast<std::uint32_t>(rcx)in the source. So the refusal comes from that term.The new controls are pinned. I removed one guard per copy of
tools/cpu_switch_aot.pyand ran the Python half each time. The pristine file was unchanged afterwards (sha25618a7bce51b4d…).is_gpr64term dropped from theLEAcopy branch:RED neg_lea_ecx_callee: unexpectedly accepted.merged[r] = 2changed to1at a join of differing states:RED neg_join_maybe_ptr_callee: unexpectedly accepted.cur.get(base, 0) != 1dropped from_check_ptr_mem:RED neg_join_maybe_ptr_callee: unexpectedly accepted.The join control is a valid input.
rdxandr8are the export's own incoming arguments, so neither control is refused for an unrelated reason.From us: 0 MUST. Not blocking: this push adds two controls. The other survivors listed in the change request (the pointer used as an index, the 32-bit
LEAdestination, the pointer live at an import, unresolved or jump-table transfer, dropping volatiles after a nested call, memoryCMOVcc, the 16-bitMUL/DIVRDX check, the segment prefix and the access kind) are still uncovered, judging by the diff. CI still does not runcpu_switch_frame_ptr.Not merged: the change request on
2a685c06is still standing. Its reviewer needs to re-check and lift it.AI-assisted review.
@pigalot on GitHub · 2026-11-29 17:48 UTC · original · approved these changes
Retested
c66aa6beintegrated overmain26df1826(treee39f568e). The trial merge is clean andgit diff --checkis clean. This supersedes my changes-requested review on2a685c06.The delta since
2a685c06is the merge9af6f85a(git show --remerge-diffprints nothing) andc66aa6be: one added term in theLEAcopy branch of_step_ptr_instruction, two controls, and the count indocs/experiments.md.1.
lea reg, [ecx]accepted as an exact copy (was blocking): addressed.LEAcopy branch now also requiresRegisterExt.is_gpr64(ins.memory_base), the same test_check_ptr_memuses for a dereference.lea r9, [rcx+4](4C 8D 49 04, one occurrence) replaced bylea r9, [ecx](67 4C 8D 09), thentranslate(copy, ["neg_lea_disp_callee"]). It is now refused in both presets:frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585.neg_lea_ecx_calleeis refused for this reason and no other: with the new term removed, the test fails withneg_lea_ecx_callee: unexpectedly accepted.2. Control for a pointer that is only possibly the parameter (requested with item 1): addressed.
neg_join_maybe_ptr_calleestores throughrcxafter a join where one path replaced it withr8. It fails the test when the join gives state 1 instead of 2, and again when_check_ptr_memno longer requires state 1, so both guards are pinned separately.3. Mutation results at this head. One change at a time in
tools/cpu_switch_aot.py, thenctest -R '^cpu_switch_frame_ptr$'on the dev build; the file was restored afterwards (git diff --quietexit 0).Killed, 4:
is_gpr64term removed from theLEAcopy branch:neg_lea_ecx_callee: unexpectedly accepted;is_gpr64test moved to the destination register (ins.op0_register):neg_lea_ecx_callee: unexpectedly accepted;merged[r] = 2changed to1at a join:neg_join_maybe_ptr_callee: unexpectedly accepted;_check_ptr_mem:neg_join_maybe_ptr_callee: unexpectedly accepted.Surviving, 2 (the test stays fully green; both were in my earlier list and are not blocking):
LEAcopy (w_reg == 8);LEAcopy.Equivalent: none in this set.
I did not rerun the other survivors from my review of
2a685c06(the pointer live at an import, unresolved call or jump-table index, the volatile drop after a nested call, memory-formCMOVccgiving state 2, the 16-bitMUL/DIVRDX check, the segment-prefix and access-kind checks). The code they cover is unchanged in this push and the description lists them as follow-up candidates. Each guard is present in the code; what is missing is a control, so a later edit could remove one without the test noticing. A follow-up that pins them would be welcome.4. What I ran.
Built everything in
devandrelease, thenctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$':7 passed in Debug and 7 in Release
/O2, no skips.cpu_switch_frame_ptrprintedverified 4 exports x 313 inputsfor/Odand/O2, both C++ mutants caught, both guard mutations confirmed and49 refusal checks passed.ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^cpu_' -E '(cpu_native_archive_|_hardware$)': 302 selected in each preset, 301 passed, 0 failed, 1 skipped (cpu_aot_sysdesc), reported separately from the passes. Every fixture thatmaintranslates still translates and passes, so the added term refuses none of them.On
main26df1826the test is not registered (tests/cmake/cpu_switch_frame_ptr.cmakedoes not exist there).tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pyexit 0.No title run: the change is confined to the offline CPU translator and its fixture. No GPU tests ran.
Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10.
CI:
Build and test on Windowspassed onc66aa6be; it does not runcpu_switch_frame_ptr.This reply was AI-assisted.