Skip to content
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

SDL signoff requirements - please enable additional C/C++ compiler warnings #66154

Closed
21 tasks done
GrabYourPitchforks opened this issue Mar 3, 2022 · 42 comments
Closed
21 tasks done

Comments

@GrabYourPitchforks
Copy link
Member

GrabYourPitchforks commented Mar 3, 2022

Please prioritize this work. Depending on the size of the code base, there could be hundreds or thousands of warnings which require addressing.

This work must be completed before RC1 snap.

Recent SDL changes require that we enable additional compiler warnings across our C/C++ projects. The requirements are:

  • Compile with warning level 3 or higher. These warnings do not have to be fixed, but they must at least be triaged.

Enable the following additional warnings, which must be fixed if they occur:

  • C4018 - 'expression' : signed/unsigned mismatch
  • C4055 - 'conversion' : from data pointer 'type1' to function pointer 'type2'
  • C4146 - unary minus operator applied to unsigned type, result still unsigned
  • C4242 - 'identifier' : conversion from 'type1' to 'type2', possible loss of data
  • C4244 - 'conversion' conversion from 'type1' to 'type2', possible loss of data
  • C4267 - 'var' : conversion from 'size_t' to 'type', possible loss of data
  • C4302 - 'conversion' : truncation from 'type 1' to 'type 2'
  • C4308 - negative integral constant converted to unsigned type
  • C4509 - nonstandard extension used: 'function' uses SEH and 'object' has destructor
  • C4510 - 'class' : default constructor could not be generated
  • C4532 - 'continue' : jump out of __finally/finally block has undefined behavior during termination handling
  • C4533 - initialization of 'variable' is skipped by 'instruction'
  • C4610 - object 'class' can never be instantiated - user-defined constructor required
  • C4611 - interaction between 'function' and C++ object destruction is non-portable
  • C4700 - uninitialized local variable 'name' used
  • C4701 - Potentially uninitialized local variable 'name' used
  • C4703 - Potentially uninitialized local pointer variable 'name' used
  • C4789 - destination of memory copy is too small
  • C4995 - 'function': name was marked as #pragma deprecated
  • C4996 - 'function': was declared deprecated also 'std::': Function call with parameters that are potentially unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

See the SDL guidelines (MSFT internal only) for further information.

To make auditing code easier prior to signoff and release, please include the string Microsoft.Security.SystemsADM.10086 somewhere in the vcxproj / cmake / whatever file which is responsible for C/C++ compilation where all of these flags are defined. That gives the code auditors a target string to search against and validate that the proper warnings are enabled. See below an example of how to do this in a cmake file.

# [[! Microsoft.Security.SystemsADM.10086 !]] - SQL required warnings
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W3>) # warning level 3
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4018>) # 'expression' : signed/unsigned mismatch
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4055>) # 'conversion' : from data pointer 'type1' to function pointer 'type2'
# ... and so on ...

Once the work is finished, or if there is no work to perform, please feel free to close this issue.

Thanks for your assistance!

Quick FAQ

What code is bound to this requirement?

This affects only production code. Production code is generally defined as code which ships as part of the product and which runs on customer machines or which manages infrastructure, such as our build labs. Unit and functional test projects are not considered production code.

Does this need to be backported?

No backporting plans at this time. If actual bugs are found during this process, individual product teams have discretion to selectively backport into the next downlevel servicing vehicle.

What about forked third-party code?

This requirement applies to all code that MSFT builds from source, regardless of its provenance. Ideally any changes that we make to local forked copies can be submitted upstream as a PR so that the wider ecosystem can enjoy their benefits.

If this is impractical, exceptions to this requirement can be sought on an as-needed basis. However, exceptions are: (a) not guaranteed to be granted; and (b) time-constrained. The exception process is not intended to provide a permanent deferral of this work. Please contact the fxsecurity alias if an exception is needed.

What about C# and other languages?

This requirement only affects C/C++ code. Requirements for other languages will be filed as separate issues.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Mar 3, 2022
@danmoseley
Copy link
Member

Added checkboxes...

@ghost
Copy link

ghost commented Mar 3, 2022

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Issue Details

Please prioritize this work. Depending on the size of the code base, there could be hundreds or thousands of warnings which require addressing.

This work must be completed before RC1 snap.

Recent SDL changes require that we enable additional compiler warnings across our C/C++ projects. The requirements are:

  • Compile with warning level 3 or higher. These warnings do not have to be fixed, but they must at least be triaged.

Enable the following additional warnings, which must be fixed if they occur:

  • C4018 - 'expression' : signed/unsigned mismatch
  • C4055 - 'conversion' : from data pointer 'type1' to function pointer 'type2'
  • C4146 - unary minus operator applied to unsigned type, result still unsigned
  • C4242 - 'identifier' : conversion from 'type1' to 'type2', possible loss of data
  • C4244 - 'conversion' conversion from 'type1' to 'type2', possible loss of data
  • C4267 - 'var' : conversion from 'size_t' to 'type', possible loss of data
  • C4302 - 'conversion' : truncation from 'type 1' to 'type 2'
  • C4308 - negative integral constant converted to unsigned type
  • C4509 - nonstandard extension used: 'function' uses SEH and 'object' has destructor
  • C4510 - 'class' : default constructor could not be generated
  • C4532 - 'continue' : jump out of __finally/finally block has undefined behavior during termination handling
  • C4533 - initialization of 'variable' is skipped by 'instruction'
  • C4610 - object 'class' can never be instantiated - user-defined constructor required
  • C4611 - interaction between 'function' and C++ object destruction is non-portable
  • C4700 - uninitialized local variable 'name' used
  • C4701 - Potentially uninitialized local variable 'name' used
  • C4703 - Potentially uninitialized local pointer variable 'name' used
  • C4789 - destination of memory copy is too small
  • C4995 - 'function': name was marked as #pragma deprecated
  • C4996 - 'function': was declared deprecated also 'std::': Function call with parameters that are potentially unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

See the SDL guidelines (MSFT internal only) for further information.

To make auditing code easier prior to signoff and release, please include the string Microsoft.Security.SystemsADM.10086 somewhere in the vcxproj / cmake / whatever file which is responsible for C/C++ compilation where all of these flags are defined. That gives the code auditors a target string to search against and validate that the proper warnings are enabled. See below an example of how to do this in a cmake file.

# [[! Microsoft.Security.SystemsADM.10086 !]] - SQL required warnings
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W3>) # warning level 3
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4018>) # 'expression' : signed/unsigned mismatch
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4055>) # 'conversion' : from data pointer 'type1' to function pointer 'type2'
# ... and so on ...

Once the work is finished, or if there is no work to perform, please feel free to close this issue.

Thanks for your assistance!

Quick FAQ

What code is bound to this requirement?

This affects only production code. Production code is generally defined as code which ships as part of the product and which runs on customer machines or which manages infrastructure, such as our build labs. Unit and functional test projects are not considered production code.

Does this need to be backported?

No backporting plans at this time. If actual bugs are found during this process, individual product teams have discretion to selectively backport into the next downlevel servicing vehicle.

What about forked third-party code?

This requirement applies to all code that MSFT builds from source, regardless of its provenance. Ideally any changes that we make to local forked copies can be submitted upstream as a PR so that the wider ecosystem can enjoy their benefits.

If this is impractical, exceptions to this requirement can be sought on an as-needed basis. However, exceptions are: (a) not guaranteed to be granted; and (b) time-constrained. The exception process is not intended to provide a permanent deferral of this work. Please contact the fxsecurity alias if an exception is needed.

What about C# and other languages?

This requirement only affects C/C++ code. Requirements for other languages will be filed as separate issues.

Author: GrabYourPitchforks
Assignees: -
Labels:

area-Infrastructure, untriaged

Milestone: -

@AaronRobinsonMSFT
Copy link
Member

@GrabYourPitchforks Is this for the repo all up or only for coreclr and native code in libraries?

@AaronRobinsonMSFT

This comment was marked as outdated.

@GrabYourPitchforks
Copy link
Member Author

GrabYourPitchforks commented Mar 4, 2022

@GrabYourPitchforks Levi Broderick FTE Is this for the repo all up or only for coreclr and native code in libraries?

Only for production code, so I'd think coreclr / mono (if compiled via MSVC++) / libs. Test code is excluded.

Edit: From the same issue in the winforms repo, the rule of thumb I've been using to define "production" code is:

If it meets at least one of these bullets, we should consider it "production" code. If it's code that instead only ever executes as part of a test suite, it's non-production.

