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

Add compiler warnings while in debug mode #52

Open
dkrautha opened this issue Aug 4, 2021 · 4 comments
Open

Add compiler warnings while in debug mode #52

dkrautha opened this issue Aug 4, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@dkrautha
Copy link
Collaborator

dkrautha commented Aug 4, 2021

We only get a limited number of warnings when in release mode (using gcc 10). We also see many warnings when compiling with clang, so it might be a good idea to enable these in debug mode for gcc.

@dkrautha dkrautha added the enhancement New feature or request label Aug 4, 2021
@dkrautha dkrautha self-assigned this Aug 4, 2021
@ahuston-0
Copy link
Collaborator

This should actually be pretty easy to do, but it depends on how much detail we really want on our warnings. I have a makefile somewhere that will spit out just about every warning ever, but I doubt we want that level of detail. I'll also look into seeing what flags are enabled by default in debug vs release.

@ahuston-0
Copy link
Collaborator

Alright so status update on this! If you add the following to the top level CMakeLists.txt, we get a lot of warnings.

if (MSVC)
    # warning level 4 and all warnings as errors
    add_compile_options(/W4 /WX)
else()
    # lots of warnings and all warnings as errors
    add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()

I got that from this StackOverflow post, but I did remove -Werror for testing purposes and then also -pedantic as the pedantic warnings were also coming from GLAD and other external dependencies. I then used this command cmake --build build --clean-first | grep \| | wc -l to get an estimate of the number of warnings. This works because a warning with GCC/Ninja/CMake seems to have one line with a line number, a pipe character, the offending code, and then another line with a pipe character and an indicator of what part of the line caused the warning. Therefore, the previously mentioned command should counts roughly twice the amount of lines as there are warnings. As of today, there are 4332 lines of warnings in the main branch, meaning that there are probably just over 2100 warnings in the entire codebase. Taking care of all of this is going to be a struggle for sure. I will probably open a separate issue for this.

@ahuston-0
Copy link
Collaborator

As for the original request, I'll look at what flags CMake's release mode uses vs their debug mode flags and see if we can get debug mode to have the same warnings.

@ahuston-0
Copy link
Collaborator

Apparently the issue here is that CMake disables optimizations by default for debug mode, so its harder for the compiler to tell when things are potentially uninitialized (a common cause of warnings in release mode that we don't see in debug mode). Looking at this, we could probably try enabling -O1 and seeing if that's enough optimization for the compiler to pick up on the fact that something's wrong while not optimizing out variables that we want to look at.

@ahuston-0 ahuston-0 self-assigned this May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants