From 3d1b81e2c40a1da30ba6de84f6ceb7d585eded45 Mon Sep 17 00:00:00 2001 From: Dino Viehland Date: Wed, 18 Dec 2024 12:29:28 -0800 Subject: [PATCH] Mark undefined instructions as deopting to themselves Summary: When CPython hands out the bytecode it will first do a de-opt on it: https://www.internalfb.com/code/fbsource/[241e0d0760d4c107a3c0ac2b4914524120b0c909]/third-party/python/3.12/Objects/codeobject.c?lines=1540&reveal=1540 This uses the de-opt table which only defines the known opcodes, meaning unknown opcodes get turned into 0's. We need CPython to at least define unknown opcodes to at least de-opt to themselves. Upstream PR: https://github.com/python/cpython/pull/128044 Reviewed By: jbower-fb Differential Revision: D67350914 fbshipit-source-id: 0073efab52da1be775272e7dd9ae5a46468ccb10 --- Include/internal/pycore_opcode.h | 62 ++++++++++++++++++++++++++++++++ Tools/build/generate_opcode_h.py | 3 ++ 2 files changed, 65 insertions(+) diff --git a/Include/internal/pycore_opcode.h b/Include/internal/pycore_opcode.h index e8258b3f90f..12b2861c455 100644 --- a/Include/internal/pycore_opcode.h +++ b/Include/internal/pycore_opcode.h @@ -241,6 +241,68 @@ const uint8_t _PyOpcode_Deopt[256] = { [UNPACK_SEQUENCE_TWO_TUPLE] = UNPACK_SEQUENCE, [WITH_EXCEPT_START] = WITH_EXCEPT_START, [YIELD_VALUE] = YIELD_VALUE, + [169] = 169, + [170] = 170, + [177] = 177, + [178] = 178, + [179] = 179, + [180] = 180, + [181] = 181, + [182] = 182, + [184] = 184, + [185] = 185, + [186] = 186, + [187] = 187, + [188] = 188, + [189] = 189, + [190] = 190, + [191] = 191, + [192] = 192, + [193] = 193, + [194] = 194, + [195] = 195, + [196] = 196, + [197] = 197, + [198] = 198, + [199] = 199, + [200] = 200, + [201] = 201, + [202] = 202, + [203] = 203, + [204] = 204, + [205] = 205, + [206] = 206, + [207] = 207, + [208] = 208, + [209] = 209, + [210] = 210, + [211] = 211, + [212] = 212, + [213] = 213, + [214] = 214, + [215] = 215, + [216] = 216, + [217] = 217, + [218] = 218, + [219] = 219, + [220] = 220, + [221] = 221, + [222] = 222, + [223] = 223, + [224] = 224, + [225] = 225, + [226] = 226, + [227] = 227, + [228] = 228, + [229] = 229, + [230] = 230, + [231] = 231, + [232] = 232, + [233] = 233, + [234] = 234, + [235] = 235, + [236] = 236, + [255] = 255, }; #endif // NEED_OPCODE_TABLES diff --git a/Tools/build/generate_opcode_h.py b/Tools/build/generate_opcode_h.py index 5be98100572..f784458a20f 100644 --- a/Tools/build/generate_opcode_h.py +++ b/Tools/build/generate_opcode_h.py @@ -168,6 +168,9 @@ def main(opcode_py, outfile='Include/opcode.h', iobj.write("\nconst uint8_t _PyOpcode_Deopt[256] = {\n") for opt, deopt in sorted(deoptcodes.items()): iobj.write(f" [{opt}] = {deopt},\n") + for i, name in enumerate(opname): + if not used[i]: + iobj.write(f" [{i}] = {i},\n") iobj.write("};\n") iobj.write("#endif // NEED_OPCODE_TABLES\n")