@teo-tsirpanis teo-tsirpanis added this to the 7.0.0 milestone Mar 4, 2022
@danmoseley danmoseley added the help wanted [up-for-grabs] Good issue for external contributors label Mar 6, 2022
@danmoseley
Copy link
Member

danmoseley commented Mar 6, 2022

@AaronRobinsonMSFT in case anyone would like to help with this one, could you give a pointer to the necessary cmake changes?

I am not familiar with cmake and I only found this, but it's for mono.

add_compile_options(/W3) # set warning level 3

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Mar 6, 2022

in case anyone would like to help with this one, could you give a pointer to the necessary cmake changes?

@danmoseley Sure. The way this issue is framed, it is confusing. I believe the entire repo already has /W3 set by default. The set up for this is

# /W3 is added by default by CMake, so remove it
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# set default warning level to 3 but allow targets to override it.
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W$<GENEX_EVAL:$<IF:$<BOOL:$<TARGET_PROPERTY:MSVC_WARNING_LEVEL>>,$<TARGET_PROPERTY:MSVC_WARNING_LEVEL>,3>>>)

Note the removal of the default flag and then the conditional for CMake is added. If TARGET_PROPERTY:MSVC_WARNING_LEVEL isn't set, /W3 is added back - at least that is how I understand that line. I've confirmed this by looking a the generated ninja files for coreclr. The coreclr JIT sets /W4 as using the above properly and mono is explicit (see your link above). I believe this means the repo is properly targeted for /W3. Which means we need to see where any of the above warnings are disabled.

In #66154 (comment), I went through coreclr and found all the places we disabled one of the target warnings. In #66234, I am removing many of them for both mono and coreclr. However, even with the above PR some still remain. I've not checked the native/ or libraries/ directories at all.

4146 - Still exists in both mono and coreclr.
4244 - Still exists in both mono and coreclr.
4267 - Still exists in mono.

Once #66234 is in, all others in the list have been handled in mono and coreclr.

@lambdageek
Copy link
Member

lambdageek commented Mar 7, 2022

For mono, we need to pay attention to:

  • AOT cross compilers running on Windows targeting Android and WebAssembly, including our LLVM fork /cc @steveisok
  • Windows desktop builds of Mono, if we productize is @lateralusX
  • the mono mscordbi, if we productize it @lewing @thaystg

one complication - mono doesn't use eng/native/configurecompiler.cmake and sets its own compiler flags. So we need to verify all these warnings are on.

@am11
Copy link
Member

am11 commented Mar 8, 2022

one complication - mono doesn't use eng/native/configurecompiler.cmake and sets its own compiler flags. So we need to verify all these warnings are on.

Note that we have slowly adapted eng/native infra in mono; so it is semi-true these days. :)

4267 - Still exists in mono.

Looking at @AaronRobinsonMSFT's fixes for coreclr, it should be easy to fix. I can take a stab at it (if nobody else is working on it).

@AaronRobinsonMSFT
Copy link
Member

@am11 if you could handle 4267 in mono that would be great. I'll be working on 4146 and 4244 shortly.

@danmoseley
Copy link
Member

If anyone is willing to take a first scan of /native that would be great.

@elinor-fung
Copy link
Member

For the hosting components, a number of these are disabled - 4018, 4244, 4267, 4996:

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4996>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4267>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4018>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4200>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4244>)

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4996>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4267>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4018>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4200>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4244>)

@elinor-fung
Copy link
Member

A few pragma suppressions in the host too:

#pragma warning(suppress : 4996) // error C4996: '_wfopen': This function or variable may be unsafe.

#pragma warning(suppress : 4996) // error C4996: '_vsnwprintf': This function or variable may be unsafe.

#pragma warning(suppress : 4996) // error C4996: '_wcserror': This function or variable may be unsafe.

@AaronRobinsonMSFT
Copy link
Member

Ugh. I forgot the src/native directory.

@AaronRobinsonMSFT
Copy link
Member

@elinor-fung Can you provide a PR for the 4996 issues in src/native?

@elinor-fung
Copy link
Member

Yep, I will do that.

@AaronRobinsonMSFT
Copy link
Member

@am11, @lambdageek, @elinor-fung Once #66427 is merged, I believe that coreclr/ is clean according to this issue. How can I help with native/ or mono/?

@elinor-fung
Copy link
Member

