Skip to content

Commit 5615d6f

Browse files
Add unknown opcode handlers
1 parent 637589e commit 5615d6f

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

Python/generated_tail_call_handlers.c.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9265,6 +9265,15 @@ Py_PRESERVE_NONE_CC static PyObject * _TAIL_CALL_YIELD_VALUE(TAIL_CALL_PARAMS){
92659265
}
92669266
}
92679267

9268+
Py_PRESERVE_NONE_CC static PyObject * _TAIL_CALL_UNKNOWN_OPCODE(TAIL_CALL_PARAMS){
9269+
9270+
int opcode = next_instr->op.code;
9271+
_PyErr_Format(tstate, PyExc_SystemError,
9272+
"%U:%d: unknown opcode %d",
9273+
_PyFrame_GetCode(frame)->co_filename,
9274+
PyUnstable_InterpreterFrame_GetLine(frame),
9275+
opcode);
9276+
CEVAL_GOTO(error);}
92689277
static py_tail_call_funcptr INSTRUCTION_TABLE[256] = {
92699278
[BINARY_OP] = _TAIL_CALL_BINARY_OP,
92709279
[BINARY_OP_ADD_FLOAT] = _TAIL_CALL_BINARY_OP_ADD_FLOAT,
@@ -9482,5 +9491,45 @@ static py_tail_call_funcptr INSTRUCTION_TABLE[256] = {
94829491
[UNPACK_SEQUENCE_TWO_TUPLE] = _TAIL_CALL_UNPACK_SEQUENCE_TWO_TUPLE,
94839492
[WITH_EXCEPT_START] = _TAIL_CALL_WITH_EXCEPT_START,
94849493
[YIELD_VALUE] = _TAIL_CALL_YIELD_VALUE,
9494+
[117] = _TAIL_CALL_UNKNOWN_OPCODE,
9495+
[118] = _TAIL_CALL_UNKNOWN_OPCODE,
9496+
[119] = _TAIL_CALL_UNKNOWN_OPCODE,
9497+
[120] = _TAIL_CALL_UNKNOWN_OPCODE,
9498+
[121] = _TAIL_CALL_UNKNOWN_OPCODE,
9499+
[122] = _TAIL_CALL_UNKNOWN_OPCODE,
9500+
[123] = _TAIL_CALL_UNKNOWN_OPCODE,
9501+
[124] = _TAIL_CALL_UNKNOWN_OPCODE,
9502+
[125] = _TAIL_CALL_UNKNOWN_OPCODE,
9503+
[126] = _TAIL_CALL_UNKNOWN_OPCODE,
9504+
[127] = _TAIL_CALL_UNKNOWN_OPCODE,
9505+
[128] = _TAIL_CALL_UNKNOWN_OPCODE,
9506+
[129] = _TAIL_CALL_UNKNOWN_OPCODE,
9507+
[130] = _TAIL_CALL_UNKNOWN_OPCODE,
9508+
[131] = _TAIL_CALL_UNKNOWN_OPCODE,
9509+
[132] = _TAIL_CALL_UNKNOWN_OPCODE,
9510+
[133] = _TAIL_CALL_UNKNOWN_OPCODE,
9511+
[134] = _TAIL_CALL_UNKNOWN_OPCODE,
9512+
[135] = _TAIL_CALL_UNKNOWN_OPCODE,
9513+
[136] = _TAIL_CALL_UNKNOWN_OPCODE,
9514+
[137] = _TAIL_CALL_UNKNOWN_OPCODE,
9515+
[138] = _TAIL_CALL_UNKNOWN_OPCODE,
9516+
[139] = _TAIL_CALL_UNKNOWN_OPCODE,
9517+
[140] = _TAIL_CALL_UNKNOWN_OPCODE,
9518+
[141] = _TAIL_CALL_UNKNOWN_OPCODE,
9519+
[142] = _TAIL_CALL_UNKNOWN_OPCODE,
9520+
[143] = _TAIL_CALL_UNKNOWN_OPCODE,
9521+
[144] = _TAIL_CALL_UNKNOWN_OPCODE,
9522+
[145] = _TAIL_CALL_UNKNOWN_OPCODE,
9523+
[146] = _TAIL_CALL_UNKNOWN_OPCODE,
9524+
[147] = _TAIL_CALL_UNKNOWN_OPCODE,
9525+
[148] = _TAIL_CALL_UNKNOWN_OPCODE,
9526+
[228] = _TAIL_CALL_UNKNOWN_OPCODE,
9527+
[229] = _TAIL_CALL_UNKNOWN_OPCODE,
9528+
[230] = _TAIL_CALL_UNKNOWN_OPCODE,
9529+
[231] = _TAIL_CALL_UNKNOWN_OPCODE,
9530+
[232] = _TAIL_CALL_UNKNOWN_OPCODE,
9531+
[233] = _TAIL_CALL_UNKNOWN_OPCODE,
9532+
[234] = _TAIL_CALL_UNKNOWN_OPCODE,
9533+
[235] = _TAIL_CALL_UNKNOWN_OPCODE,
94859534
};
94869535
#undef TIER_ONE

Tools/cases_generator/tier1_tail_call_generator.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def generate_tier1(
8282
out.emit("static inline PyObject *_TAIL_CALL_shim(TAIL_CALL_PARAMS);\n")
8383
out.emit("static py_tail_call_funcptr INSTRUCTION_TABLE[256];\n");
8484

85-
# Emit error handlers
86-
8785
generate_label_handlers(outfile)
8886

8987
emitter = Emitter(out)
@@ -105,9 +103,27 @@ def generate_tier1(
105103

106104
out.emit("\n")
107105

106+
# Emit unknown opcode handler.
107+
out.emit(function_proto("UNKNOWN_OPCODE"))
108+
out.emit("{\n")
109+
out.emit("""
110+
int opcode = next_instr->op.code;
111+
_PyErr_Format(tstate, PyExc_SystemError,
112+
"%U:%d: unknown opcode %d",
113+
_PyFrame_GetCode(frame)->co_filename,
114+
PyUnstable_InterpreterFrame_GetLine(frame),
115+
opcode);
116+
""")
117+
out.emit("CEVAL_GOTO(error);")
118+
out.emit("}\n")
119+
108120
out.emit("static py_tail_call_funcptr INSTRUCTION_TABLE[256] = {\n")
109121
for name in sorted(analysis.instructions.keys()):
110122
out.emit(f"[{name}] = _TAIL_CALL_{name},\n")
123+
named_values = analysis.opmap.values()
124+
for rest in range(256):
125+
if rest not in named_values:
126+
out.emit(f"[{rest}] = _TAIL_CALL_UNKNOWN_OPCODE,\n")
111127
out.emit("};\n")
112128
outfile.write(FOOTER)
113129

0 commit comments

Comments
 (0)