Visitar URL original
Phase 5.B c14-followup-A: static_assert guard for jit::FrameHeader si… · SonicField/cpython@1fc473a · GitHub
Skip to content

Commit 1fc473a

Browse files
committed
Phase 5.B c14-followup-A: static_assert guard for jit::FrameHeader sizeof
Closes c14 latent silent-break gap per supervisor 00:51:18Z (A) + pythia python#368 missing-validation flag. c14 (0703dba) phx_frame_header_size hardcodes sizeof(void*) for the FrameHeader argument to jit_frame_header_size, matching C++ frameHeaderSize semantics (frame_header.h:67). The hardcoded value is documented as "On 3.12+, FrameHeader = union { PyFunctionObject*; uintptr_t rtfs; } = sizeof(void*)" — comment-derived, NOT static_asserted. If the FrameHeader union grows in a future Python version (or even on 3.12.X minor revisions adding fields), the hardcoded sizeof(void*) silently produces wrong offsets at runtime, re-creating the c14 SIGSEGV class with no compile-time signal. This commit adds a static_assert guard in hir_instr_c_verify.cpp: #if PY_VERSION_HEX >= 0x030C0000 static_assert(sizeof(jit::FrameHeader) == sizeof(void*), "..."); #endif Files: M Python/jit/hir/hir_instr_c_verify.cpp (+15 LOC: include + 5-line static_assert with explanatory comment) Net delta: +15 LOC. Defensive-infra-class commit per docs/methodology/synthetic_falsifier_at_gate.md (1546c43). Synthetic falsifier OPTIONAL given trivial scope (5-LOC static_assert + include) per supervisor 00:51:18Z (A) — would-be falsifier test (intentionally redefining FrameHeader to 16 bytes; verifying static assert FIRES) is symbolic since the FrameHeader struct is defined upstream. PRE-COMMIT BUILD VERIFIED via pre-commit hook a2e8808 — hook re-globs .cpp file via cmake configure, compiles with new static_assert, PASS = current FrameHeader is sizeof(void*) on this build target.
1 parent 0703dba commit 1fc473a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎Python/jit/hir/hir_instr_c_verify.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "cinderx/Jit/hir/phx_ptr_queue.h" /* Phase 4.X-full X2a (Batch 91) */
2020
#include "cinderx/Jit/hir/phx_ptr_set.h" /* Phase 4.X-full X2b (Batch 92) */
2121
#include "cinderx/Jit/hir/phx_ptr_map.h" /* Phase 4.X-full X3a (Batch 95) */
22+
#include "cinderx/Jit/frame_header.h" /* Phase 5.B c14-followup-A: jit::FrameHeader sizeof guard */
2223

2324
#include <cassert>
2425
#include <cstring>
@@ -27,6 +28,22 @@
2728
using namespace jit::hir;
2829

2930
/* ---- Compile-time size checks ---- */
31+
32+
/* Phase 5.B c14-followup-A: guard against silent breakage of
33+
* generator_helpers_c.c::phx_frame_header_size, which hardcodes
34+
* sizeof(void*) for the FrameHeader argument matching C++
35+
* frameHeaderSize semantics (frame_header.h:67). On 3.12+, FrameHeader
36+
* = union { PyFunctionObject*; uintptr_t rtfs; } = sizeof(void*). If the
37+
* union grows in a future Python version, this static_assert fires AT
38+
* COMPILE TIME, before the c14 port produces wrong offsets at runtime
39+
* (the c14 SIGSEGV class). 3.11 branch is dead code per CLAUDE.md. */
40+
#if PY_VERSION_HEX >= 0x030C0000
41+
static_assert(sizeof(jit::FrameHeader) == sizeof(void*),
42+
"jit::FrameHeader size assumption broken — c14 phx_frame_header_size "
43+
"would produce wrong offsets; revisit hardcoded sizeof(void*) in "
44+
"generator_helpers_c.c::phx_frame_header_size.");
45+
#endif
46+
3047
static_assert(sizeof(HirInstrLayout) == sizeof(Instr),
3148
"HirInstr size must match C++ Instr");
3249
static_assert(sizeof(HirCondBranchInstr) == sizeof(CondBranchBase),

0 commit comments

Comments
 (0)