elinor-fung commented Mar 10, 2022

A number of the additional warnings listed that must be fixed wouldn't be under /W3 - are those already explicitly enabled for coreclr/?

  • C4244 (level 3 and 4)
  • C4610 (level 4)
  • C4611 (level 4)
  • C4701 (level 4)
  • C4703 (level 4)

I know they are not enabled for the host.

C4700 is level 1 and 4, but it is explicitly enabled by configurecompiler.cmake.

@lateralusX
Copy link
Member

lateralusX commented Apr 19, 2022

@AaronRobinsonMSFT, what is the strategy around fixing the last two warnings levels on Mono? I just tried out 4244 and it issued around 2000 warnings, some in macros, but still a bunch to go through, guess that 4018 will generate a bunch as well.

I guess we would need to fix most of them in different PR's and only enable them on the last one when most have already been fixed. Question is if/how this work should be distributed and what strategy we should use to handle it.

@AaronRobinsonMSFT
Copy link
Member

I just tried out 4244 and it issued around 2000 warnings, some in macros, but still a bunch to go through, guess that 4018 will generate a bunch as well.

@lateralusX Yes, there is going to be substantial changes to mitigate these. I tried going down this path but got a bit overwhelmed and took a step back to work on other tasks. I am not sure of the preferred strategy for Mono to mitigate these to be honest. There are so many and as someone who primarily works in CoreCLR I'm likely not the correct person to make a call on how to proceed.

I am more than willing to help in any way that I can but I can't make the call myself and would prefer to hear from you, @lambdageek, or @vargaz on how you would like to mitigate them.

@lateralusX
Copy link
Member

lateralusX commented Apr 19, 2022

I just tried out 4244 and it issued around 2000 warnings, some in macros, but still a bunch to go through, guess that 4018 will generate a bunch as well.

@lateralusX Yes, there is going to be substantial changes to mitigate these. I tried going down this path but got a bit overwhelmed and took a step back to work on other tasks. I am not sure of the preferred strategy for Mono to mitigate these to be honest. There are so many and as someone who primarily works in CoreCLR I'm likely not the correct person to make a call on how to proceed.

I am more than willing to help in any way that I can but I can't make the call myself and would prefer to hear from you, @lambdageek, or @vargaz on how you would like to mitigate them.

OK, I can coordinate within Mono team, just wanted to make sure we don't end up doing similar work on different ends. I guess we could coordinate using this issue on what we plan to work on making sure (maybe that's wishful thinking on my end) no one else work on the same things.

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Apr 19, 2022

@lateralusX That is a fine solution. I agree using this task is feasible. I, along with @elinor-fung and likely @am11, would be willing to help with tasks if they could be clearly defined - perhaps down to compilation unit?

@lateralusX
Copy link
Member

lateralusX commented Apr 19, 2022

@lateralusX That is a fine solution. I agree using this task feasible. I, along with @elinor-fung and likely @am11, would be willing to help with tasks if they could be clearly defined - perhaps down to compilation unit?

I can probably work through component libraries first to get a feeling as well as the total amount of outstanding warnings after that work. Once that is done, we could divide on compile unit or sub area, like utils/metadata/mini (different folders), but they will probably need to come in dependency order, since fixing in one might also fix in others (due to shared headers).

@AaronRobinsonMSFT
Copy link
Member

@lateralusX Have you had a chance to discuss with the rest of the mono team on this one? No pressure, just want to avoid a mad rush on this kind of issue prior to RC.

@AaronRobinsonMSFT
Copy link
Member

I stand corrected. It looks like 4244 is still present under src/coreclr and src/native/external.

@lateralusX
Copy link
Member

@lateralusX Have you had a chance to discuss with the rest of the mono team on this one? No pressure, just want to avoid a mad rush on this kind of issue prior to RC.

Finishing of another work item and then I will do a triage on the remaining ones and add them to this issue (probably fix a set of them during the triage), we could then distribute it withing the teams if needed. Hopefully I will have something done beginning of next week.

@lateralusX
Copy link
Member

lateralusX commented Apr 27, 2022

Using this comment to track progress against fixing 4018 and 4244 on Mono.

Enabling 4018 on Mono Windows build generate 1402 0 warnings:

