Skip to content

Commit a924c85

Browse files
committed
Add hir_c_init_end_inlined() for inline_depth=-1 enforcement
EndInlinedFunction::inline_depth_ defaults to -1 in C++ but calloc gives 0. This was identified as the sole remaining unprotected non-zero default (Pythia python#73, calloc-zero audit D-1776289329). Add hir_c_init_end_inlined() following the same pattern as hir_c_init_deopt (nonce=-1) and hir_c_alloc_instr (bytecode_offset=-1). Any future C factory for EndInlinedFunction must use this init function.
1 parent 9ff7359 commit a924c85

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎Python/jit/hir/hir_instr_c.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ typedef struct { HIR_INSTR_FIELDS; int32_t cache_id; } HirLoadTypeMethodCacheEnt
156156

157157
/* ---- Multi-field (Instr base) ---- */
158158
typedef struct { HIR_INSTR_FIELDS; void *addr; HirType ret_type; } HirCallStatic;
159-
/* WARNING: inline_depth defaults to -1 in C++ (hir.h:1731).
160-
* Any C factory for this type MUST set inline_depth = -1. */
159+
/* inline_depth defaults to -1 in C++ (hir.h:1731).
160+
* Use hir_c_init_end_inlined() for any C factory — enforces the invariant. */
161161
typedef struct { HIR_INSTR_FIELDS; void *begin; int32_t inline_depth; } HirEndInlinedFunction;
162162
typedef struct { HIR_INSTR_FIELDS; int32_t line_no; int32_t _pad; void *parent; } HirUpdatePrevInstr;
163163
typedef struct { HIR_INSTR_FIELDS; uint32_t arg_idx; int32_t _pad; HirType type; } HirLoadArg;
@@ -656,6 +656,14 @@ static inline void hir_c_init_deopt(void *instr, int32_t opcode) {
656656
* suppress_exception_deopt) are correctly zero/NULL from calloc. */
657657
}
658658

659+
/* Initialize EndInlinedFunction fields after hir_c_init_instr.
660+
* inline_depth defaults to 0 from calloc; C++ constructor uses -1.
661+
* Same enforcement pattern as bytecode_offset and nonce. */
662+
static inline void hir_c_init_end_inlined(void *instr, int32_t opcode) {
663+
hir_c_init_instr(instr, opcode);
664+
((HirEndInlinedFunction *)instr)->inline_depth = -1;
665+
}
666+
659667
/* ==== Slab base pointer ====
660668
* The slab layout is: [Register*[N]] [size_t N] [Instr struct...]
661669
* base() returns the start of the slab allocation. */

0 commit comments

Comments
 (0)