mirror of
https://github.com/python/cpython.git
synced 2024-11-28 12:31:14 +08:00
GH-91409: Don't overwrite valid locations with NOP locations (GH-95067)
This commit is contained in:
parent
41e0585ffa
commit
742d4614e1
@ -1202,6 +1202,44 @@ f(
|
||||
tree.body[0] = new_node
|
||||
compile(tree, "<test>", "exec")
|
||||
|
||||
def test_push_null_load_global_positions(self):
|
||||
source_template = """
|
||||
import abc, dis
|
||||
import ast as art
|
||||
|
||||
abc = None
|
||||
dix = dis
|
||||
ast = art
|
||||
|
||||
def f():
|
||||
{}
|
||||
"""
|
||||
for body in [
|
||||
" abc.a()",
|
||||
" art.a()",
|
||||
" ast.a()",
|
||||
" dis.a()",
|
||||
" dix.a()",
|
||||
" abc[...]()",
|
||||
" art()()",
|
||||
" (ast or ...)()",
|
||||
" [dis]()",
|
||||
" (dix + ...)()",
|
||||
]:
|
||||
with self.subTest(body):
|
||||
namespace = {}
|
||||
source = textwrap.dedent(source_template.format(body))
|
||||
exec(source, namespace)
|
||||
code = namespace["f"].__code__
|
||||
self.assertOpcodeSourcePositionIs(
|
||||
code,
|
||||
"LOAD_GLOBAL",
|
||||
line=10,
|
||||
end_line=10,
|
||||
column=4,
|
||||
end_column=7,
|
||||
)
|
||||
|
||||
|
||||
class TestExpressionStackSize(unittest.TestCase):
|
||||
# These tests check that the computed stack size for a code object
|
||||
|
@ -0,0 +1,2 @@
|
||||
Fix incorrect source location info caused by certain optimizations in the
|
||||
bytecode compiler.
|
@ -9278,7 +9278,10 @@ clean_basic_block(basicblock *bb) {
|
||||
/* or, if the next instruction has same line number or no line number */
|
||||
if (src < bb->b_iused - 1) {
|
||||
int next_lineno = bb->b_instr[src+1].i_loc.lineno;
|
||||
if (next_lineno < 0 || next_lineno == lineno) {
|
||||
if (next_lineno == lineno) {
|
||||
continue;
|
||||
}
|
||||
if (next_lineno < 0) {
|
||||
bb->b_instr[src+1].i_loc = bb->b_instr[src].i_loc;
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user