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

cmake: enable more strict compiler warnings #508

Merged
merged 6 commits into from
Sep 9, 2020
Merged

cmake: enable more strict compiler warnings #508

merged 6 commits into from
Sep 9, 2020

Conversation

axic
Copy link
Member

@axic axic commented Aug 24, 2020

No description provided.

@axic axic force-pushed the cmake-warnings branch 2 times, most recently from ec2f408 to e57f3d1 Compare August 24, 2020 12:31
@chfast
Copy link
Collaborator

chfast commented Aug 27, 2020

Add -Wmissing-declarations (may be GCC only)

@@ -1963,7 +1963,7 @@ ExecutionResult execute(
}
case Instr::f64_promote_f32:
{
stack.top() = double{stack.top().f32};
stack.top() = static_cast<double>(stack.top().f32);
Copy link
Member Author

Choose a reason for hiding this comment

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

@chfast do you want this to go into master?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have consensus here?

@axic axic force-pushed the cmake-warnings branch 7 times, most recently from 788f2eb to bece2a1 Compare September 2, 2020 13:17
@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

Merging #508 into master will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #508   +/-   ##
=======================================
  Coverage   98.73%   98.73%           
=======================================
  Files          56       56           
  Lines        8704     8704           
=======================================
  Hits         8594     8594           
  Misses        110      110           

@@ -87,6 +87,12 @@ macro(cable_configure_compiler)
# Enable basing warnings set and treat them as errors.
add_compile_options(-Werror -Wall -Wextra -Wshadow)

add_compile_options(-Wdouble-promotion -Wcast-qual -Wcast-align -Wdangling-else -Wlogical-not-parentheses -Wmissing-declarations)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this must be checked against documentation.
E.g. -Wlogical-not-parentheses

Copy link
Member Author

Choose a reason for hiding this comment

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

I added these based on documentation: first added a lot of the things I liked, then removed those which are included in -Wall (and other settings we have). Seems like this one slipped through the cracks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I picked this one randomly.

The -Wdouble-promotion should be remove as I don't want the change #508 (comment).

I will check the rest.

Copy link
Collaborator

@chfast chfast Sep 2, 2020

Choose a reason for hiding this comment

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

  • It seems -Wcast-qual and -Wcast-align is only for C-style casts of pointers. Unlikely we will see such thing in our code, but the warning option can stay.
  • The -Wdangling-else is enabled by default/-Wall.
  • The -Wmissing-declarations is nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

The -Wdouble-promotion should be remove as I don't want the change #508 (comment).

Do you have a reasoning? I'd be also interested to hear @gumb0's view.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The -Wdouble-promotion should be remove as I don't want the change #508 (comment).

Do you have a reasoning? I'd be also interested to hear @gumb0's view.

The double{x} is superior to static_cast<double>(x) and the -Wdouble-promotion forbids using the first syntax. It is rather a compiler bug due to fact that -Wdouble-promotion predates the double{x} syntax.

There is even Clang bug for this: https://bugs.llvm.org/show_bug.cgi?id=34062.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@chfast @gumb0 any other warnings we should/could enable?

Yes, try

-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-switch-enum -Wno-float-equal -Wno-double-promotion

I found many easy fixes with these already.

Copy link
Collaborator

Choose a reason for hiding this comment

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

-Wlogical-not-parentheses looks to be included in -Wall?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Move the changes to the main CMakeLists.txt, do not modify the Cable file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cleaned up now.

test/utils/wasm_engine.cpp Outdated Show resolved Hide resolved
@chfast chfast force-pushed the cmake-warnings branch 2 times, most recently from 0fdc110 to 9b65842 Compare September 3, 2020 21:46
test/utils/wasm3_engine.cpp Outdated Show resolved Hide resolved
@chfast chfast force-pushed the cmake-warnings branch 3 times, most recently from 445273e to 1d5168c Compare September 3, 2020 22:02
@chfast chfast force-pushed the cmake-warnings branch 4 times, most recently from cddddec to 5228ae2 Compare September 4, 2020 20:38
@chfast chfast changed the base branch from master to exception_vtables September 4, 2020 21:11
@chfast chfast marked this pull request as ready for review September 4, 2020 21:13
Base automatically changed from exception_vtables to master September 4, 2020 21:20

option(WEVERYTHING "Enable almost all compiler warnings" OFF)
if(WEVERYTHING)
add_compile_options(-Weverything)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do I not see these on CI?
Build Tidy (Debug) step outputs

----
Generator:  Ninja
Compiler:   Clang
Build Type: Debug
LTO:        OFF
Flags:          -Dd_m3HasTracer -Wall -Wextra -Wparentheses -Wundef -Wpointer-arith -Wstrict-aliasing=2 -Werror=implicit-function-declaration -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -Werror=shadow
Debug flags:   -g -DDEBUG=1 -ggdb -O0
Release flags: -O3 -Wfatal-errors -fomit-frame-pointer -fno-stack-check -fno-stack-protector
----

are these not all of the flags?

Copy link
Collaborator

Choose a reason for hiding this comment

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

These are wasm3 flags. We don't add ours to theirs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see any warning emitted in Build Tidy, do we not generate any currently? If we did, would CI fail?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean, if it fails CI, what's the point of making them optional?

Copy link
Collaborator

Choose a reason for hiding this comment

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

People can still build it locally without a struggle.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mean they can build it locally without -Weverything for compilers that we don't test?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. Clang discourages usage of -Weverything regularly for projects so I want to follow this rule for now. While Fizzy is actively maintained it is probably not big deal, but future versions of Clang may enable something we don't want.

@@ -0,0 +1,15 @@
// Fizzy: A fast WebAssembly interpreter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this file should be experimental.hpp, because two of its three functions are defined in experimental.cpp?

Also not sure if the third one - leb128u_decode_u64_noinline - needs to be in its own cpp.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would go with something less specific than parser_benchmarks.cpp: experimental.cpp is fine.

This is not explicitly needed now as I discovered [[noinline]] attribute...

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is resolved now to use experimental.hpp for alternative LEB128 implementation. The other functions were moved to parser_benchmarks.cpp with [[gnu::noinline]] attribute.

@@ -137,8 +137,8 @@ class TestValues
std::array<T, ps.size() * 2 + 1> a;

auto it = std::begin(a);
it = std::transform(std::reverse_iterator{std::end(ps)},
std::reverse_iterator{std::begin(ps)}, it, std::negate<T>{});
it = std::transform(std::make_reverse_iterator(std::end(ps)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this resolve some warning?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is warning that reverse_iterator is may not to designed for CTAD (as it does not have any explicit CTAD hints). I think it is ok to change it here as this is the only case for this warning. And I'm also considering rewriting these test arrays to constexpr version where STL algorithms are going to be less useful.

@axic axic merged commit 2340104 into master Sep 9, 2020
@axic axic deleted the cmake-warnings branch September 9, 2020 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants