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: Add compiler diagnostic flags #84

Merged
merged 4 commits into from
Mar 11, 2024
Merged

Conversation

hebasto
Copy link
Owner

@hebasto hebasto commented Jan 26, 2024

Sorry for not presenting the third commit as fixup ones ready to be auto-squashed.

@hebasto hebasto force-pushed the 240126-cmake-BA branch 2 times, most recently from 131db28 to d9d0ce7 Compare January 26, 2024 17:53
@hebasto
Copy link
Owner Author

hebasto commented Jan 27, 2024

Rebased.

@hebasto hebasto added the enhancement New feature or request label Jan 27, 2024
@@ -85,6 +85,9 @@ target_include_directories(bitcoinqt
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
)
set_property(SOURCE macnotificationhandler.mm
APPEND PROPERTY COMPILE_OPTIONS -Wno-error=deprecated-declarations

Choose a reason for hiding this comment

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

This isn't in the master branch? Also not sure why it's -Wno-error? We aren't moving to a state where we are using, or trying to enable -Werror by default?

Copy link
Owner Author

Choose a reason for hiding this comment

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

This isn't in the master branch?

bitcoin#29362 has been submitted to the master branch.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ok, dropped.

@@ -57,4 +57,6 @@ if(MSVC)
)
endif()

target_link_libraries(secp256k1 PRIVATE core_interface)
# Using core_base_interface instead of core_interface
# to avoid C++-specific flags from warn_interface.

Choose a reason for hiding this comment

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

I think this comment can be improved. We are avoiding passing warning flags to libsecp256k1 because it's a subtree, and warnings produced aren't fixable in our tree, making them pointless, not because it's C code.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks! Reworked.

)
try_append_cxx_flags("-Wself-assign" TARGET warn_interface
IF_CHECK_PASSED "-Wno-self-assign"
)

Choose a reason for hiding this comment

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

Missing -Wno-deprecated-copy ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes. It is not required anymore as CMake includes imported packages headers as system ones, which effectively suppresses external warnings.

@hebasto
Copy link
Owner Author

hebasto commented Feb 9, 2024

Drafted.

Please review #99 and #100 first.

@hebasto hebasto force-pushed the 240126-cmake-BA branch 4 times, most recently from 3ef5cc5 to 7878e2b Compare February 10, 2024 13:01
hebasto added a commit that referenced this pull request Feb 15, 2024
33dee19 fixup! cmake: Build `leveldb` static library (Hennadii Stepanov)

Pull request description:

  This PR split from #84

  It introduces a new `warn_leveldb_interface`, which overrides `-Wconditional-uninitialized` and `-Wsuggest-override` if any.

  For MSVC builds, dropped warning suppressions that are provided at the global level.

  For example, on the staging branch:
  ```
  $ env CC=clang CXX=clang++ CXXFLAGS="-Wconditional-uninitialized -Wsuggest-override" cmake -B build
  $ cmake --build build --target leveldb > /dev/null
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:474:17: warning: 'Name' overrides a member function but is not marked 'override' [-Wsuggest-override]
      const char* Name() const { return rep_->Name(); }
                  ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:110:15: note: overridden virtual function is here
    const char* Name() const override { return (*name_)(state_); }
                ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:475:10: warning: 'CreateFilter' overrides a member function but is not marked 'override' [-Wsuggest-override]
      void CreateFilter(const Slice* keys, int n, std::string* dst) const {
           ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:112:8: note: overridden virtual function is here
    void CreateFilter(const Slice* keys, int n, std::string* dst) const override {
         ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:478:10: warning: 'KeyMayMatch' overrides a member function but is not marked 'override' [-Wsuggest-override]
      bool KeyMayMatch(const Slice& key, const Slice& filter) const {
           ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:125:8: note: overridden virtual function is here
    bool KeyMayMatch(const Slice& key, const Slice& filter) const override {
         ^
  3 warnings generated.
  /home/hebasto/git/bitcoin/src/leveldb/db/version_set.cc:1016:55: warning: variable 'manifest_size' may be uninitialized when used here [-Wconditional-uninitialized]
    descriptor_log_ = new log::Writer(descriptor_file_, manifest_size);
                                                        ^~~~~~~~~~~~~
  /home/hebasto/git/bitcoin/src/leveldb/db/version_set.cc:997:25: note: initialize the variable 'manifest_size' to silence this warning
    uint64_t manifest_size;
                          ^
                           = 0
  1 warning generated.
  ```

ACKs for top commit:
  vasild:
    ACK 33dee19
  theuni:
    ACK 33dee19