File Count Comment
C:\git\runtime\src\mono\mono\mini\aot-compiler.c 140 #71269
C:\git\runtime\src\mono\mono\mini\method-to-ir.c 116 #71269
C:\git\runtime\src\mono\mono\mini\ssa.c 72 #71269
C:\git\runtime\src\mono\mono\mini\mini-llvm.c 66 #71269
C:\git\runtime\src\mono\mono\mini\liveness.c 56 #71269
C:\git\runtime\src\mono\mono\metadata\metadata.c 54 #70417
C:\git\runtime\src\mono\mono\mini\interp\transform.c 52 #71269
C:\git\runtime\src\mono\mono\mini\interp\interp.c 50 #71269
C:\git\runtime\src\mono\mono\mini\mini.c 48 #71269
C:\git\runtime\src\mono\mono\mini\mini-generic-sharing.c 38 #71269
C:\git\runtime\src\mono\mono\mini\mini-amd64.c 34 #70417
C:\git\runtime\src\mono\mono\mini\decompose.c 30 #71269
C:\git\runtime\src\mono\mono\component\debugger-agent.c 27 #71269
C:\git\runtime\src\mono\mono\mini\dwarfwriter.c 26 #71269
C:\git\runtime\src\mono\mono\utils\monobitset.c 26 #71269
C:\git\runtime\src\mono\mono\mini\debug-mini.c 24 #71269
C:\git\runtime\src\mono\mono\mini\dominators.c 22 #71269
C:\git\runtime\src\mono\mono\metadata\class-setup-vtable.c 22 #71269
C:\git\runtime\src\mono\mono\mini\mini-exceptions.c 20 #71269
C:\git\runtime\src\mono\mono\mini\aot-runtime.c 20 #71269
C:\git\runtime\src\mono\mono\mini\mini-x86.c 20 #71269
C:\git\runtime\src\mono\mono\metadata\icall.c 18 #71269
C:\git\runtime\src\mono\mono\metadata\class.c 18 #71269
C:\git\runtime\src\mono\mono\metadata\sre.c 16 #71269
C:\git\runtime\src\mono\mono\mini\local-propagation.c 16 #71269
C:\git\runtime\src\mono\mono\component\debugger-engine.c 14 #71269
C:\git\runtime\src\mono\mono\metadata\class-init.c 14 #70417
C:\git\runtime\src\mono\mono\mini\mini-arm64.c 14 #71269
C:\git\runtime\src\mono\mono\mini\mini-arm.c 14 #71269
C:\git\runtime\src\mono\mono\sgen\sgen-marksweep.c 14 #71269
C:\git\runtime\src\mono\mono\metadata\reflection.c 12 #70783
C:\git\runtime\src\mono\mono\metadata\mono-hash.c 12 #70783
C:\git\runtime\src\mono\mono\metadata\object.c 12 #70783
C:\git\runtime\src\mono\mono\metadata\marshal.c 10 #70783
C:\git\runtime\src\mono\mono\metadata\mono-basic-block.c 10 #70783
C:\git\runtime\src\mono\mono\metadata\threads.c 10 #70783
C:\git\runtime\src\mono\mono\eventpipe\ep-rt-mono.c 10 #70417
C:\git\runtime\src\mono\mono\metadata\loader.c 8 #70783
C:\git\runtime\src\mono\mono\component\hot_reload.c 8 #70783
C:\git\runtime\src\mono\mono\metadata\memory-manager.c 8 #70783
C:\git\runtime\src\mono\mono\mini\abcremoval.c 8 #70783
C:\git\runtime\src\mono\mono\metadata\image.c 8 #70783
C:\git\runtime\src\mono\mono\metadata\custom-attrs.c 8 #70783
C:\git\runtime\src\mono\mono\sgen\sgen-internal.c 8 #71269
C:\git\runtime\src\mono\mono\mini\mini-profiler.c 6 #70783
C:\git\runtime\src\mono\mono\mini\seq-points.c 6 #70783
C:\git\runtime\src\mono\mono\mini\mini-runtime.c 6 #70783
C:\git\runtime\src\mono\mono\mini\driver.c 6 #70783
C:\git\runtime\src\mono\mono\metadata\debug-helpers.c 6 #70783
C:\git\runtime\src\mono\mono\utils\mono-flight-recorder.c 6 #70783
C:\git\runtime\src\mono\mono\metadata\sgen-new-bridge.c 6 #71269
C:\git\runtime\src\mono\mono\metadata\sgen-mono.c 6 #71269
C:\git\runtime\src\mono\mono\mini\mini-codegen.c 4 #70783
C:\git\runtime\src\mono\mono\mini\exceptions-amd64.c 4 #70783
C:\git\runtime\src\mono\mono\mini\linear-scan.c 4 #70783
C:\git\runtime\src\mono\mono\profiler\aot.c 4 #70783
C:\git\runtime\src\mono\mono\mini\simd-intrinsics.c 4 #70417
C:\git\runtime\src\mono\mono\mini\memory-access.c 4 #70783
C:\git\runtime\src\mono\mono\metadata\debug-mono-ppdb.c 4 #70783
C:\git\runtime\src\mono\mono\metadata\dynamic-stream.c 4 #70783
C:\git\runtime\src\mono\mono\utils\mono-poll.c 4 #70783
C:\git\runtime\src\mono\mono\metadata\marshal-shared.c 4 #71269
C:\git\runtime\src\mono\mono\metadata\marshal-lightweight.c 4 #71269
C:\git\runtime\src\mono\mono\metadata\mono-debug.c 4 #71269
C:\git\runtime\src\mono\mono\sgen\sgen-pinning.c 4 #71269
C:\git\runtime\src\mono\mono\sgen\sgen-debug.c 4 #71269
C:\git\runtime\src\mono\mono\utils\hazard-pointer.c 4 #71269
C:\git\runtime\src\mono\mono\metadata\exception.c 2 #70783
C:\git\runtime\src\mono\mono\mini\unwind.c 2 #70783
C:\git\runtime\src\mono\mono\mini\helpers.c 2 #70783
C:\git\runtime\src\mono\mono\mini\alias-analysis.c 2 #70783
C:\git\runtime\src\mono\mono\utils\lock-free-alloc.c 2 #70783
C:\git\runtime\src\mono\mono\metadata\dynamic-image.c 2 #70783
C:\git\runtime\src\mono\mono\mini\graph.c 2 #70783
C:\git\runtime\src\mono\mono\metadata\assembly.c 2 #70783
C:\git\runtime\src\mono\mono\mini\type-checking.c 2 #70783
C:\git\runtime\src\mono\mono\mini\lldb.c 2 #70783
C:\git\runtime\src\mono\mono\metadata\assembly-load-context.c 2 #70783
C:\git\runtime\src\mono\mono\metadata\sre-encode.c 2 #70783
C:\git\runtime\src\mono\mono\mini\mini-amd64-gsharedvt.c 2 #70783
C:\git\runtime\src\mono\mono\mini\monovm.c 2 #70783
C:\git\runtime\src\mono\mono\mini\calls.c 2 #70783
C:\git\runtime\src\mono\mono\mini\branch-opts.c 2 #70783
C:\git\runtime\src\mono\mono\metadata\marshal-ilgen.c 2 #71269
C:\git\runtime\src\mono\mono\metadata\sgen-stw.c 2 #71269
C:\git\runtime\src\mono\mono\metadata\seq-points-data.c 2 #71269
C:\git\runtime\src\mono\mono\utils\os-event-win32.c 2 #71269
C:\git\runtime\src\mono\mono\utils\mono-log-flight-recorder.c 2 #71269
C:\git\runtime\src\mono\mono\mini\mini-x86-gsharedvt.c 2 #71269
C:\git\runtime\src\mono\mono\mini\ir-emit.h 2 #71269
C:\git\runtime\src\mono\mono\mini\mini-arm64-gsharedvt.c 2 #71269
C:\git\runtime\src\mono\mono\mini\mini-arm-gsharedvt.c 2 #71269
C:\git\runtime\src\mono\mono\sgen\sgen-cardtable.c 2 #71269
C:\git\runtime\src\mono\mono\sgen\sgen-los.c 2 #71269
C:\git\runtime\src\mono\mono\sgen\sgen-thread-pool.c 2 #71269
C:\git\runtime\src\mono\mono\eglib\gfile.c 1 #70417
C:\git\runtime\src\mono\mono\eventpipe\ep-rt-mono.h 1 #70417
C:\git\runtime\src\mono\mono\eglib\gptrarray.c 1 #70417
C:\git\runtime\src\mono\mono\component\debugger-state-machine.c 1 #70417
C:\git\runtime\src\mono\mono\eglib\garray.c 1 #70417
Grand Total 1402

