Skip to content

Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0) #5726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ static void zend_get_windows_version_info(OSVERSIONINFOEX *osvi) /* {{{ */
ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if(!GetVersionEx((OSVERSIONINFO *) osvi)) {
ZEND_ASSERT(0); /* Should not happen as sizeof is used. */
ZEND_UNREACHABLE(); /* Should not happen as sizeof is used. */
}
}
/* }}} */
Expand Down Expand Up @@ -1718,7 +1718,7 @@ ZEND_API void *zend_map_ptr_new(void)
if (CG(map_ptr_last) >= CG(map_ptr_size)) {
#if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
// TODO: error ???
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
#elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
/* Grow map_ptr table */
CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(CG(map_ptr_last) + 1, 4096);
Expand Down Expand Up @@ -1747,7 +1747,7 @@ ZEND_API void zend_map_ptr_extend(size_t last)
if (last >= CG(map_ptr_size)) {
#if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
/* This may never happen */
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
#elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
/* Grow map_ptr table */
CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(last, 4096);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
break;
case ZEND_AST_ZNODE:
/* This AST kind is only used for temporary nodes during compilation */
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
break;

/* declaration nodes */
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ zend_ast *zend_negate_num_string(zend_ast *ast) /* {{{ */
memmove(Z_STRVAL_P(zv) + 1, Z_STRVAL_P(zv), orig_len + 1);
Z_STRVAL_P(zv)[0] = '-';
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
return ast;
}
Expand Down Expand Up @@ -2258,7 +2258,7 @@ static void zend_compile_memoized_expr(znode *result, zend_ast *expr) /* {{{ */
Z_TRY_ADDREF(result->u.constant);
}
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void _zend_is_inconsistent(const HashTable *ht, const char *file, int lin
zend_output_debug_string(1, "%s(%d) : ht=%p is inconsistent", file, line, ht);
break;
}
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
#define IS_CONSISTENT(a) _zend_is_inconsistent(a, __FILE__, __LINE__);
#define SET_INCONSISTENT(n) do { \
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
zend_class_init_statics(parent_ce);
}
if (UNEXPECTED(zend_update_class_constants(parent_ce) != SUCCESS)) {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
src = CE_STATIC_MEMBERS(parent_ce) + parent_ce->default_static_members_count;
do {
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ ZEND_API HashTable *zend_std_get_properties_for(zend_object *obj, zend_prop_purp
}
return ht;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return NULL;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ static void emit_live_range(
case ZEND_ADD_ARRAY_ELEMENT:
case ZEND_ADD_ARRAY_UNPACK:
case ZEND_ROPE_ADD:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return;
/* Result is boolean, it doesn't have to be destroyed. */
case ZEND_JMPZ_EX:
Expand Down Expand Up @@ -1131,7 +1131,7 @@ ZEND_API binary_op_type get_binary_op(int opcode)
case ZEND_BOOL_XOR:
return (binary_op_type) boolean_xor_function;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return (binary_op_type) NULL;
}
}
2 changes: 1 addition & 1 deletion Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2) /* {{{ */
} else if (Z_TYPE_P(op2)==IS_ARRAY) {
return -1;
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
zend_throw_error(NULL, "Unsupported operand types");
return 1;
}
Expand Down
10 changes: 6 additions & 4 deletions Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@
# define ZEND_ASSERT(c) ZEND_ASSUME(c)
#endif

/* Only use this macro if you know for sure that all of the switches values
are covered by its case statements */
#if ZEND_DEBUG
# define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_ASSERT(0); break;
# define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); ZEND_ASSUME(0);} while (0)
#else
# define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_ASSUME(0); break;
# define ZEND_UNREACHABLE() ZEND_ASSUME(0)
#endif

/* Only use this macro if you know for sure that all of the switches values
are covered by its case statements */
#define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_UNREACHABLE(); break;

#if defined(__GNUC__) && __GNUC__ >= 4
# define ZEND_IGNORE_VALUE(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
#else
Expand Down
12 changes: 6 additions & 6 deletions ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ static int zend_ffi_ctype_name(zend_ffi_ctype_name_buf *buf, const zend_ffi_type
}
break;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
if (name) {
break;
Expand Down Expand Up @@ -1992,7 +1992,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zend_object *obj, int *is_temp)
return ht;
break;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
break;
}
return NULL;
Expand Down Expand Up @@ -5364,7 +5364,7 @@ void zend_ffi_resolve_const(const char *name, size_t name_len, zend_ffi_val *val
val->kind = ZEND_FFI_VAL_UINT64;
break;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
return;
}
Expand Down Expand Up @@ -6185,7 +6185,7 @@ void zend_ffi_declare_tag(const char *name, size_t name_len, zend_ffi_dcl *dcl,
return;
}
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return;
}
dcl->type = type;
Expand All @@ -6212,7 +6212,7 @@ void zend_ffi_declare_tag(const char *name, size_t name_len, zend_ffi_dcl *dcl,
type = ZEND_FFI_TYPE(dcl->type);
type->enumeration.tag_name = zend_string_copy(tag_name);
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
tag->type = ZEND_FFI_TYPE_MAKE_OWNED(dcl->type);
dcl->type = ZEND_FFI_TYPE(dcl->type);
Expand Down Expand Up @@ -6511,7 +6511,7 @@ static int zend_ffi_nested_type(zend_ffi_type *type, zend_ffi_type *nested_type)
}
break;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
}
/* }}} */
Expand Down
4 changes: 2 additions & 2 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
(*func_p)(im, fp, q, t);
break;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
fflush(fp);
fclose(fp);
Expand All @@ -1899,7 +1899,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
(*func_p)(im, tmp, q, t);
break;
default:
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}

