Skip to content

Commit 833ef40

Browse files
committed
Fixes all 4244 warnings on Mono runtime x86/x64 Windows build,
aligning with SDL requirements (dotnet#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.
1 parent 2659885 commit 833ef40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1560
-1072
lines changed

src/mono/mono/arch/x86/x86-codegen.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ mono_x86_patch_inline (guchar* code, gpointer target)
17101710
*/
17111711
#define x86_jump_code(inst,target) \
17121712
do { \
1713-
int t; \
1713+
ptrdiff_t t; \
17141714
x86_codegen_pre(&(inst), 2); \
17151715
t = (unsigned char*)(target) - (inst) - 2; \
17161716
if (x86_is_imm8(t)) { \
@@ -1783,7 +1783,7 @@ mono_x86_patch_inline (guchar* code, gpointer target)
17831783
#if defined(TARGET_X86)
17841784
#define x86_branch(inst,cond,target,is_signed) \
17851785
do { \
1786-
int __offset; \
1786+
ptrdiff_t __offset; \
17871787
guint8* __branch_start; \
17881788
x86_codegen_pre(&(inst), 2); \
17891789
__offset = (target) - (inst) - 2; \
@@ -1803,7 +1803,7 @@ mono_x86_patch_inline (guchar* code, gpointer target)
18031803

18041804
#define x86_branch(inst,cond,target,is_signed) \
18051805
do { \
1806-
int __offset = (target) - (inst) - 2; \
1806+
ptrdiff_t __offset = (target) - (inst) - 2; \
18071807
if (x86_is_imm8 ((__offset))) \
18081808
x86_branch8 ((inst), (cond), __offset, (is_signed)); \
18091809
else { \
@@ -1893,7 +1893,7 @@ mono_x86_patch_inline (guchar* code, gpointer target)
18931893

18941894
#define x86_call_code(inst,target) \
18951895
do { \
1896-
int _x86_offset; \
1896+
ptrdiff_t _x86_offset; \
18971897
_x86_offset = (unsigned char*)(target) - (inst); \
18981898
_x86_offset -= 5; \
18991899
x86_call_imm_body ((inst), _x86_offset); \

0 commit comments

Comments
 (0)