Enabling 4244 on Mono runtime Windows x86/x64 build generate 2615 1156 ~500 386 0 warnings:

File Count Comment
C:\git\runtime\src\mono\mono\mini\interp\transform.c 644 #69236
C:\git\runtime\src\mono\mono\mini\mini-amd64.c 386 #69236
C:\git\runtime\src\mono\mono\mini\method-to-ir.c 204 #69236
C:\git\runtime\src\mono\mono\mini\mini.h 123 #69236
C:\git\runtime\src\mono\mono\mini\tramp-amd64.c 118 #69236
C:\git\runtime\src\mono\mono\mini\aot-compiler.c 102 #69236
C:\git\runtime\src\mono\mono\mini\intrinsics.c 68 #69236
C:\git\runtime\src\mono\mono\metadata\sre.c 60 #69236
C:\git\runtime\src\mono\mono\metadata\metadata.c 58 #69236
C:\git\runtime\src\mono\mono\metadata\icall.c 58 #69236
C:\git\runtime\src\mono\mono\mini\aot-runtime.c 42 #69236
C:\git\runtime\src\mono\mono\mini\mini.c 38 #69236
C:\git\runtime\src\mono\mono\mini\dwarfwriter.c 38 #69236
C:\git\runtime\src\mono\mono\mini\interp\interp.c 32 #69236
C:\git\runtime\src\mono\mono\component\debugger-agent.c 31 #69236
C:\git\runtime\src\mono\mono\mini\exceptions-amd64.c 28 #69236
C:\git\runtime\src\mono\mono\metadata\class.c 26 #69236
C:\git\runtime\src\mono\mono\mini\tramp-amd64-gsharedvt.c 26 #69236
C:\git\runtime\src\mono\mono\metadata\image.c 26 #69236
C:\git\runtime\src\mono\mono\mini\ir-emit.h 26 #69236
C:\git\runtime\src\mono\mono\mini\ssa.c 24 #69236
C:\git\runtime\src\mono\mono\metadata\assembly.c 22 #69236
C:\git\runtime\src\mono\mono\metadata\class-init.c 22 #69236
C:\git\runtime\src\mono\mono\metadata\sre-encode.c 20 #69236
C:\git\runtime\src\mono\mono\mini\unwind.c 20 #69236
C:\git\runtime\src\mono\mono\mini\debug-mini.c 18 #69236
C:\git\runtime\src\mono\mono\mini\mini-exceptions.c 18 #69236
C:\git\runtime\src\mono\mono\mini\local-propagation.c 18 #69236
C:\git\runtime\src\mono\mono\mini\mini-runtime.c 18 #69236
C:\git\runtime\src\mono\mono\mini\decompose.c 18 #69236
C:\git\runtime\src\mono\mono\metadata\reflection.c 16 #69236
C:\git\runtime\src\mono\mono\mini\mini-generic-sharing.c 16 #69236
C:\git\runtime\src\mono\mono\mini\liveness.c 16 #69236
C:\git\runtime\src\mono\mono\mini\memory-access.c 14 #69236
C:\git\runtime\src\mono\mono\metadata\marshal.c 14 #69236
C:\git\runtime\src\mono\mono\mini\branch-opts.c 12 #69236
C:\git\runtime\src\mono\mono\eglib\giconv.c 12 #69236
C:\git\runtime\src\mono\mono\metadata\mono-basic-block.c 12 #69236
C:\git\runtime\src\mono\mono\mini\abcremoval.c 10 #69236
C:\git\runtime\src\mono\mono\eventpipe\ep-rt-mono.c 9 #69236
C:\git\runtime\src\mono\mono\mini\mini-codegen.c 8 #69236
C:\git\runtime\src\mono\mono\metadata\custom-attrs.c 8 #69236
C:\git\runtime\src\mono\mono\utils\networking.c 8 #69236
C:\git\runtime\src\mono\mono\mini\lldb.c 8 #69236
C:\git\runtime\src\mono\mono\mini\mini-profiler.c 8 #69236
C:\git\runtime\src\mono\mono\metadata\debug-helpers.c 6 #69236
C:\git\runtime\src\mono\mono\mini\alias-analysis.c 6 #69236
C:\git\runtime\src\mono\mono\mini\calls.c 6 #69236
C:\git\runtime\src\mono\mono\metadata\loader.c 6 #69236
C:\git\runtime\src\mono\mono\metadata\memory-manager.c 6 #69236
C:\git\runtime\src\mono\mono\utils\mono-codeman.c 4 #69236
C:\git\runtime\src\mono\mono\metadata\class-setup-vtable.c 4 #69236
C:\git\runtime\src\mono\mono\metadata\profiler.c 4 #69236
C:\git\runtime\src\mono\mono\utils\mono-dl.c 4 #69236
C:\git\runtime\src\mono\mono\mini\type-checking.c 4 #69236
C:\git\runtime\src\mono\mono\utils\mono-threads.c 4 #69236
C:\git\runtime\src\mono\mono\mini\seq-points.c 4 #69236
C:\git\runtime\src\mono\mono\utils\mono-error.c 4 #69236
C:\git\runtime\src\mono\mono\metadata\mempool.c 4 #69236
C:\git\runtime\src\mono\mono\mini\mini-trampolines.c 4 #69236
C:\git\runtime\src\mono\mono\mini\simd-intrinsics.c 4 #69236
C:\git\runtime\src\mono\mono\component\debugger-engine.c 3 #69236
C:\git\runtime\src\mono\mono\metadata\threads.c 2 #69236
C:\git\runtime\src\mono\mono\metadata\jit-info.c 2 #69236
C:\git\runtime\src\mono\mono\metadata\handle.c 2 #69236
C:\git\runtime\src\mono\mono\metadata\native-library.c 2 #69236
C:\git\runtime\src\mono\mono\utils\mono-threads-coop.c 2 #69236
C:\git\runtime\src\mono\mono\mini\driver.c 2 #69236
C:\git\runtime\src\mono\mono\metadata\mono-debug.c 2 #69236
C:\git\runtime\src\mono\mono\metadata\debug-mono-ppdb.c 2 #69236
C:\git\runtime\src\mono\mono\mini\cfold.c 2 #69236
C:\git\runtime\src\mono\mono\utils\mono-math-c.c 2 #69236
C:\git\runtime\src\mono\mono\utils\mono-path.c 2 #69236
C:\git\runtime\src\mono\mono\metadata\mono-hash.c 2 #69236
C:\git\runtime\src\mono\mono\profiler\aot.c 2 #69236
C:\git\runtime\src\mono\mono\utils\mono-time.c 2 #69236
C:\git\runtime\src\mono\mono\profiler\helper.c 2 #69236
C:\git\runtime\src\mono\mono\utils\lock-free-alloc.c 2 #69236
C:\git\runtime\src\mono\mono\component\event_pipe.c 1 #69236
C:\git\runtime\src\mono\mono\eglib\gstr.c 1 #69236
C:\git\runtime\src\mono\mono\eglib\gutf8.c 1 #69236
Grand Total 2615

