Skip to content

Enable -Wassign-enum in the Cirrus clang build (plus two fixes) #10641

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 8 commits into from
3 changes: 2 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ asan_task:
`#--with-pdo-firebird`
`#--with-pdo-dblib`
--enable-werror
CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC' LDFLAGS='-fsanitize=undefined,address'
CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC -Wassign-enum'
LDFLAGS='-fsanitize=undefined,address'
CC=clang
CXX=clang++
- make -j2
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ static void php_set_attribute_id(xmlAttrPtr attrp, bool is_id) /* {{{ */
}
} else if (is_id == 0 && attrp->atype == XML_ATTRIBUTE_ID) {
xmlRemoveID(attrp->doc, attrp);
attrp->atype = 0;
attrp->atype = (xmlAttributeType)0;
}
}
/* }}} */
Expand Down
17 changes: 7 additions & 10 deletions ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static zend_object *zend_ffi_cdata_new(zend_class_entry *class_type) /* {{{ */

cdata->type = NULL;
cdata->ptr = NULL;
cdata->flags = 0;
cdata->flags = (zend_ffi_flags)0;

return &cdata->std;
}
Expand Down Expand Up @@ -1110,7 +1110,7 @@ static zval *zend_ffi_cdata_get(zend_object *obj, zend_string *member, int read_
return &EG(uninitialized_zval);
}

zend_ffi_cdata_to_zval(cdata, cdata->ptr, type, BP_VAR_R, rv, 0, 0, 0);
zend_ffi_cdata_to_zval(cdata, cdata->ptr, type, BP_VAR_R, rv, (zend_ffi_flags)0, 0, 0);
return rv;
}
/* }}} */
Expand Down Expand Up @@ -2833,7 +2833,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */
}

if (ZEND_FFI_TYPE(type->func.ret_type)->kind != ZEND_FFI_TYPE_VOID) {
zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, 0, 1, 0);
zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, (zend_ffi_flags)0, 1, 0);
} else {
ZVAL_NULL(return_value);
}
Expand Down Expand Up @@ -3736,7 +3736,6 @@ ZEND_METHOD(FFI, new) /* {{{ */
bool owned = 1;
bool persistent = 0;
bool is_const = 0;
zend_ffi_flags flags = ZEND_FFI_FLAG_OWNED;

ZEND_FFI_VALIDATE_API_RESTRICTION();
ZEND_PARSE_PARAMETERS_START(1, 3)
Expand All @@ -3746,9 +3745,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
Z_PARAM_BOOL(persistent)
ZEND_PARSE_PARAMETERS_END();

if (!owned) {
flags &= ~ZEND_FFI_FLAG_OWNED;
}
zend_ffi_flags flags = owned ? ZEND_FFI_FLAG_OWNED : 0;

