summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-07-07 12:10:32 +0200
committerGitHub <noreply@github.com>2022-07-07 03:10:32 -0700
commit74c953d396816c0ef3de80276c00d29f79cbf8bf (patch)
treefa88ff9c1acdebb30f025525507f71bdf028d7d1 /Python
parent3517c138a814a571fab512c489bacafc7a0e3f22 (diff)
downloadpython-74c953d396816c0ef3de80276c00d29f79cbf8bf.tar.gz
python-74c953d396816c0ef3de80276c00d29f79cbf8bf.zip
[3.11] gh-92228: disable the compiler's 'small exit block inlining' optimization for blocks that have a line number (GH-94592) (GH-94643)
Inlining of code that corresponds to source code lines, can make it hard to distinguish later between code which is only reachable from except handlers, and that which is reachable in normal control flow. This caused problems with the debugger's jump feature. This PR turns off the inlining optimisation for code which has line numbers. We still inline things like the implicit "return None".. (cherry picked from commit bde06e1b8381f140b296a397ddd1deb1c784ff8e) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index cfe4b6ec04f..a71e7d31eec 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -8976,6 +8976,16 @@ error:
return -1;
}
+static bool
+basicblock_has_lineno(const basicblock *bb) {
+ for (int i = 0; i < bb->b_iused; i++) {
+ if (bb->b_instr[i].i_lineno > 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
/* If this block ends with an unconditional jump to an exit block,
* then remove the jump and extend this block with the target.
*/
@@ -8992,6 +9002,10 @@ extend_block(basicblock *bb) {
}
if (last->i_target->b_exit && last->i_target->b_iused <= MAX_COPY_SIZE) {
basicblock *to_copy = last->i_target;
+ if (basicblock_has_lineno(to_copy)) {
+ /* copy only blocks without line number (like implicit 'return None's) */
+ return 0;
+ }
last->i_opcode = NOP;
for (int i = 0; i < to_copy->b_iused; i++) {
int index = compiler_next_instr(bb);