fseek(tmp, 0, SEEK_SET);
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/optimize_func_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
|| fcall->opcode == ZEND_NEW) {
/* We don't have specialized opcodes for this, do nothing */
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}

if ((ZEND_OPTIMIZER_PASS_16 & ctx->optimization_level)
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static zend_bool can_replace_op1(
(opline - 1)->opcode != ZEND_ASSIGN_STATIC_PROP_REF;
default:
if (ssa_op->op1_def != -1) {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/scdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static inline uint32_t scdf_edge(zend_cfg *cfg, int from, int to) {
return edge;
}
}
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}

static inline zend_bool scdf_is_edge_feasible(scdf_ctx *scdf, int from, int to) {
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,7 @@ static zend_always_inline int _zend_update_type_info(
case ZEND_CATCH:
case ZEND_INCLUDE_OR_EVAL:
/* Forbidden opcodes */
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
break;
default:
unknown_opcode:
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/zend_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
ZEND_ASSERT(opline->extended_value == ZEND_FREE_ON_RETURN);
MAKE_NOP(opline);
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
}
opline++;
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/Optimizer/zend_ssa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ int zend_ssa_unlink_use_chain(zend_ssa *ssa, int op, int var) /* {{{ */
}
}
/* something wrong */
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return 0;
}
}
Expand Down Expand Up @@ -1238,7 +1238,7 @@ static inline zend_ssa_phi **zend_ssa_next_use_phi_ptr(zend_ssa *ssa, int var, z
}
}
}
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return NULL;
}
/* }}} */
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3373,7 +3373,7 @@ ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
return SUCCESS;
}
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
}

Expand Down Expand Up @@ -3485,7 +3485,7 @@ ZEND_EXT_API int zend_jit_script(zend_script *script)
ZEND_SET_FUNC_INFO(call_graph.op_arrays[i], NULL);
}
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}

zend_arena_release(&CG(arena), checkpoint);
Expand Down
6 changes: 3 additions & 3 deletions ext/opcache/jit/zend_jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ static zend_always_inline const zend_op* zend_jit_trace_get_exit_opline(zend_jit
*exit_if_true = opline->opcode == ZEND_JMPZ;
return opline + 1;
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
*exit_if_true = 0;
return NULL;
Expand All @@ -476,7 +476,7 @@ static zend_always_inline zend_bool zend_jit_may_be_polymorphic_call(const zend_
} else if (opline->opcode == ZEND_NEW) {
return (opline->op1_type != IS_CONST);
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return 0;
}
}
Expand Down
20 changes: 10 additions & 10 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_fla
} else if (trace_flags & ZEND_JIT_TRACE_START_RETURN) {
return "return";
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return "???";
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ static uint32_t zend_jit_find_trace(const void *addr)
return i;
}
}
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
return 0;
}

Expand Down Expand Up @@ -2711,7 +2711,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
} else if (i < parent_vars_count
&& STACK_TYPE(parent_stack, i) != IS_UNKNOWN) {
/* This must be already handled by trace type inference */
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
SET_STACK_TYPE(stack, i, STACK_TYPE(parent_stack, i));
} else if ((info & MAY_BE_GUARD) != 0
&& trace_buffer->stop == ZEND_JIT_TRACE_STOP_LOOP
Expand All @@ -2729,7 +2729,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
&& op_array->function_name
&& i >= op_array->num_args) {
/* This must be already handled by trace type inference */
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
SET_STACK_TYPE(stack, i, IS_UNDEF);
} else {
SET_STACK_TYPE(stack, i, IS_UNKNOWN);
Expand Down Expand Up @@ -3557,7 +3557,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
smart_branch_opcode = opline->opcode;
exit_opline = OP_JMP_ADDR(opline, opline->op2);
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
if (ra) {
zend_jit_trace_clenup_stack(stack, opline, ssa_op, ssa, ra);
Expand All @@ -3568,7 +3568,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
goto jit_failure;
}
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
if (opline->result_type == IS_UNDEF) {
res_addr = 0;
Expand Down Expand Up @@ -4202,7 +4202,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
frame->call = call->prev;
}
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
}

Expand Down Expand Up @@ -5246,7 +5246,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
} else if (STACK_REG(stack, i) == ZREG_LONG_MAX) {
val = ZEND_LONG_MAX;
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
ZVAL_LONG(EX_VAR_NUM(i), val);
} else if (STACK_TYPE(stack, i) == IS_DOUBLE) {
Expand All @@ -5259,11 +5259,11 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
} else if (STACK_REG(stack, i) == ZREG_LONG_MAX_PLUS_1) {
val = (double)ZEND_LONG_MAX + 1.0;
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
ZVAL_DOUBLE(EX_VAR_NUM(i), val);
} else {
ZEND_ASSERT(0);
ZEND_UNREACHABLE();
}
}
}
Expand Down
Loading