Skip to content

Commit 805321b

Browse files
committed
Review
1 parent 8c7e856 commit 805321b

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

Zend/Optimizer/zend_cfg.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *
144144
end = blocks + block_map[op_array->try_catch_array[j].finally_op];
145145
while (b != end) {
146146
if (b->flags & ZEND_BB_REACHABLE) {
147-
op_array->try_catch_array[j].try_op = b->start;
147+
/* In case we get here, there is no live try block but there is a live finally block.
148+
* If we do have catch_op set, we need to set it to the first catch block to satisfy
149+
* the constraint try_op <= catch_op <= finally_op */
150+
op_array->try_catch_array[j].try_op =
151+
op_array->try_catch_array[j].catch_op ? op_array->try_catch_array[j].catch_op : b->start;
148152
changed = 1;
149153
zend_mark_reachable(op_array->opcodes, cfg, blocks + block_map[op_array->try_catch_array[j].try_op]);
150154
break;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
GH-18107 (Opcache CFG jmp optimization with try-finally breaks the exception table)
3+
--CREDITS--
4+
SpencerMalone
5+
--EXTENSIONS--
6+
opcache
7+
--INI--
8+
opcache.optimization_level=0x10
9+
opcache.opt_debug_level=0x20000
10+
--FILE--
11+
<?php
12+
13+
if (!isset($badvar)) {
14+
throw new Exception("Should happen");
15+
}
16+
try {
17+
goto foo;
18+
} catch (Throwable $e) {
19+
echo "foo";
20+
foo:;
21+
} finally {
22+
throw new Exception("Should not happen");
23+
}
24+
25+
?>
26+
--EXPECTF--
27+
$_main:
28+
; (lines=%d, args=0, vars=%d, tmps=%d)
29+
; (after optimizer)
30+
; %s
31+
0000 T2 = ISSET_ISEMPTY_CV (isset) CV0($badvar)
32+
0001 JMPNZ T2 0008
33+
0002 V4 = NEW 1 string("Exception")
34+
0003 SEND_VAL_EX string("Should happen") 1
35+
0004 DO_FCALL
36+
0005 THROW V4
37+
0006 CV1($e) = CATCH string("Throwable")
38+
0007 ECHO string("foo")
39+
0008 T6 = FAST_CALL 0010
40+
0009 JMP 0015
41+
0010 V7 = NEW 1 string("Exception")
42+
0011 SEND_VAL_EX string("Should not happen") 1
43+
0012 DO_FCALL
44+
0013 THROW V7
45+
0014 FAST_RET T6
46+
0015 RETURN int(1)
47+
EXCEPTION TABLE:
48+
0006, 0006, 0010, 0014
49+
Fatal error: Uncaught Exception: Should happen in %s:%d
50+
Stack trace:
51+
#0 {main}
52+
thrown in %s on line %d

0 commit comments

Comments
 (0)