From 1e4920c1191c8e324604bdfe3b3cd0397faf44a7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 7 Jan 2020 14:53:25 +0100 Subject: [PATCH] Renumber zval types, clarify allowed overlap Make it clear that types used for type declarations can overlap with the rest, and can also overlap in MAY_BE space. This makes things more robust against the addition of new primitive types. --- .gdbinit | 19 +++++-------------- Zend/zend_type_info.h | 12 ++++++------ Zend/zend_types.h | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/.gdbinit b/.gdbinit index a903c086e5..be901f80a2 100644 --- a/.gdbinit +++ b/.gdbinit @@ -255,31 +255,22 @@ define ____printzv_contents printf "CONSTANT_AST" end if $type == 12 - printf "CALLABLE" - end - if $type == 13 - printf "ITERABLE" - end - if $type == 14 - printf "VOID" - end - if $type == 15 printf "indirect: " ____printzv $zvalue->value.zv $arg1 end - if $type == 16 + if $type == 13 printf "pointer: %p", $zvalue->value.ptr end - if $type == 17 + if $type == 15 printf "_ERROR" end - if $type == 18 + if $type == 16 printf "_BOOL" end - if $type == 19 + if $type == 17 printf "_NUMBER" end - if $type > 19 + if $type > 17 printf "unknown type %d", $type end printf "\n" diff --git a/Zend/zend_type_info.h b/Zend/zend_type_info.h index ef2c6a19bc..752e6a4b85 100644 --- a/Zend/zend_type_info.h +++ b/Zend/zend_type_info.h @@ -35,12 +35,13 @@ #define MAY_BE_ANY (MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE) #define MAY_BE_REF (1 << IS_REFERENCE) /* may be reference */ -/* These are used in zend_type, but not for type inference. */ +/* These are used in zend_type, but not for type inference. + * They are allowed to overlap with types used during inference. */ #define MAY_BE_CALLABLE (1 << IS_CALLABLE) #define MAY_BE_ITERABLE (1 << IS_ITERABLE) #define MAY_BE_VOID (1 << IS_VOID) -#define MAY_BE_ARRAY_SHIFT (IS_VOID) +#define MAY_BE_ARRAY_SHIFT (IS_REFERENCE) #define MAY_BE_ARRAY_OF_NULL (MAY_BE_NULL << MAY_BE_ARRAY_SHIFT) #define MAY_BE_ARRAY_OF_FALSE (MAY_BE_FALSE << MAY_BE_ARRAY_SHIFT) @@ -54,11 +55,10 @@ #define MAY_BE_ARRAY_OF_ANY (MAY_BE_ANY << MAY_BE_ARRAY_SHIFT) #define MAY_BE_ARRAY_OF_REF (MAY_BE_REF << MAY_BE_ARRAY_SHIFT) -#define MAY_BE_ARRAY_KEY_LONG (1<<25) -#define MAY_BE_ARRAY_KEY_STRING (1<<26) +#define MAY_BE_ARRAY_KEY_LONG (1<<21) +#define MAY_BE_ARRAY_KEY_STRING (1<<22) #define MAY_BE_ARRAY_KEY_ANY (MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_KEY_STRING) -/* Bit 27 unused */ -#define MAY_BE_CLASS (1<<28) +#define MAY_BE_CLASS (1<<23) #endif /* ZEND_TYPE_INFO_H */ diff --git a/Zend/zend_types.h b/Zend/zend_types.h index e32538591b..20fddd74c9 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -137,7 +137,6 @@ typedef struct { #define _ZEND_TYPE_EXTRA_FLAGS_SHIFT 24 #define _ZEND_TYPE_MASK ((1u << 24) - 1) -#define _ZEND_TYPE_MAY_BE_MASK ((1u << (IS_VOID+1)) - 1) /* Only one of these bits may be set. */ #define _ZEND_TYPE_NAME_BIT (1u << 23) #define _ZEND_TYPE_CE_BIT (1u << 22) @@ -145,6 +144,8 @@ typedef struct { #define _ZEND_TYPE_KIND_MASK (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_CE_BIT|_ZEND_TYPE_NAME_BIT) /* Whether the type list is arena allocated */ #define _ZEND_TYPE_ARENA_BIT (1u << 20) +/* Type mask excluding the flags above. */ +#define _ZEND_TYPE_MAY_BE_MASK ((1u << 20) - 1) /* Must have same value as MAY_BE_NULL */ #define _ZEND_TYPE_NULLABLE_BIT 0x2 @@ -533,20 +534,21 @@ struct _zend_ast_ref { #define IS_REFERENCE 10 #define IS_CONSTANT_AST 11 /* Constant expressions */ -/* Fake types used only for type hinting. IS_VOID should be the last. */ +/* Fake types used only for type hinting. + * These are allowed to overlap with the types below. */ #define IS_CALLABLE 12 #define IS_ITERABLE 13 #define IS_VOID 14 /* internal types */ -#define IS_INDIRECT 15 -#define IS_PTR 16 -#define IS_ALIAS_PTR 17 -#define _IS_ERROR 17 +#define IS_INDIRECT 12 +#define IS_PTR 13 +#define IS_ALIAS_PTR 14 +#define _IS_ERROR 15 /* used for casts */ -#define _IS_BOOL 18 -#define _IS_NUMBER 19 +#define _IS_BOOL 16 +#define _IS_NUMBER 17 static zend_always_inline zend_uchar zval_get_type(const zval* pz) { return pz->u1.v.type; -- 2.50.1