8000 GH-91409: Don't overwrite valid locations with `NOP` locations by brandtbucher · Pull Request #95067 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-91409: Don't overwrite valid locations with NOP locations #95067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,44 @@ def test_multiline_assert_rewritten_as_method_call(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix incorrect source location info caused by certain optimizations in the
bytecode compiler.
5 changes: 4 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
0