]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: suppress -Wmaybe-uninitialized warning in memstore PageSet 63796/head
authorKefu Chai <tchaikov@gmail.com>
Tue, 17 Jun 2025 08:28:57 +0000 (16:28 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 18 Jun 2025 03:26:32 +0000 (11:26 +0800)
Suppress GCC-15 false positive warning about uninitialized memory in
Page::operator delete() using placement new pattern.

GCC-15 incorrectly warns about potentially uninitialized data when
using placement new with manual memory management:

```
[409/506] Building CXX object src/os/CMakeFiles/os.dir/memstore/MemStore.cc.o
In file included from /home/kefu/dev/ceph/src/os/memstore/MemStore.h:29,
                 from /home/kefu/dev/ceph/src/os/memstore/MemStore.cc:28:
In static member function ‘static void Page::operator delete(void*)’,
    inlined from ‘void Page::put()’ at /home/kefu/dev/ceph/src/os/memstore/PageSet.h:36:41:
/home/kefu/dev/ceph/src/os/memstore/PageSet.h:83:42: warning: ‘*this.Page::data’ may be used uninitialized [-Wmaybe-uninitialized]
   83 |     delete[] reinterpret_cast<Page*>(p)->data;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
```

The warning is a false positive: Page instances are constructed using
placement new over pre-allocated memory, requiring manual cleanup of
the underlying data array. This is the intended behavior and memory
is properly initialized. So, in this change we just silence this warning
in CMake after checking its availability.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/os/memstore/CMakeLists.txt

index 1f7db6b544d5d30bb8cec18de66186b105357919..e59b64af7b4fa5978886806bbf85a2559203bd1a 100644 (file)
@@ -1,2 +1,10 @@
+include(CheckCXXCompilerFlag)
+
 add_library(memstore
   MemStore.cc)
+check_cxx_compiler_flag("-Wno-maybe-uninitialized"
+  HAS_WARNING_MAYBE_UNINITIALIZED)
+if(HAS_WARNING_MAYBE_UNINITIALIZED)
+  target_compile_options(os
+    PRIVATE "-Wno-maybe-uninitialized")
+endif()