Skip to content

Commit 3a9036a

Browse files
committed
Stricter verification of func info against arg info
Make sure they're actually the same up to cases where func info allows more accurate expressions. There are some awkward edge cases around true/false/null limitations in union types.
1 parent 6e09a3e commit 3a9036a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,12 +932,23 @@ uint32_t zend_get_func_info(
932932
}
933933

934934
#if ZEND_DEBUG
935-
/* Check whether the func_info information is a subset of the information we can compute
936-
* from the specified return type. */
937935
if (internal_ret) {
936+
/* Check whether the func_info information is a subset of the information we can
937+
* compute from the specified return type, otherwise it contains redundant types. */
938938
if (internal_ret & ~ret) {
939939
fprintf(stderr, "Inaccurate func info for %s()\n", ZSTR_VAL(lcname));
940940
}
941+
/* If the return type is not mixed, check that the types match exactly if we exclude
942+
* RC and array information. */
943+
uint32_t ret_any = ret & MAY_BE_ANY, internal_ret_any = internal_ret & MAY_BE_ANY;
944+
if (ret_any != MAY_BE_ANY) {
945+
uint32_t diff = internal_ret_any ^ ret_any;
946+
/* Func info may contain "true" types as well as isolated "null" and "false". */
947+
if (diff && !(diff == MAY_BE_FALSE && (ret & MAY_BE_FALSE))
948+
&& (internal_ret_any & ~(MAY_BE_NULL|MAY_BE_FALSE))) {
949+
fprintf(stderr, "Incorrect func info for %s()\n", ZSTR_VAL(lcname));
950+
}
951+
}
941952
return internal_ret;
942953
}
943954
#endif

0 commit comments

Comments
 (0)