From caac966b0051578b60b4b07fe341174f25d9f8b1 Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Sat, 14 Feb 2026 18:39:10 +0100 Subject: [PATCH 1/2] fix warnings in jit builds (GH-144817) --- Python/jit.c | 2 +- Python/optimizer.c | 5 +++-- Python/optimizer_analysis.c | 8 ++++---- Python/optimizer_bytecodes.c | 13 ++++++++----- Python/optimizer_cases.c.h | 11 +++++++---- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Python/jit.c b/Python/jit.c index 0791d042710efb..3e0a0aa8bfcc81 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -164,7 +164,7 @@ mark_executable(unsigned char *memory, size_t size) jit_error("unable to flush instruction cache"); return -1; } - int old; + DWORD old; int failed = !VirtualProtect(memory, size, PAGE_EXECUTE_READ, &old); #else __builtin___clear_cache((char *)memory, (char *)memory + size); diff --git a/Python/optimizer.c b/Python/optimizer.c index 12ef7c3fc0adf5..466729b158d345 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -1044,7 +1044,7 @@ _PyJit_TryInitializeTracing( tracer->initial_state.func = (PyFunctionObject *)Py_NewRef(func); tracer->initial_state.executor = (_PyExecutorObject *)Py_XNewRef(current_executor); tracer->initial_state.exit = exit; - tracer->initial_state.stack_depth = stack_pointer - _PyFrame_Stackbase(frame); + tracer->initial_state.stack_depth = (int)(stack_pointer - _PyFrame_Stackbase(frame)); tracer->initial_state.chain_depth = chain_depth; tracer->prev_state.dependencies_still_valid = true; tracer->prev_state.instr_code = (PyCodeObject *)Py_NewRef(_PyFrame_GetCode(frame)); @@ -1486,7 +1486,7 @@ stack_allocate(_PyUOpInstruction *buffer, _PyUOpInstruction *output, int length) write++; depth = _PyUop_Caching[uop].entries[depth].output; } - return write - output; + return (int)(write - output); } static int @@ -2130,6 +2130,7 @@ executor_to_gv(_PyExecutorObject *executor, FILE *out) assert(inst->format == UOP_FORMAT_JUMP); _PyUOpInstruction const *exit_inst = &executor->trace[inst->jump_target]; uint16_t base_exit_opcode = _PyUop_Uncached[exit_inst->opcode]; + (void)base_exit_opcode; assert(base_exit_opcode == _EXIT_TRACE || base_exit_opcode == _DYNAMIC_EXIT); exit = (_PyExitData *)exit_inst->operand0; } diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index 7bd6970e5fd2dc..c6a513ad220b63 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -398,7 +398,7 @@ get_test_bit_for_bools(void) { uintptr_t true_bits = (uintptr_t)&_Py_TrueStruct; #endif for (int i = 4; i < 8; i++) { - if ((true_bits ^ false_bits) & (1 << i)) { + if ((true_bits ^ false_bits) & (uintptr_t)(1 << i)) { return i; } } @@ -412,8 +412,8 @@ test_bit_set_in_true(int bit) { #else uintptr_t true_bits = (uintptr_t)&_Py_TrueStruct; #endif - assert((true_bits ^ ((uintptr_t)&_Py_FalseStruct)) & (1 << bit)); - return true_bits & (1 << bit); + assert((true_bits ^ ((uintptr_t)&_Py_FalseStruct)) & (uintptr_t)(1 << bit)); + return true_bits & (uintptr_t)(1 << bit); } #ifdef Py_DEBUG @@ -504,7 +504,7 @@ optimize_uops( stack_pointer = ctx->frame->stack_pointer; } - DUMP_UOP(ctx, "abs", this_instr - trace, this_instr, stack_pointer); + DUMP_UOP(ctx, "abs", (int)(this_instr - trace), this_instr, stack_pointer); _PyUOpInstruction *out_ptr = ctx->out_buffer.next; diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 7c928e6502a412..2b35628ad99999 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -109,11 +109,13 @@ dummy_func(void) { } op(_STORE_ATTR_INSTANCE_VALUE, (offset/1, value, owner -- o)) { + (void)offset; (void)value; o = owner; } op(_STORE_ATTR_WITH_HINT, (hint/1, value, owner -- o)) { + (void)hint; (void)value; o = owner; } @@ -320,7 +322,8 @@ dummy_func(void) { r = right; } - op(_BINARY_OP_EXTEND, (left, right -- res, l, r)) { + op(_BINARY_OP_EXTEND, (descr/4, left, right -- res, l, r)) { + (void)descr; res = sym_new_not_null(ctx); l = left; r = right; @@ -386,7 +389,7 @@ dummy_func(void) { assert(PyLong_CheckExact(sym_get_const(ctx, sub_st))); long index = PyLong_AsLong(sym_get_const(ctx, sub_st)); assert(index >= 0); - int tuple_length = sym_tuple_length(tuple_st); + Py_ssize_t tuple_length = sym_tuple_length(tuple_st); if (tuple_length != -1 && index < tuple_length) { ADD_OP(_NOP, 0, 0); } @@ -951,7 +954,7 @@ dummy_func(void) { ctx->done = true; break; } - int returning_stacklevel = this_instr->operand1; + int returning_stacklevel = (int)this_instr->operand1; if (ctx->curr_frame_depth >= 2) { PyCodeObject *expected_code = ctx->frames[ctx->curr_frame_depth - 2].code; if (expected_code == returning_code) { @@ -979,7 +982,7 @@ dummy_func(void) { break; } _Py_BloomFilter_Add(dependencies, returning_code); - int returning_stacklevel = this_instr->operand1; + int returning_stacklevel = (int)this_instr->operand1; if (frame_pop(ctx, returning_code, returning_stacklevel)) { break; } @@ -1001,7 +1004,7 @@ dummy_func(void) { break; } _Py_BloomFilter_Add(dependencies, returning_code); - int returning_stacklevel = this_instr->operand1; + int returning_stacklevel = (int)this_instr->operand1; if (frame_pop(ctx, returning_code, returning_stacklevel)) { break; } diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 24ae511ebcde31..7faa699a058249 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -896,6 +896,7 @@ right = stack_pointer[-1]; left = stack_pointer[-2]; PyObject *descr = (PyObject *)this_instr->operand0; + (void)descr; res = sym_new_not_null(ctx); l = left; r = right; @@ -1046,7 +1047,7 @@ assert(PyLong_CheckExact(sym_get_const(ctx, sub_st))); long index = PyLong_AsLong(sym_get_const(ctx, sub_st)); assert(index >= 0); - int tuple_length = sym_tuple_length(tuple_st); + Py_ssize_t tuple_length = sym_tuple_length(tuple_st); if (tuple_length != -1 && index < tuple_length) { ADD_OP(_NOP, 0, 0); } @@ -1271,7 +1272,7 @@ ctx->done = true; break; } - int returning_stacklevel = this_instr->operand1; + int returning_stacklevel = (int)this_instr->operand1; if (ctx->curr_frame_depth >= 2) { PyCodeObject *expected_code = ctx->frames[ctx->curr_frame_depth - 2].code; if (expected_code == returning_code) { @@ -1351,7 +1352,7 @@ break; } _Py_BloomFilter_Add(dependencies, returning_code); - int returning_stacklevel = this_instr->operand1; + int returning_stacklevel = (int)this_instr->operand1; if (frame_pop(ctx, returning_code, returning_stacklevel)) { break; } @@ -2033,6 +2034,7 @@ owner = stack_pointer[-1]; value = stack_pointer[-2]; uint16_t offset = (uint16_t)this_instr->operand0; + (void)offset; (void)value; o = owner; CHECK_STACK_BOUNDS(-1); @@ -2049,6 +2051,7 @@ owner = stack_pointer[-1]; value = stack_pointer[-2]; uint16_t hint = (uint16_t)this_instr->operand0; + (void)hint; (void)value; o = owner; CHECK_STACK_BOUNDS(-1); @@ -3595,7 +3598,7 @@ break; } _Py_BloomFilter_Add(dependencies, returning_code); - int returning_stacklevel = this_instr->operand1; + int returning_stacklevel = (int)this_instr->operand1; if (frame_pop(ctx, returning_code, returning_stacklevel)) { break; } From 645f5c4a737b3eab29d0b7bcd4ec5f8bd36f332d Mon Sep 17 00:00:00 2001 From: Benedikt Johannes Date: Sat, 14 Feb 2026 20:20:33 +0100 Subject: [PATCH 2/2] gh-144822: remove redundant decref in `codegen.c` (#144823) --- Python/codegen.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Python/codegen.c b/Python/codegen.c index 32a03e7212eeab..42fccb07d31dba 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -1422,7 +1422,6 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags PyCodeObject *co = _PyCompile_OptimizeAndAssemble(c, 1); _PyCompile_ExitScope(c); if (co == NULL) { - Py_XDECREF(co); return ERROR; } int ret = codegen_make_closure(c, LOC(s), co, funcflags);