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

Fix compiler warnings with MacOS Clang 14.0.3 #6467

Merged
merged 12 commits into from
Apr 6, 2023

Conversation

michael-wb
Copy link
Contributor

@michael-wb michael-wb commented Apr 4, 2023

What, How & Why?

MacOS Clang 14.0.3 enables -Wunqualified-std-cast-call and -Wunused-but-set-variable warnings. Fix the unqualified move's and existing unused-but-set-variable warnings in the Realm Core source. The warning is disabled only for the bison and flex generated parser files and the Catch2 library.

Updated

☑️ ToDos

  • 📝 Changelog update
  • [ ] 🚦 Tests (or not relevant)
  • [ ] C-API, if public C++ API changed.

@kiburtse
Copy link
Contributor

kiburtse commented Apr 4, 2023

Why introduce this project wide? It's pretty useful, why not to fix warnings? There are not that many of them

@michael-wb
Copy link
Contributor Author

Why introduce this project wide? It's pretty useful, why not to fix warnings? There are not that many of them

There are some of these warnings in the 3rd party catch and generated/parser source as well - I can fix the couple of warnings in the regular source.

@kiburtse
Copy link
Contributor

kiburtse commented Apr 4, 2023

Why introduce this project wide? It's pretty useful, why not to fix warnings? There are not that many of them

There are some of these warnings in the 3rd party catch and generated/parser source as well - I can fix the couple of warnings in the regular source.

Well it's fine to set flags for external dependencies, but would be good to keep our codebase clean at least.

@michael-wb michael-wb requested review from fealebenpae and tgoyne April 4, 2023 17:46
CMakeLists.txt Outdated
@@ -57,6 +57,17 @@ function(add_cxx_flag_if_supported flag)
endif()
endfunction()

function(check_if_cxx_compiler_flag_supported flag out_var)
if(flag MATCHES "^-Wno-")
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead.
Copy link
Member

Choose a reason for hiding this comment

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

If we're assuming unrecognized -Wno flags will be ignored can't we just set -Wno-unused-but-set-variable unconditionally?

Copy link
Contributor Author

@michael-wb michael-wb Apr 4, 2023

Choose a reason for hiding this comment

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

I had originally just disabled it for the project, but I got some push back, so I disabled it just for the 3rd party items. I guess it is a valid warning, similar to the -Wunused-variable warning that is already enabled. There were only 2 places where this warning was found in core, but they were also found in Catch2 and the flex generated parser cpp file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh - I misread your comment. I think this was there to avoid a false positive to determine if a no- flag was really supported or not by the compiler.

Copy link
Member

Choose a reason for hiding this comment

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

If passing -Wno to the compiler doesn't result in an error we don't really care if it's actually doing anything or not, so doing complicated things to try to check if it's actually disabling a warning seems pointless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point and I can change it if you prefer, but I copied this function wholesale from this commit: ca39b9f and it also matches the existing add_cxx_flag_if_supported function already in the same CMakeLists.txt file.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC unrecognized -Wno-blah flags aren't exactly ignored. There are in a weird Schrödinger state where they act as-if ignored unless the compiler prints anything else, in which case it also prints a warning about an unrecognized flag. This can be annoying if you pass tons of -Wno-blah flags unconditionally. Note that we are already doing something like this:

function(add_cxx_flag_if_supported flag)
if(flag MATCHES "^-Wno-")
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead.
string(REPLACE "-Wno-" "-W" check_flag ${flag})
else()
set(check_flag ${flag})
endif()
check_cxx_compiler_flag(${check_flag} HAVE${check_flag})
if(HAVE${check_flag})
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${flag}>)
endif()
endfunction()

I added that logic based on this code from the mongo build scripts.

We should probably dedupe this logic between the functions though.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, I remember running into that before.

Copy link
Contributor

@RedBeard0531 RedBeard0531 left a comment

Choose a reason for hiding this comment

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

Please change add_cxx_flag_if_supported to use check_if_cxx_flag_is_supported rather than duplicating the logic.

CMakeLists.txt Outdated
@@ -112,6 +123,8 @@ else()
# compilers that we still support. It is also harmless, unlike pessimizing moves.
add_cxx_flag_if_supported(-Wno-redundant-move)

check_if_cxx_compiler_flag_supported(-Wno-unused-but-set-variable HAS-Wno-unused-but-set-variable)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the output is only used in one place, I think I'd move this there.

@michael-wb
Copy link
Contributor Author

FYI - The Jenkins failure is due to the results file not being exported successfully from the iOSSimulator, even though all the tests passed. This happens occasionally and we have an existing task to look into this.

CMakeLists.txt Outdated
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead.
string(REPLACE "-Wno-" "-W" check_flag ${flag})
function(append_source_file_compile_options file property)
get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS)
get_source_file_property(OLD_OPTS ${file} COMPILE_OPTIONS)

Because you are in a function, you don't need to use a unique variable name.

CMakeLists.txt Outdated
string(REPLACE "-Wno-" "-W" check_flag ${flag})
function(append_source_file_compile_options file property)
get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS)
if ("${SRC_PROPS_${file}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${file}}" STREQUAL "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ("${SRC_PROPS_${file}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${file}}" STREQUAL "")
if (NOT OLD_OPTS)

The if() command in cmake is wierd and magical but somehow works out well with the rest of cmake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice!

@michael-wb
Copy link
Contributor Author

michael-wb commented Apr 5, 2023

Created #6474 to address the data race failure in LangBindHelper_HandoverBetweenThreads in core tests for the ubuntu2004-encryption-tsan task. The other failure is the known asymmetric sync issue.

@michael-wb michael-wb merged commit 15543d5 into master Apr 6, 2023
@michael-wb michael-wb deleted the mwb/fix-compiler-warnings branch April 6, 2023 03:37
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants