-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
import dis
def _f(a):
print(a)
dis.dis(_f)
Here is a test in Python 3.12 test_dis.py BytecodeTests.test_disassembled, It outputs:
3 0 RESUME 0
4 2 LOAD_GLOBAL 1 (NULL + print)
12 LOAD_FAST 0 (a)
14 CALL 1
22 POP_TOP
24 RETURN_CONST 0 (None)
source code for this optimization is at: https://github.com/python/cpython/blob/3.12/Python/flowgraph.c#L1556-L1560
case PUSH_NULL:
if (nextop == LOAD_GLOBAL && (inst[1].i_opcode & 1) == 0) {
INSTR_SET_OP0(inst, NOP);
inst[1].i_oparg |= 1;
}
break;
I feel the correct check should be:
if (nextop == LOAD_GLOBAL && (inst[1].i_oparg & 1) == 0)
I'm unable to write a unit test for this code to make some real error, but if opcode for LOAD_GLOBAL is changed to some odd number, test_dis will fail.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error