1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

[Zend]: Fix unnecessary alignment in ZEND_CALL_FRAME_SLOT macro (#10988)

Alignment is not necessary while calculating slots reserved for
zend_execute_data and _zend_vm_stack.

ZEND_STATIC_ASSERT ensures the correct alignment while code
compilation. Credit is to Ilija Tovilo.

PR: https://github.com/php/php-src/pull/10988

Signed-off-by: Tony Su <tao.su@intel.com>
Reviewed-by  : Ilija Tovilo
Reviewed-by  : Dmitry Stogov
Reviewed-by  : Niels Dossche
This commit is contained in:
Tony Su
2023-04-04 18:09:38 +08:00
committed by GitHub
parent 44b1619370
commit bf123da562
3 changed files with 16 additions and 2 deletions

View File

@@ -606,8 +606,12 @@ struct _zend_execute_data {
#define ZEND_CALL_NUM_ARGS(call) \
(call)->This.u2.num_args
/* Ensure the correct alignment before slots calculation */
ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
"zval must be aligned by ZEND_MM_ALIGNMENT");
/* A number of call frame slots (zvals) reserved for zend_execute_data. */
#define ZEND_CALL_FRAME_SLOT \
((int)((ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval))))
((int)((sizeof(zend_execute_data) + sizeof(zval) - 1) / sizeof(zval)))
#define ZEND_CALL_VAR(call, n) \
((zval*)(((char*)(call)) + ((int)(n))))

View File

@@ -195,8 +195,12 @@ struct _zend_vm_stack {
zend_vm_stack prev;
};
/* Ensure the correct alignment before slots calculation */
ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
"zval must be aligned by ZEND_MM_ALIGNMENT");
/* A number of call frame slots (zvals) reserved for _zend_vm_stack. */
#define ZEND_VM_STACK_HEADER_SLOTS \
((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
((sizeof(struct _zend_vm_stack) + sizeof(zval) - 1) / sizeof(zval))
#define ZEND_VM_STACK_ELEMENTS(stack) \
(((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)

View File

@@ -750,4 +750,10 @@ extern "C++" {
# define ZEND_CGG_DIAGNOSTIC_IGNORED_END
#endif
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
# define ZEND_STATIC_ASSERT(c, m) _Static_assert((c), m)
#else
# define ZEND_STATIC_ASSERT(c, m)
#endif
#endif /* ZEND_PORTABILITY_H */