Skip to content

Commit 92c4b06

Browse files
committed
Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce `ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)` to mark unreachable code does no longer trigger C4715[1] warnings in debug builds. This may be useful for other compilers as well. [1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
1 parent 9ff3230 commit 92c4b06

26 files changed

+122
-120
lines changed

Zend/zend.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ static void zend_get_windows_version_info(OSVERSIONINFOEX *osvi) /* {{{ */
529529
ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
530530
osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
531531
if(!GetVersionEx((OSVERSIONINFO *) osvi)) {
532-
ZEND_ASSERT(0); /* Should not happen as sizeof is used. */
532+
ZEND_UNREACHABLE(); /* Should not happen as sizeof is used. */
533533
}
534534
}
535535
/* }}} */
@@ -1718,7 +1718,7 @@ ZEND_API void *zend_map_ptr_new(void)
17181718
if (CG(map_ptr_last) >= CG(map_ptr_size)) {
17191719
#if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
17201720
// TODO: error ???
1721-
ZEND_ASSERT(0);
1721+
ZEND_UNREACHABLE();
17221722
#elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
17231723
/* Grow map_ptr table */
17241724
CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(CG(map_ptr_last) + 1, 4096);
@@ -1747,7 +1747,7 @@ ZEND_API void zend_map_ptr_extend(size_t last)
17471747
if (last >= CG(map_ptr_size)) {
17481748
#if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
17491749
/* This may never happen */
1750-
ZEND_ASSERT(0);
1750+
ZEND_UNREACHABLE();
17511751
#elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
17521752
/* Grow map_ptr table */
17531753
CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(last, 4096);

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
14651465
break;
14661466
case ZEND_AST_ZNODE:
14671467
/* This AST kind is only used for temporary nodes during compilation */
1468-
ZEND_ASSERT(0);
1468+
ZEND_UNREACHABLE();
14691469
break;
14701470

14711471
/* declaration nodes */

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ zend_ast *zend_negate_num_string(zend_ast *ast) /* {{{ */
19031903
memmove(Z_STRVAL_P(zv) + 1, Z_STRVAL_P(zv), orig_len + 1);
19041904
Z_STRVAL_P(zv)[0] = '-';
19051905
} else {
1906-
ZEND_ASSERT(0);
1906+
ZEND_UNREACHABLE();
19071907
}
19081908
return ast;
19091909
}
@@ -2258,7 +2258,7 @@ static void zend_compile_memoized_expr(znode *result, zend_ast *expr) /* {{{ */
22582258
Z_TRY_ADDREF(result->u.constant);
22592259
}
22602260
} else {
2261-
ZEND_ASSERT(0);
2261+
ZEND_UNREACHABLE();
22622262
}
22632263
}
22642264
/* }}} */

Zend/zend_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void _zend_is_inconsistent(const HashTable *ht, const char *file, int lin
6868
zend_output_debug_string(1, "%s(%d) : ht=%p is inconsistent", file, line, ht);
6969
break;
7070
}
71-
ZEND_ASSERT(0);
71+
ZEND_UNREACHABLE();
7272
}
7373
#define IS_CONSISTENT(a) _zend_is_inconsistent(a, __FILE__, __LINE__);
7474
#define SET_INCONSISTENT(n) do { \

Zend/zend_inheritance.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
12801280
zend_class_init_statics(parent_ce);
12811281
}
12821282
if (UNEXPECTED(zend_update_class_constants(parent_ce) != SUCCESS)) {
1283-
ZEND_ASSERT(0);
1283+
ZEND_UNREACHABLE();
12841284
}
12851285
src = CE_STATIC_MEMBERS(parent_ce) + parent_ce->default_static_members_count;
12861286
do {

Zend/zend_object_handlers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ ZEND_API HashTable *zend_std_get_properties_for(zend_object *obj, zend_prop_purp
17571757
}
17581758
return ht;
17591759
default:
1760-
ZEND_ASSERT(0);
1760+
ZEND_UNREACHABLE();
17611761
return NULL;
17621762
}
17631763
}