//CC @lambdageek @vargaz

lateralusX added a commit to lateralusX/runtime that referenced this issue May 31, 2022
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.
lateralusX added a commit that referenced this issue May 31, 2022
* 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.
@danmoseley
Copy link
Member

@AaronRobinsonMSFT is CoreCLR work here now all done?
@lateralusX @fanyang-mono is Mono work still in progress, but on track for RC1 snap?

@fanyang-mono
Copy link
Member

@danmoseley The final piece of work should be merged no later than tmr. (#71269)

@fanyang-mono
Copy link
Member

@danmoseley The final piece of work should be merged no later than tmr. (#71269)
Merged.

@AaronRobinsonMSFT
Copy link
Member

@danmoseley The final piece of work should be merged no later than tmr. (#71269)
Merged.

W00t! Thank you @fanyang-mono @lambdageek @lateralusX @elinor-fung @am11 and anyone else who helped make this happen.

@GrabYourPitchforks Do we have an audit plan from SDL. Just to make sure we didn't miss anything.

@danmoseley
Copy link
Member

@GrabYourPitchforks ? what remains to close this..

@GrabYourPitchforks
Copy link
Member Author

I think we're good here! Will reopen it if new things crop up. Thanks again for the efforts. :)

@GrabYourPitchforks GrabYourPitchforks removed the help wanted [up-for-grabs] Good issue for external contributors label Jul 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants