Skip to content

Commit f5efdc6

Browse files
committed
Fix preloading FCC const exprs
Preloading will try to evaluate class constants during compilation, but evaluated FCCs are objects, which can not be persisted. Apply the same fix as for enums: Fail evaluation when compiling. Preloading will also reset CG(map_ptr_last) after compilation, which results in collisions if map ptrs were allocated during compilation. Move the ZEND_MAP_PTR_NEW() to the persist phase, as a shared map ptr is not necessary before that.
1 parent fe6432b commit f5efdc6

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

Zend/zend_ast.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,12 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
11391139
case ZEND_AST_CALL:
11401140
case ZEND_AST_STATIC_CALL:
11411141
{
1142+
// Preloading will attempt to resolve constants but objects can't be stored in shm
1143+
// Aborting here to store the const AST instead
1144+
if (CG(in_compilation)) {
1145+
return FAILURE;
1146+
}
1147+
11421148
zend_function *fptr;
11431149
zend_class_entry *called_scope = NULL;
11441150

Zend/zend_compile.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12027,8 +12027,6 @@ static void zend_compile_const_expr_fcc(zend_ast **ast_ptr)
1202712027
zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
1202812028
}
1202912029

12030-
ZEND_MAP_PTR_NEW(((zend_ast_fcc *)*args_ast)->fptr);
12031-
1203212030
switch ((*ast_ptr)->kind) {
1203312031
case ZEND_AST_CALL: {
1203412032
zend_ast *name_ast = (*ast_ptr)->child[0];

ext/opcache/zend_persist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ static zend_ast *zend_persist_ast(zend_ast *ast)
196196
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
197197
zend_ast_fcc *copy = zend_shared_memdup(ast, sizeof(zend_ast_fcc));
198198
copy->args = zend_persist_ast(copy->args);
199+
ZEND_MAP_PTR_NEW(copy->fptr);
199200
node = (zend_ast *) copy;
200201
} else if (zend_ast_is_decl(ast)) {
201202
/* Not implemented. */

0 commit comments

Comments
 (0)