if (persistent) {
flags |= ZEND_FFI_FLAG_PERSISTENT;
Expand Down Expand Up @@ -3871,7 +3868,7 @@ ZEND_METHOD(FFI, free) /* {{{ */
} else if (!(cdata->flags & ZEND_FFI_FLAG_OWNED)) {
pefree(cdata->ptr, cdata->flags & ZEND_FFI_FLAG_PERSISTENT);
cdata->ptr = NULL;
cdata->flags &= ~(ZEND_FFI_FLAG_OWNED|ZEND_FFI_FLAG_PERSISTENT);
cdata->flags = (zend_ffi_flags)(cdata->flags & ~(ZEND_FFI_FLAG_OWNED|ZEND_FFI_FLAG_PERSISTENT));
cdata->std.handlers = &zend_ffi_cdata_free_handlers;
} else {
zend_throw_error(zend_ffi_exception_ce, "free() non a C pointer");
Expand Down Expand Up @@ -4045,7 +4042,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
if (old_cdata->flags & ZEND_FFI_FLAG_OWNED) {
if (GC_REFCOUNT(&old_cdata->std) == 1 && Z_REFCOUNT_P(arg) == 1) {
/* transfer ownership */
old_cdata->flags &= ~ZEND_FFI_FLAG_OWNED;
old_cdata->flags = (zend_ffi_flags)(old_cdata->flags & ~ZEND_FFI_FLAG_OWNED);
cdata->flags |= ZEND_FFI_FLAG_OWNED;
} else {
//???zend_throw_error(zend_ffi_exception_ce, "Attempt to cast owned C pointer");
Expand Down Expand Up @@ -4282,7 +4279,7 @@ ZEND_METHOD(FFI, addr) /* {{{ */
}
if (cdata->flags & ZEND_FFI_FLAG_OWNED) {
/* transfer ownership */
cdata->flags &= ~ZEND_FFI_FLAG_OWNED;
cdata->flags = (zend_ffi_flags)(cdata->flags & ~ZEND_FFI_FLAG_OWNED);
new_cdata->flags |= ZEND_FFI_FLAG_OWNED;
}
}
Expand Down
9 changes: 3 additions & 6 deletions ext/mysqlnd/mysqlnd_ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ MYSQLND_METHOD(mysqlnd_stmt, reset)(MYSQLND_STMT * const s)
/* Reset Long Data */
for (i = 0; i < stmt->param_count; i++) {
if (stmt->param_bind[i].flags & MYSQLND_PARAM_BIND_BLOB_USED) {
stmt->param_bind[i].flags &= ~MYSQLND_PARAM_BIND_BLOB_USED;
stmt->param_bind[i].flags = (enum_param_bind_flags)(stmt->param_bind[i].flags & ~MYSQLND_PARAM_BIND_BLOB_USED);
}
}
}
Expand Down Expand Up @@ -1148,10 +1148,7 @@ MYSQLND_METHOD(mysqlnd_stmt, bind_parameters)(MYSQLND_STMT * const s, MYSQLND_PA
/* Prevent from freeing */
/* Don't update is_ref, or we will leak during conversion */
Z_TRY_ADDREF(stmt->param_bind[i].zv);
stmt->param_bind[i].flags = 0;
if (stmt->param_bind[i].type == MYSQL_TYPE_LONG_BLOB) {
stmt->param_bind[i].flags &= ~MYSQLND_PARAM_BIND_BLOB_USED;
}
stmt->param_bind[i].flags = (enum_param_bind_flags)0;
}
stmt->send_types_to_server = 1;
} else if (param_bind && param_bind != stmt->param_bind) {
Expand Down Expand Up @@ -1207,7 +1204,7 @@ MYSQLND_METHOD(mysqlnd_stmt, bind_one_parameter)(MYSQLND_STMT * const s, unsigne
zval_ptr_dtor(&stmt->param_bind[param_no].zv);
if (type == MYSQL_TYPE_LONG_BLOB) {
/* The client will use stmt_send_long_data */
stmt->param_bind[param_no].flags &= ~MYSQLND_PARAM_BIND_BLOB_USED;
stmt->param_bind[param_no].flags = (enum_param_bind_flags)(stmt->param_bind[param_no].flags & ~MYSQLND_PARAM_BIND_BLOB_USED);
}
ZVAL_COPY_VALUE(&stmt->param_bind[param_no].zv, zv);
stmt->param_bind[param_no].type = type;
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqlnd/mysqlnd_ps_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ mysqlnd_stmt_execute_store_param_values(MYSQLND_STMT_DATA * stmt, zval * copies,
break;
case MYSQL_TYPE_LONG_BLOB:
if (stmt->param_bind[i].flags & MYSQLND_PARAM_BIND_BLOB_USED) {
stmt->param_bind[i].flags &= ~MYSQLND_PARAM_BIND_BLOB_USED;
stmt->param_bind[i].flags = (enum_param_bind_flags)(stmt->param_bind[i].flags & ~MYSQLND_PARAM_BIND_BLOB_USED);
} else {
/* send_long_data() not called, send empty string */
*p = php_mysqlnd_net_store_length(*p, 0);
Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -7634,7 +7634,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
if (stop & ZEND_JIT_TRACE_HALT) {
ret = -1;
}
stop &= ~ZEND_JIT_TRACE_HALT;
stop = (zend_jit_trace_stop)(stop & ~ZEND_JIT_TRACE_HALT);

if (UNEXPECTED(trace_buffer[1].opline != orig_opline)) {
orig_opline = trace_buffer[1].opline;
Expand Down Expand Up @@ -7972,7 +7972,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
if (stop & ZEND_JIT_TRACE_HALT) {
ret = -1;
}
stop &= ~ZEND_JIT_TRACE_HALT;
stop = (zend_jit_trace_stop)(stop & ~ZEND_JIT_TRACE_HALT);

if (UNEXPECTED(trace_buffer->start != ZEND_JIT_TRACE_START_SIDE)) {
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_START) {
Expand Down
2 changes: 1 addition & 1 deletion ext/openssl/xp_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_

if (xparam->outputs.client && sock->enable_on_connect) {
/* remove the client bit */
sock->method &= ~STREAM_CRYPTO_IS_CLIENT;
sock->method = (php_stream_xport_crypt_method_t)(sock->method & ~STREAM_CRYPTO_IS_CLIENT);

clisockdata->method = sock->method;

Expand Down