Tree-SHA512: ffe9efc438bc808a42abaa42a45f7073c1e3cdd6404e9b8b811e94b304c2464f3df26c276d363c97a3941d50f0e6bcb3788f1d870dd23df86b0d9a33363b7e77
hebasto added a commit that referenced this pull request Feb 15, 2024
cbd43cc fixup! cmake: Build `bitcoind` executable (Hennadii Stepanov)
6be6d78 fixup! cmake: Build `bitcoin_util` static library (Hennadii Stepanov)

Pull request description:

  The `HAVE_THREAD_LOCAL` is not visible in `src/test/util_threadnames_tests.cpp`. It is easy to verify with the diff as follows:
  ```diff
  --- a/src/test/util_threadnames_tests.cpp
  +++ b/src/test/util_threadnames_tests.cpp
  @@ -55,6 +55,7 @@ std::set<std::string> RenameEnMasse(int num_threads)
   BOOST_AUTO_TEST_CASE(util_threadnames_test_rename_threaded)
   {
   #if !defined(HAVE_THREAD_LOCAL)
  +#error
       // This test doesn't apply to platforms where we don't have thread_local.
       return;
   #endif
  ```

  This PR fixes this issue by moving the macro definition to the `core_interface` library.

  Split from #84.

ACKs for top commit:
  vasild:
    ACK cbd43cc

Tree-SHA512: bd558ae35251d0e9bbdf494690a06ed57f6a36bdbf94840f1b134779bef5aa1de94ee53c962948a5a4b9cc11927777b5a919a7506779149e5fe0c6355c416419
@hebasto hebasto marked this pull request as ready for review February 15, 2024 09:57
@hebasto
Copy link
Owner Author

hebasto commented Feb 15, 2024

Rebased and undrafted.

Copy link

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK ab1a745

Comment on lines +263 to +276
# For -Wno-error=unreachable-code, please refer to https://github.com/bitcoin/bitcoin/issues/29334
configure_env: 'env CXXFLAGS="-Wno-error=unreachable-code"'
Copy link

Choose a reason for hiding this comment

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

Adding this to silence a particular issue, obviously has the problem that if new issues like that are created, then they will be silenced as well (on this platform). 👎 I understand that this is the best thing to do if there is resistance to change the source code.

Choose a reason for hiding this comment

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

The source code was changed to solve other issues, and so far no-one has shown why this version of the compiler isn't broken and/or emitting false positives (why is only the older version emitting these warnings?). Generally we don't refactor source code to work around warnings from compilers, let alone older compilers. Especially not when it's just in pursuit of using -Werror.

Comment on lines +259 to +282
string(STRIP "${CMAKE_CXX_FLAGS}" cxx_flags)
string(STRIP "${CMAKE_CXX_FLAGS_INIT}" cxx_flags_init)
if(cxx_flags STREQUAL cxx_flags_init)
Copy link

Choose a reason for hiding this comment

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

Non-blocker IMO, just mentioning: with this change it is no longer possible to set your own flags on the command line like cmake -DCMAKE_CXX_FLAGS=-myflag and have stuff from try_append_cxx_flags() from inside CMakeLists.txt appended to them.

To achieve this either one of the following worked for me:

export CXXFLAGS="-myflag" (and then run cmake)
or
-DCMAKE_CXX_COMPILER="c++;-myflag"

Choose a reason for hiding this comment

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

-DCMAKE_CXX_COMPILER="c++;-myflag"

This is definitely not someting that we would want (or encourage others) to do.

Copy link

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK ba8a3c3

The sneaked fixups look ok too.

@hebasto
Copy link
Owner Author

hebasto commented Feb 28, 2024

Rebased to avoid merge conflicts.

@vasild

ACK ba8a3c3

The sneaked fixups look ok too.

Sorry for invalidating your ACK :)

Copy link

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 3abba8b

Copy link

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

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

tACK e4ef404

Before (or when with this PR user overrides CMAKE_CXX_FLAGS):

Common compile options ................ -fno-extended-identifiers -fstack-reuse=none -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection

After (when CMAKE_CXX_FLAGS matches CMAKE_CXX_FLAGS_INIT -> meant to be set by a toolchain file):

Common compile options ................ -fno-extended-identifiers -fstack-reuse=none -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wno-unused-parameter

Copy link

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK e4ef404

@hebasto
Copy link
Owner Author

hebasto commented Mar 8, 2024

Rebased on top of the bitcoin#29577 after the latest syncing.

It made OBJCXXFLAGS="-Wno-error=deprecated-declarations" unneeded in the CI.

Copy link

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 695a5ca

@hebasto hebasto merged commit d01f59f into cmake-staging Mar 11, 2024
27 checks passed
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

Successfully merging this pull request may close these issues.

4 participants