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

[Mono] Fix warnings to enable W4 on Windows. #66710

Merged
merged 24 commits into from
Apr 12, 2022

Conversation

lateralusX
Copy link
Member

@lateralusX lateralusX commented Mar 16, 2022

Upstream work done in different downstream repros.

Fix selected W4 warnings on Windows as well as suppressing specific W4 warnings to be fixed. Give us option to do Mono runtime build using W4 on Windows and also turn on warnings as errors to prevent regressions on the warnings we enable.

Fix Warning C4146 in Mono runtime build.

Enable "Treat Warnings As Errors" to prevent regressions on the warnings we decided to fix.

@dotnet-issue-labeler
Copy link

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

@AaronRobinsonMSFT
Copy link
Member

@lateralusX Is this helping to contribute to #66154?

@AaronRobinsonMSFT
Copy link
Member

If so, I would also add the following to help ensure regressions are caught early.

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors

@lateralusX
Copy link
Member Author

If so, I would also add the following to help ensure regressions are caught early.

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors

Yes, that was my plan to do in this PR, once I worked it through.

@lateralusX
Copy link
Member Author

lateralusX commented Mar 21, 2022

@lateralusX Is this helping to contribute to #66154?

This PR is mainly upstreaming other work getting W4 building on Mono, so not explicitly target any of those warnings, but yet another stepping stone bringing down warnings altogether on Mono while still bumping to W4.

I think I will be able to take care of:

#pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned

as part of this PR, so will add some progression on #66154 as well.

@lateralusX lateralusX force-pushed the lateralusX/fix-warnings-w4 branch from e026c33 to 49b688f Compare March 21, 2022 15:42
@lateralusX lateralusX changed the title WIP: [Mono] Fix warnings to enable W4 on Windows. [Mono] Fix warnings to enable W4 on Windows. Mar 21, 2022
@lateralusX lateralusX marked this pull request as ready for review March 21, 2022 15:45
@@ -6433,7 +6429,7 @@ get_types_for_source_file (gpointer key, gpointer value, gpointer user_data)
files = get_source_files_for_type (klass);
g_hash_table_insert (info->source_files, klass, files);

for (int i = 0; i < files->len; ++i) {
for (guint i = 0; i < files->len; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change GPtrArray->len to an int instead ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we probably could, did a quick test and it still builds without additional warnings. Any particular reason to do that, except that we might have usage in many places that do int i when iterating it? It will also affect the signature of g_ptr_array_remove_* that currently accept indexes to go from guint to int.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it to int would reduce the amount of changes required and make it easier to write code to iterate on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for the warnings, this PR makes sure all builds as expected, but enabling more warnings might trigger more warnings related to doing unsinged->signed conversion. This PR is already very big, and I mainly did small number of changes like the one above, just to align with original types in files already touched. Could an alternative be to look into that when we enable some additional warnings that will trigger errors due to singed/unsigned mismatch? An alternative would be to revert all of the int i -> source type in this PR and then take care of all in separate PR when enabling more warnings where we also could discuss if we should change type when iterating or at the source. So mainly three options for this PR:

  • Leave as is, changes done so far will simplify future fixes of warnings, but might need to be change back in a couple of places if we change any of the source types like len -> int.
  • Revert the int i -> source type done in this PR (unless it breaks some other warnings enabled by this PR).
  • Change len to int and fix all usage of it as part of this PR, includes changing some of the array API's as well, but as said, this PR is already big enough.

Thoughts?

@@ -529,14 +529,14 @@ hot_reload_close_all (MonoImage *base_image)
if (!info)
return;
for (GList *ptr = info->delta_info; ptr; ptr = ptr->next) {
DeltaInfo *info = (DeltaInfo *)ptr->data;
if (!info)
DeltaInfo *delta_info = (DeltaInfo *)ptr->data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the problem here ?

Copy link
Member Author

@lateralusX lateralusX Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change was mainly aligning the last DeltaInfo *info to use same naming as all others in this file, delta_info, the other change in this file fix a local hiding issue, warning C4456: declaration of 'info' hides previous local declaration, that was very common through the code and fixed in this PR.

@lateralusX lateralusX force-pushed the lateralusX/fix-warnings-w4 branch 3 times, most recently from 9ce5ecc to c81c2b0 Compare March 23, 2022 15:33
@lateralusX lateralusX force-pushed the lateralusX/fix-warnings-w4 branch 2 times, most recently from 0e88c45 to 277a366 Compare March 24, 2022 10:04
@lateralusX
Copy link
Member Author

Rebased and fixed review feedback.

# Conflicts:
#	src/mono/mono/component/debugger-agent.c

# Conflicts:
#	src/mono/mono/component/debugger-agent.c
# Conflicts:
#	src/mono/mono/mini/method-to-ir.c

# Conflicts:
#	src/mono/mono/mini/aot-runtime.c
# Conflicts:
#	src/mono/mono/component/hot_reload.c
@lateralusX lateralusX force-pushed the lateralusX/fix-warnings-w4 branch from 4a86047 to 0617776 Compare April 11, 2022 08:34
@lateralusX
Copy link
Member Author

Moved disable of zlib warnings from source file into cmake file + rebase branch.

@lateralusX lateralusX merged commit ff4d3d4 into dotnet:main Apr 12, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants