Skip to content

Commit bf123da

Browse files
author
Tony Su
authored
[Zend]: Fix unnecessary alignment in ZEND_CALL_FRAME_SLOT macro (php#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: php#10988 Signed-off-by: Tony Su <[email protected]> Reviewed-by : Ilija Tovilo Reviewed-by : Dmitry Stogov Reviewed-by : Niels Dossche
1 parent 44b1619 commit bf123da

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Zend/zend_compile.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,12 @@ struct _zend_execute_data {
606606
#define ZEND_CALL_NUM_ARGS(call) \
607607
(call)->This.u2.num_args
608608

609+
/* Ensure the correct alignment before slots calculation */
610+
ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
611+
"zval must be aligned by ZEND_MM_ALIGNMENT");
612+
/* A number of call frame slots (zvals) reserved for zend_execute_data. */
609613
#define ZEND_CALL_FRAME_SLOT \
610-
((int)((ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval))))
614+
((int)((sizeof(zend_execute_data) + sizeof(zval) - 1) / sizeof(zval)))
611615

612616
#define ZEND_CALL_VAR(call, n) \
613617
((zval*)(((char*)(call)) + ((int)(n))))

Zend/zend_execute.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,12 @@ struct _zend_vm_stack {
195195
zend_vm_stack prev;
196196
};
197197

198+
/* Ensure the correct alignment before slots calculation */
199+
ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
200+
"zval must be aligned by ZEND_MM_ALIGNMENT");
201+
/* A number of call frame slots (zvals) reserved for _zend_vm_stack. */
198202
#define ZEND_VM_STACK_HEADER_SLOTS \
199-
((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
203+
((sizeof(struct _zend_vm_stack) + sizeof(zval) - 1) / sizeof(zval))
200204

201205
#define ZEND_VM_STACK_ELEMENTS(stack) \
202206
(((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)

Zend/zend_portability.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,4 +750,10 @@ extern "C++" {
750750
# define ZEND_CGG_DIAGNOSTIC_IGNORED_END
751751
#endif
752752

753+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
754+
# define ZEND_STATIC_ASSERT(c, m) _Static_assert((c), m)
755+
#else
756+
# define ZEND_STATIC_ASSERT(c, m)
757+
#endif
758+
753759
#endif /* ZEND_PORTABILITY_H */

0 commit comments

Comments
 (0)