Zend/zend_opcode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ static void emit_live_range(
631631
case ZEND_ADD_ARRAY_ELEMENT:
632632
case ZEND_ADD_ARRAY_UNPACK:
633633
case ZEND_ROPE_ADD:
634-
ZEND_ASSERT(0);
634+
ZEND_UNREACHABLE();
635635
return;
636636
/* Result is boolean, it doesn't have to be destroyed. */
637637
case ZEND_JMPZ_EX:
@@ -1131,7 +1131,7 @@ ZEND_API binary_op_type get_binary_op(int opcode)
11311131
case ZEND_BOOL_XOR:
11321132
return (binary_op_type) boolean_xor_function;
11331133
default:
1134-
ZEND_ASSERT(0);
1134+
ZEND_UNREACHABLE();
11351135
return (binary_op_type) NULL;
11361136
}
11371137
}

Zend/zend_operators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2) /* {{{ */
20892089
} else if (Z_TYPE_P(op2)==IS_ARRAY) {
20902090
return -1;
20912091
} else {
2092-
ZEND_ASSERT(0);
2092+
ZEND_UNREACHABLE();
20932093
zend_throw_error(NULL, "Unsupported operand types");
20942094
return 1;
20952095
}

Zend/zend_portability.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,16 @@
107107
# define ZEND_ASSERT(c) ZEND_ASSUME(c)
108108
#endif
109109

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

116+
/* Only use this macro if you know for sure that all of the switches values
117+
are covered by its case statements */
118+
#define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_UNREACHABLE(); break;
119+
118120
#if defined(__GNUC__) && __GNUC__ >= 4
119121
# define ZEND_IGNORE_VALUE(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
120122
#else

ext/ffi/ffi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ static int zend_ffi_ctype_name(zend_ffi_ctype_name_buf *buf, const zend_ffi_type
15041504
}
15051505
break;
15061506
default:
1507-
ZEND_ASSERT(0);
1507+
ZEND_UNREACHABLE();
15081508
}
15091509
if (name) {
15101510
break;
@@ -1992,7 +1992,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zend_object *obj, int *is_temp)
19921992
return ht;
19931993
break;
19941994
default:
1995-
ZEND_ASSERT(0);
1995+
ZEND_UNREACHABLE();
19961996
break;
19971997
}
19981998
return NULL;
@@ -5364,7 +5364,7 @@ void zend_ffi_resolve_const(const char *name, size_t name_len, zend_ffi_val *val
53645364
val->kind = ZEND_FFI_VAL_UINT64;
53655365
break;
53665366
default:
5367-
ZEND_ASSERT(0);
5367+
ZEND_UNREACHABLE();
53685368
}
53695369
return;
53705370
}
@@ -6185,7 +6185,7 @@ void zend_ffi_declare_tag(const char *name, size_t name_len, zend_ffi_dcl *dcl,
61856185
return;
61866186
}
61876187
} else {
6188-
ZEND_ASSERT(0);
6188+
ZEND_UNREACHABLE();
61896189
return;
61906190
}
61916191
dcl->type = type;
@@ -6212,7 +6212,7 @@ void zend_ffi_declare_tag(const char *name, size_t name_len, zend_ffi_dcl *dcl,
62126212
type = ZEND_FFI_TYPE(dcl->type);
62136213
type->enumeration.tag_name = zend_string_copy(tag_name);
62146214
} else {
6215-
ZEND_ASSERT(0);
6215+
ZEND_UNREACHABLE();
62166216
}
62176217
tag->type = ZEND_FFI_TYPE_MAKE_OWNED(dcl->type);
62186218
dcl->type = ZEND_FFI_TYPE(dcl->type);
@@ -6511,7 +6511,7 @@ static int zend_ffi_nested_type(zend_ffi_type *type, zend_ffi_type *nested_type)
65116511
}
65126512
break;
65136513
default:
6514-
ZEND_ASSERT(0);
6514+
ZEND_UNREACHABLE();
65156515
}
65166516
}
65176517
/* }}} */

0 commit comments

Comments
 (0)