Skip to content

Commit f199de9

Browse files
committed
Zend: silence -Warray-bounds false positive in zend_vm_init_call_frame
ZEND_CLOSURE_OBJECT() steps back from the func pointer to the enclosing zend_closure; under -O2 GCC reads that as an out-of-bounds access of func and -Werror=array-bounds fails the build. The access is valid (func is embedded in the closure), so guard it with a localized GCC diagnostic pragma. Needed for --enable-werror release builds.
1 parent 1692bfd commit f199de9

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Zend/zend_execute.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,18 @@ static zend_always_inline void zend_vm_init_call_frame(zend_execute_data *call,
345345
* call-frame teardown skips destroying it. VERIFY_GENERIC_ARGUMENTS may
346346
* still overwrite type_args later for explicit-turbofish calls. */
347347
if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_CLOSURE)) {
348+
/* ZEND_CLOSURE_OBJECT() steps back from func to the enclosing closure;
349+
* GCC's -Warray-bounds wrongly reads that as out-of-bounds of func. */
350+
#if defined(__GNUC__) && !defined(__clang__)
351+
# pragma GCC diagnostic push
352+
# pragma GCC diagnostic ignored "-Warray-bounds"
353+
#endif
348354
const zend_closure *closure =
349355
(const zend_closure *) ZEND_CLOSURE_OBJECT(func);
350356
call->type_args = closure->captured_type_args;
357+
#if defined(__GNUC__) && !defined(__clang__)
358+
# pragma GCC diagnostic pop
359+
#endif
351360
} else if (UNEXPECTED(ZEND_USER_CODE(func->type)
352361
&& (func->op_array.fn_flags2 & ZEND_ACC2_MONOMORPH_TYPE_ARGS))) {
353362
/* Monomorph reached via by-name dispatch: bind its concrete type-arg table. */

0 commit comments

Comments
 (0)