[Mono] Fix 4244 warnings. (#69236)
authorJohan Lorensson <lateralusx.github@gmail.com>
Tue, 31 May 2022 16:03:52 +0000 (18:03 +0200)
committerGitHub <noreply@github.com>
Tue, 31 May 2022 16:03:52 +0000 (18:03 +0200)
commit5adac4ac39c7473d3b17ab8875aeeaae79d27187
tree1b8e8dc647c662e1d5134839f21c1d481c48355d
parent6010dc0604a9f2708dba8d21f57d97b613dfcabe
[Mono] Fix 4244 warnings. (#69236)

* Fixes all 4244 warnings on Mono runtime x86/x64 Windows build,
aligning with SDL requirements (#66154).

There will be additional warnings in the cross compilers that needs
to be fixed separately, but this should fix the major bulk of
4244 warnings.

All changes done in this PR are mitigating compiler issued data type
truncation 4244 warnings:

'conversion' conversion from 'type1' to 'type2', possible loss of data

and PR will align to the same type as the compiler issued in the warning.

PR introduce a new set of macros to cast between types following patter
of existing GPOINTER_TO_INT, GPOINTER_TO_UINT, GTYPE1_TO_TYPE2.

The idea of use these macros is that it will be clear where casts are done,
and we will have ability to intercept and add validation logic in
specialized builds to catch truncation errors. The PR also introduce
the needed inline functions under ENABLE_CHECKED_CASTS that could be
used for extended validation when using the macros. Failure actions
in these inline functions are not currently fully implemented,
since that will be different from case to case,
but can be added when needed since all infrastructure is prepared.

If it is possible to change types used in code to mitigate the warnings,
that will be the initial strategy used by this PR, if that however would
cause ripple effects through the source code (unfortunately quite common),
we will fallback using the GTYPE1_TO_TYPE2 macros to clearly show the
intent, keep trackability of the change as well as adding ability to do
additional validation of casts in the future.
108 files changed:
src/mono/mono/arch/x86/x86-codegen.h
src/mono/mono/component/debugger-agent.c
src/mono/mono/component/debugger-engine.c
src/mono/mono/component/event_pipe.c
src/mono/mono/eglib/giconv.c
src/mono/mono/eglib/glib.h
src/mono/mono/eglib/gstr.c
src/mono/mono/eglib/gutf8.c
src/mono/mono/eventpipe/ep-rt-mono.c
src/mono/mono/metadata/appdomain.c
src/mono/mono/metadata/assembly.c
src/mono/mono/metadata/class-init.c
src/mono/mono/metadata/class-setup-vtable.c
src/mono/mono/metadata/class.c
src/mono/mono/metadata/custom-attrs.c
src/mono/mono/metadata/debug-helpers.c
src/mono/mono/metadata/debug-mono-ppdb.c
src/mono/mono/metadata/gc.c
src/mono/mono/metadata/handle.c
src/mono/mono/metadata/icall.c
src/mono/mono/metadata/image.c
src/mono/mono/metadata/jit-info.c
src/mono/mono/metadata/loader.c
src/mono/mono/metadata/marshal-ilgen.c
src/mono/mono/metadata/marshal-lightweight.c
src/mono/mono/metadata/marshal-shared.c
src/mono/mono/metadata/marshal.c
src/mono/mono/metadata/marshal.h
src/mono/mono/metadata/memory-manager.c
src/mono/mono/metadata/mempool.c
src/mono/mono/metadata/metadata-internals.h
src/mono/mono/metadata/metadata.c
src/mono/mono/metadata/method-builder-ilgen.c
src/mono/mono/metadata/monitor.c
src/mono/mono/metadata/mono-basic-block.c
src/mono/mono/metadata/mono-debug.c
src/mono/mono/metadata/mono-hash.c
src/mono/mono/metadata/native-library.c
src/mono/mono/metadata/object-internals.h
src/mono/mono/metadata/profiler.c
src/mono/mono/metadata/reflection.c
src/mono/mono/metadata/sgen-mono-ilgen.c
src/mono/mono/metadata/sgen-mono.c
src/mono/mono/metadata/sgen-stw.c
src/mono/mono/metadata/sgen-tarjan-bridge.c
src/mono/mono/metadata/sre-encode.c
src/mono/mono/metadata/sre.c
src/mono/mono/metadata/threads.c
src/mono/mono/mini/abcremoval.c
src/mono/mono/mini/alias-analysis.c
src/mono/mono/mini/aot-compiler.c
src/mono/mono/mini/aot-runtime.c
src/mono/mono/mini/branch-opts.c
src/mono/mono/mini/calls.c
src/mono/mono/mini/cfold.c
src/mono/mono/mini/debug-mini.c
src/mono/mono/mini/decompose.c
src/mono/mono/mini/driver.c
src/mono/mono/mini/dwarfwriter.c
src/mono/mono/mini/exceptions-amd64.c
src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/interp/transform.c
src/mono/mono/mini/intrinsics.c
src/mono/mono/mini/ir-emit.h
src/mono/mono/mini/jit-icalls.c
src/mono/mono/mini/liveness.c
src/mono/mono/mini/lldb.c
src/mono/mono/mini/local-propagation.c
src/mono/mono/mini/memory-access.c
src/mono/mono/mini/method-to-ir.c
src/mono/mono/mini/mini-amd64.c
src/mono/mono/mini/mini-exceptions.c
src/mono/mono/mini/mini-generic-sharing.c
src/mono/mono/mini/mini-profiler.c
src/mono/mono/mini/mini-runtime.c
src/mono/mono/mini/mini-trampolines.c
src/mono/mono/mini/mini-x86.c
src/mono/mono/mini/mini.c
src/mono/mono/mini/mini.h
src/mono/mono/mini/seq-points.c
src/mono/mono/mini/ssa.c
src/mono/mono/mini/tramp-amd64-gsharedvt.c
src/mono/mono/mini/tramp-amd64.c
src/mono/mono/mini/type-checking.c
src/mono/mono/mini/unwind.c
src/mono/mono/profiler/aot.c
src/mono/mono/profiler/helper.c
src/mono/mono/profiler/helper.h
src/mono/mono/sgen/sgen-descriptor.c
src/mono/mono/sgen/sgen-gc.c
src/mono/mono/sgen/sgen-gc.h
src/mono/mono/sgen/sgen-gray.c
src/mono/mono/sgen/sgen-marksweep.c
src/mono/mono/sgen/sgen-memory-governor.c
src/mono/mono/sgen/sgen-protocol.c
src/mono/mono/sgen/sgen-thread-pool.c
src/mono/mono/sgen/sgen-workers.c
src/mono/mono/utils/lock-free-alloc.c
src/mono/mono/utils/mono-codeman.c
src/mono/mono/utils/mono-dl.c
src/mono/mono/utils/mono-error.c
src/mono/mono/utils/mono-machine.h
src/mono/mono/utils/mono-math-c.c
src/mono/mono/utils/mono-path.c
src/mono/mono/utils/mono-threads-coop.c
src/mono/mono/utils/mono-threads.c
src/mono/mono/utils/mono-time.c
src/mono/mono/utils/networking.c