Skip to content

Commit

Permalink
[mono] Reenable C4244 MSVC warning and fix occurrences (#91395)
Browse files Browse the repository at this point in the history
Fixes #91249

We originally fixed the warnings with #69236 but due to `add_compile_options()` calls in zlib.cmake _all_ of the mono native libs - not just the zlib components - were being built with C4244 disabled and a few couple more leaked in.

This fixes the occurrences and reworks the .cmake files a bit to hopefully prevent this in the future.
  • Loading branch information
akoeplinger authored Sep 5, 2023
1 parent 913a844 commit 4c0a7c4
Show file tree
Hide file tree
Showing 47 changed files with 526 additions and 510 deletions.
3 changes: 0 additions & 3 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ if (MSVC)
if(EXISTS ${CLR_SOURCELINK_FILE_PATH})
add_link_options("/sourcelink:${CLR_SOURCELINK_FILE_PATH}")
endif()

# FIXME: Remove the line below when https://github.com/dotnet/runtime/issues/91249 is fixed.
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4244>) # conversion from 'type1' to 'type2', possible loss of data
endif(MSVC)

set(CROSS_ROOTFS $ENV{ROOTFS_DIR})
Expand Down
8 changes: 4 additions & 4 deletions src/mono/mono/arch/arm64/arm64-codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ arm_is_bl_disp (void *code, void *target)
static G_GNUC_UNUSED inline unsigned int
arm_get_disp (void *p, void *target)
{
unsigned int disp = ((char*)target - (char*)p) / 4;
unsigned int disp = GINT64_TO_UINT (((char*)target - (char*)p) / 4);

if (target)
g_assert (arm_is_bl_disp (p, target));
Expand All @@ -205,7 +205,7 @@ arm_is_disp19 (void *code, void *target)
static G_GNUC_UNUSED inline unsigned int
arm_get_disp19 (void *p, void *target)
{
unsigned int disp = ((char*)target - (char*)p) / 4;
unsigned int disp = GINT64_TO_UINT (((char*)target - (char*)p) / 4);

if (target)
g_assert (arm_is_disp19 (p, target));
Expand Down Expand Up @@ -233,7 +233,7 @@ arm_get_disp19 (void *p, void *target)
static G_GNUC_UNUSED inline unsigned int
arm_get_disp15 (void *p, void *target)
{
unsigned int disp = ((char*)target - (char*)p) / 4;
unsigned int disp = GINT64_TO_UINT (((char*)target - (char*)p) / 4);
return (disp & 0x7fff);
}

Expand Down Expand Up @@ -545,7 +545,7 @@ arm_encode_arith_imm (int imm, guint32 *shift)
#define arm_movkw(p, rd, imm, shift) do { g_assert ((shift) % 16 == 0); arm_format_mov ((p), 0x0, 0x3, (shift) / 16, (rd), (imm)); } while (0)

/* PC-relative address calculation */
#define arm_format_adrp(p, op, rd, target) do { guint64 imm1 = (guint64)(target); guint64 imm2 = (guint64)(p); int _imm = imm1 - imm2; arm_emit ((p), ((op) << 31) | (((_imm) & 0x3) << 29) | (0x10 << 24) | (((_imm >> 2) & 0x7ffff) << 5) | ((rd) << 0)); } while (0)
#define arm_format_adrp(p, op, rd, target) do { guint64 imm1 = (guint64)(target); guint64 imm2 = (guint64)(p); int _imm = GUINT64_TO_INT (imm1 - imm2); arm_emit ((p), ((op) << 31) | (((_imm) & 0x3) << 29) | (0x10 << 24) | (((_imm >> 2) & 0x7ffff) << 5) | ((rd) << 0)); } while (0)

#define arm_adrpx(p, rd, target) arm_format_adrp ((p), 0x1, (rd), (target))
#define arm_adrx(p, rd, target) arm_format_adrp ((p), 0x0, (rd), (target))
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -8855,7 +8855,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
buffer_add_objid (buf, obj);
if (CHECK_ICORDBG (TRUE))
{
buffer_add_byte(buf, m_class_is_valuetype (klass));
buffer_add_byte(buf, GINT_TO_UINT8(m_class_is_valuetype (klass)));
if (m_class_is_valuetype (klass))
{
int nfields = 0;
Expand Down Expand Up @@ -8950,7 +8950,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
case MDBGPROT_CMD_TYPE_ELEMENT_TYPE:
{
buffer_add_int (buf, m_class_get_byval_arg (klass)->type);
buffer_add_byte (buf, MONO_TYPE_ISSTRUCT (m_class_get_byval_arg (klass)));
buffer_add_byte (buf, GINT_TO_UINT8 (MONO_TYPE_ISSTRUCT (m_class_get_byval_arg (klass))));
break;
}
case MDBGPROT_CMD_TYPE_RANK:
Expand Down Expand Up @@ -10141,7 +10141,7 @@ array_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
{
buffer_add_typeid (buf, arr->obj.vtable->domain, m_class_get_element_class (arr->obj.vtable->klass));
if (CHECK_ICORDBG (TRUE))
buffer_add_byte (buf, MONO_TYPE_ISSTRUCT (m_class_get_byval_arg (m_class_get_element_class (arr->obj.vtable->klass))));
buffer_add_byte (buf, GINT_TO_UINT8 (MONO_TYPE_ISSTRUCT (m_class_get_byval_arg (m_class_get_element_class (arr->obj.vtable->klass)))));
}
}
break;
Expand Down
4 changes: 1 addition & 3 deletions src/mono/mono/eglib/giconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ g_unichar_to_utf8 (gunichar c, gchar *outbuf)
static FORCE_INLINE (int)
g_unichar_to_utf16_endian (gunichar c, gunichar2 *outbuf, unsigned endian)
{
gunichar c2;

if (c < 0xd800) {
if (outbuf)
*outbuf = (gunichar2) (endian == G_BIG_ENDIAN ? GUINT16_TO_BE(c) : GUINT16_TO_LE(c));
Expand All @@ -253,7 +251,7 @@ g_unichar_to_utf16_endian (gunichar c, gunichar2 *outbuf, unsigned endian)
return 1;
} else if (c < 0x110000) {
if (outbuf) {
c2 = c - 0x10000;
gunichar2 c2 = (gunichar2)(c - 0x10000);

gunichar2 part1 = (c2 >> 10) + 0xd800;
gunichar2 part2 = (c2 & 0x3ff) + 0xdc00;
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -3729,7 +3729,7 @@ buffer_gc_event_object_reference_callback (
sizeof (object_size) +
sizeof (object_type) +
sizeof (edge_count) +
(edge_count * sizeof (uintptr_t));
GUINT64_TO_UINT32 (edge_count * sizeof (uintptr_t));

EP_ASSERT (context->buffer);
EP_ASSERT (context->buffer->context);
Expand Down Expand Up @@ -3775,7 +3775,7 @@ flush_gc_event_bulk_root_static_vars (GCHeapDumpContext *context)
context->bulk_root_static_vars.count,
(uint64_t)mono_get_root_domain (),
clr_instance_get_id (),
context->bulk_root_static_vars.data_current - context->bulk_root_static_vars.data_start,
GPTRDIFF_TO_INT (context->bulk_root_static_vars.data_current - context->bulk_root_static_vars.data_start),
context->bulk_root_static_vars.data_start,
NULL,
NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ ves_icall_RuntimeType_GetCallingConventionFromFunctionPointerInternal (MonoQCall
MonoType *type = type_handle.type;
g_assert (type->type == MONO_TYPE_FNPTR);
// FIXME: Once we address: https://github.com/dotnet/runtime/issues/90308 this should not be needed anymore
return type->data.method->suppress_gc_transition ? MONO_CALL_UNMANAGED_MD : type->data.method->call_convention;
return GUINT_TO_INT8 (type->data.method->suppress_gc_transition ? MONO_CALL_UNMANAGED_MD : type->data.method->call_convention);
}

MonoBoolean
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/sgen-client-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum {
};

static inline mword
sgen_mono_array_size (GCVTable vtable, MonoArray *array, mword *bounds_size, mword descr)
sgen_mono_array_size (GCVTable vtable, MonoArray *array, mword *bounds_size, SgenDescriptor descr)
{
mword size, size_without_bounds;
int element_size;
Expand Down
12 changes: 6 additions & 6 deletions src/mono/mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ptr_on_stack (void *ptr)
} while (0)

static void
scan_object_for_binary_protocol_copy_wbarrier (gpointer dest, char *start, mword desc)
scan_object_for_binary_protocol_copy_wbarrier (gpointer dest, char *start, SgenDescriptor desc)
{
#define SCAN_OBJECT_NOVTABLE
#include "sgen/sgen-scan-object.h"
Expand Down Expand Up @@ -127,7 +127,7 @@ mono_gc_wbarrier_value_copy_internal (gpointer dest, gconstpointer src, int coun
for (i = 0; i < count; ++i) {
scan_object_for_binary_protocol_copy_wbarrier ((char*)dest + i * element_size,
(char*)src + i * element_size - MONO_ABI_SIZEOF (MonoObject),
(mword) m_class_get_gc_descr (klass));
m_class_get_gc_descr (klass));
}
}
#endif
Expand Down Expand Up @@ -157,7 +157,7 @@ mono_gc_wbarrier_object_copy_internal (MonoObject* obj, MonoObject *src)

#ifdef SGEN_HEAVY_BINARY_PROTOCOL
if (sgen_binary_protocol_is_heavy_enabled ())
scan_object_for_binary_protocol_copy_wbarrier (obj, (char*)src, (mword) src->vtable->gc_descr);
scan_object_for_binary_protocol_copy_wbarrier (obj, (char*)src, src->vtable->gc_descr);
#endif

sgen_get_remset ()->wbarrier_object_copy (obj, src);
Expand Down Expand Up @@ -982,7 +982,7 @@ sgen_client_cardtable_scan_object (GCObject *obj, guint8 *cards, ScanCopyContext
size_t card_count;
size_t extra_idx = 0;

mword desc = (mword)m_class_get_gc_descr (m_class_get_element_class (klass));
SgenDescriptor desc = m_class_get_gc_descr (m_class_get_element_class (klass));
int elem_size = mono_array_element_size (klass);

#ifdef SGEN_OBJECT_LAYOUT_STATISTICS
Expand Down Expand Up @@ -1297,7 +1297,7 @@ two_args_report_root (void *address, MonoObject *obj, void *gc_data)
}

static void
precisely_report_roots_from (GCRootReport *report, void** start_root, void** end_root, mword desc)
precisely_report_roots_from (GCRootReport *report, void** start_root, void** end_root, SgenDescriptor desc)
{
switch (desc & ROOT_DESC_TYPE_MASK) {
case ROOT_DESC_BITMAP:
Expand Down Expand Up @@ -1850,7 +1850,7 @@ static void
collect_references (HeapWalkInfo *hwi, GCObject *obj, size_t size)
{
char *start = (char*)obj;
mword desc = sgen_obj_get_descriptor (obj);
SgenDescriptor desc = sgen_obj_get_descriptor (obj);

#include "sgen/sgen-scan-object.h"
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/sgen-new-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ dfs1 (HashEntry *obj_entry)

if (!obj_entry->v.dfs1.is_visited) {
int num_links = 0;
mword desc = sgen_obj_get_descriptor_safe (obj);
SgenDescriptor desc = sgen_obj_get_descriptor_safe (obj);

obj_entry->v.dfs1.is_visited = 1;

Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/sgen-tarjan-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ push_all (ScanData *data)
{
GCObject *obj = data->obj;
char *start = (char*)obj;
mword desc = sgen_obj_get_descriptor_safe (obj);
SgenDescriptor desc = sgen_obj_get_descriptor_safe (obj);

#if DUMP_GRAPH
printf ("+scanning %s (%p) index %d color %p\n", safe_name_bridge (data->obj), data->obj, data->index, data->color);
Expand Down Expand Up @@ -741,7 +741,7 @@ compute_low (ScanData *data)
{
GCObject *obj = data->obj;
char *start = (char*)obj;
mword desc = sgen_obj_get_descriptor_safe (obj);
SgenDescriptor desc = sgen_obj_get_descriptor_safe (obj);

#include "sgen/sgen-scan-object.h"
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/weak-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ rehash (MonoWeakHashTable *hash)
* Rehash to a size that can fit the current elements. Rehash relative to in_use
* to allow also for compaction.
*/
data.new_size = g_spaced_primes_closest (hash->in_use / HASH_TABLE_MAX_LOAD_FACTOR * HASH_TABLE_RESIZE_RATIO);
data.new_size = g_spaced_primes_closest (GFLOAT_TO_UINT (hash->in_use / HASH_TABLE_MAX_LOAD_FACTOR * HASH_TABLE_RESIZE_RATIO));

MonoArray *holder = (MonoArray*)mono_gchandle_get_target_internal (hash->key_value_handle);
g_assert (holder);
Expand Down
5 changes: 2 additions & 3 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ elseif(NOT HOST_BROWSER AND NOT HOST_WASI)
set(mini_sources "${mini_sources};${VERSION_FILE_PATH}") # this is generated by GenerateNativeVersionFile in Arcade
endif()

if(HOST_WIN32)
set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "/wd4005;/wd4127;/wd4131;/wd4244")
endif()
set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}")
set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}")

set(monosgen-sources "${mini_sources};${ZLIB_SOURCES}")

Expand Down
Loading

0 comments on commit 4c0a7c4

Please sign in to comment.