]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src: Add sign-compare warnings to clang 65012/head
authorAlex Ainscow <aainscow@uk.ibm.com>
Wed, 13 Aug 2025 11:03:21 +0000 (12:03 +0100)
committerAlex Ainscow <aainscow@uk.ibm.com>
Wed, 20 Aug 2025 06:43:59 +0000 (07:43 +0100)
For a while, GCC has generated warnings about sign errors. A common
mistake if compiling with clang was to accidentally introduce signedness
errors, which were picked up by the GCC builds.

This occurs due to an inconsistency in -Wall implementation between clang
and gcc: gcc includes sign-compare, clang does not.

See:
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wall
vs
https://clang.llvm.org/docs/DiagnosticsReference.html#wall

Note that sign-compare is included under -Wextra for clang:
https://clang.llvm.org/docs/DiagnosticsReference.html#wextra

Clang will now generate similar warnings with -Wsign-compare:
https://clang.llvm.org/docs/DiagnosticsReference.html#wsign-compare

Interestingly, if specified on its own, -Wsign-compare will include
C, whereas gcc -Wall affects C++ only. Therefore we must work around
this in the make file to emulate the GCC behaviour in clang builds.

Also fix a couple of warnings found in some tests.

Signed-off-by: Alex Ainscow <aainscow@uk.ibm.com>
src/CMakeLists.txt
src/test/osd/TestECBackend.cc
src/test/osd/test_scrubber_be.cc

index ada75e281c5fd6663845703ee2864a0c50cf57ff..a851c25312cd779f96841c3997d2bd6988693910 100644 (file)
@@ -113,6 +113,10 @@ if(NOT MSVC)
   add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-ignored-qualifiers>)
 endif()
 
+if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
+  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wsign-compare>)
+endif()
+
 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-ftemplate-depth-1024>)
 
 # Because Boost can't be bothered to not include its own deprecated headers
index ca299abd9631108574b410788c3b46a4cfbe9c40..664969be295823b13ddd79bd5c58e6a3b2aee75d 100644 (file)
@@ -158,12 +158,12 @@ public:
       // for each missing shard.
       for (auto a : available) {
         minimum_set.insert(a);
-        if (minimum_set.size() == data_chunk_count) {
+        if (std::cmp_equal(minimum_set.size(), data_chunk_count)) {
           break;
         }
       }
 
-      if (minimum_set.size() != data_chunk_count) {
+      if (std::cmp_not_equal(minimum_set.size(), data_chunk_count)) {
         minimum_set.clear();
         return -EIO; // Cannot recover.
       }
@@ -174,7 +174,6 @@ public:
     }
     return 0;
   }
-
   [[deprecated]]
   int minimum_to_decode(const std::set<int> &want_to_read,
     const std::set<int> &available,
index bc6db59ac17af663ea971b0c49f9ce290886c0ea..60e995aed5f6c023d032238869bd396fc998bcc3 100644 (file)
@@ -118,7 +118,7 @@ class TestPg : public PgScrubBeListener {
     }
 
     for (shard_id_t i; i < get_ec_sinfo().get_k(); ++i) {
-      for (int j = 0; j < get_ec_sinfo().get_chunk_size(); j++) {
+      for (int j = 0; std::cmp_less(j, get_ec_sinfo().get_chunk_size()); j++) {
         encode_map.at(i).c_str()[j] =
             chunks[j + (get_ec_sinfo().get_chunk_size() * i.id)];
         for (shard_id_t k{static_cast<int8_t>(get_ec_sinfo().get_k_plus_m())};