Skip to content

Commit 04c54f3

Browse files
committed
Zend: make exit/die a function instead of a language construct
1 parent 6ffd120 commit 04c54f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1355
-1401
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
868868
break;
869869

870870
case ZEND_RETURN:
871-
case ZEND_EXIT:
872871
if (opline->op1_type == IS_TMP_VAR) {
873872
src = VAR_SOURCE(opline->op1);
874873
if (src && src->opcode == ZEND_QM_ASSIGN) {
@@ -1221,8 +1220,7 @@ static void zend_jmp_optimization(zend_basic_block *block, zend_op_array *op_arr
12211220
target = op_array->opcodes + target_block->start;
12221221
if ((target->opcode == ZEND_RETURN ||
12231222
target->opcode == ZEND_RETURN_BY_REF ||
1224-
target->opcode == ZEND_GENERATOR_RETURN ||
1225-
target->opcode == ZEND_EXIT) &&
1223+
target->opcode == ZEND_GENERATOR_RETURN) &&
12261224
!(op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
12271225
/* JMP L, L: RETURN to immediate RETURN */
12281226
*last_op = *target;

Zend/Optimizer/pass1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
331331
case ZEND_RETURN:
332332
case ZEND_RETURN_BY_REF:
333333
case ZEND_GENERATOR_RETURN:
334-
case ZEND_EXIT:
335334
case ZEND_THROW:
336335
case ZEND_MATCH_ERROR:
337336
case ZEND_CATCH:

Zend/Optimizer/pass3.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ void zend_optimizer_pass3(zend_op_array *op_array, zend_optimizer_ctx *ctx)
8888
MAKE_NOP(opline);
8989
} else if ((target->opcode == ZEND_RETURN ||
9090
target->opcode == ZEND_RETURN_BY_REF ||
91-
target->opcode == ZEND_GENERATOR_RETURN ||
92-
target->opcode == ZEND_EXIT) &&
91+
target->opcode == ZEND_GENERATOR_RETURN) &&
9392
!(op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
9493
/* JMP L, L: RETURN to immediate RETURN */
9594
*opline = *target;

Zend/Optimizer/zend_call_graph.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
161161
call_info->send_unpack = 1;
162162
}
163163
break;
164-
case ZEND_EXIT:
165-
/* In this case the DO_CALL opcode may have been dropped
166-
* and caller_call_opline will be NULL. */
167-
break;
168164
}
169165
opline++;
170166
}

Zend/Optimizer/zend_cfg.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
303303
}
304304
break;
305305
case ZEND_MATCH_ERROR:
306-
case ZEND_EXIT:
307306
case ZEND_THROW:
308307
/* Don't treat THROW as terminator if it's used in expression context,
309308
* as we may lose live ranges when eliminating unreachable code. */
@@ -507,7 +506,6 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array,
507506
case ZEND_RETURN:
508507
case ZEND_RETURN_BY_REF:
509508
case ZEND_GENERATOR_RETURN:
510-
case ZEND_EXIT:
511509
case ZEND_THROW:
512510
case ZEND_MATCH_ERROR:
513511
case ZEND_VERIFY_NEVER_TYPE:

Zend/tests/arginfo_zpp_mismatch.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ function skipFunction($function): bool {
66
|| $function === 'readline'
77
|| $function === 'readline_read_history'
88
|| $function === 'readline_write_history'
9+
/* terminates script */
10+
|| $function === 'exit'
11+
|| $function === 'die'
912
/* intentionally violate invariants */
1013
|| $function === 'zend_create_unterminated_string'
1114
|| $function === 'zend_test_array_return'

Zend/tests/exit/ast_print_assert_die_const.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
AssertionError: assert(0 && exit)
16+
AssertionError: assert(0 && die)

Zend/tests/exit/ast_print_assert_die_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
AssertionError: assert(0 && exit)
16+
AssertionError: assert(0 && die())

Zend/tests/exit/ast_print_assert_exit_function.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313

1414
?>
1515
--EXPECT--
16-
AssertionError: assert(0 && exit)
16+
AssertionError: assert(0 && exit())

Zend/tests/exit/define_die_constant.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ var_dump(die);
99

1010
?>
1111
--EXPECTF--
12-
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d
12+
Fatal error: Cannot define constant with name die in %s on line %d

0 commit comments

Comments
 (0)