apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.63k stars 3.56k forks source link

[C++] Potentially uninitialized variable warnings #44788

Closed raulcd closed 5 hours ago

raulcd commented 2 days ago

Describe the enhancement requested

When compiling locally with the ninja-python-release preset:

cmake -S arrow/cpp -B arrow/cpp/build \
        -DCMAKE_INSTALL_PREFIX=$ARROW_HOME \
        --preset ninja-release-python

cmake --build arrow/cpp/build --target install

I can see the following maybe-uninitialized warnings:

[36/311] Building CXX object src/arrow/CMakeFiles/arrow_compute.dir/compute/expression.cc.o
In static member function ‘static arrow::Result<std::optional<arrow::compute::Expression> > arrow::compute::{anonymous}::Inequality::SimplifyIsIn(const arrow::compute::{anonymous}::Inequality&, const arrow::compute::Expression::Call*)’,
    inlined from ‘arrow::Result<arrow::compute::Expression> arrow::compute::{anonymous}::Inequality::Simplify(arrow::compute::Expression)’ at /home/raulcd/code/arrow/cpp/src/arrow/compute/expression.cc:1329:7:
/home/raulcd/code/arrow/cpp/src/arrow/compute/expression.cc:1292:48: warning: ‘null_selection’ may be used uninitialized [-Wmaybe-uninitialized]
 1292 |     FilterOptions filter_options(null_selection);
      |                                                ^
/home/raulcd/code/arrow/cpp/src/arrow/compute/expression.cc: In member function ‘arrow::Result<arrow::compute::Expression> arrow::compute::{anonymous}::Inequality::Simplify(arrow::compute::Expression)’:
/home/raulcd/code/arrow/cpp/src/arrow/compute/expression.cc:1266:42: note: ‘null_selection’ was declared here
 1266 |     FilterOptions::NullSelectionBehavior null_selection;
      |                                          ^~~~~~~~~~~~~~
[47/311] Building CXX object src/arrow/CMakeFiles/arrow_csv.dir/csv/reader.cc.o
In file included from /usr/include/c++/13/bits/shared_ptr.h:53,
                 from /usr/include/c++/13/memory:80,
                 from /home/raulcd/code/arrow/cpp/src/arrow/csv/reader.h:20,
                 from /home/raulcd/code/arrow/cpp/src/arrow/csv/reader.cc:18:
In constructor ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::__shared_ptr<_Tp, _Lp>&&) [with _Tp = arrow::Buffer; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’,
    inlined from ‘std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Tp>&&) [with _Tp = arrow::Buffer]’ at /usr/include/c++/13/bits/shared_ptr.h:360:41,
    inlined from ‘constexpr std::_Optional_payload_base<_Tp>::_Storage<_Up, false>::_Storage(std::in_place_t, _Args&& ...) [with _Args = {std::shared_ptr<arrow::Buffer>}; _Up = std::shared_ptr<arrow::Buffer>; _Tp = std::shared_ptr<arrow::Buffer>]’ at /usr/include/c++/13/optional:244:8,
    inlined from ‘constexpr std::_Optional_payload_base<_Tp>::_Optional_payload_base(std::in_place_t, _Args&& ...) [with _Args = {std::shared_ptr<arrow::Buffer>}; _Tp = std::shared_ptr<arrow::Buffer>]’ at /usr/include/c++/13/optional:126:4,
    inlined from ‘constexpr std::_Optional_payload<std::shared_ptr<arrow::Buffer>, true, false, false>::_Optional_payload(std::in_place_t, _Args&& ...) [with _Args = {std::shared_ptr<arrow::Buffer>}][inherited from std::_Optional_payload_base<std::shared_ptr<arrow::Buffer> >]’ at /usr/include/c++/13/optional:399:42,
    inlined from ‘constexpr std::_Optional_payload<std::shared_ptr<arrow::Buffer>, false, false, false>::_Optional_payload(std::in_place_t, _Args&& ...) [with _Args = {std::shared_ptr<arrow::Buffer>}][inherited from std::_Optional_payload_base<std::shared_ptr<arrow::Buffer> >]’ at /usr/include/c++/13/optional:433:57,
    inlined from ‘constexpr std::_Optional_base<_Tp, <anonymous>, <anonymous> >::_Optional_base(std::in_place_t, _Args&& ...) [with _Args = {std::shared_ptr<arrow::Buffer>}; typename std::enable_if<is_constructible_v<_Tp, _Args ...>, bool>::type <anonymous> = false; _Tp = std::shared_ptr<arrow::Buffer>; bool <anonymous> = false; bool <anonymous> = false]’ at /usr/include/c++/13/optional:523:4,
    inlined from ‘constexpr std::optional<_Tp>::optional(_Up&&) [with _Up = std::shared_ptr<arrow::Buffer>; typename std::enable_if<__and_v<std::__not_<std::is_same<std::optional<_Tp>, typename std::remove_cv<typename std::remove_reference<_Tuple>::type>::type> >, std::__not_<std::is_same<std::in_place_t, typename std::remove_cv<typename std::remove_reference<_Tuple>::type>::type> >, std::is_constructible<_T1, _U1>, std::is_convertible<_U1, _T1> >, bool>::type <anonymous> = true; _Tp = std::shared_ptr<arrow::Buffer>]’ at /usr/include/c++/13/optional:751:47,
    inlined from ‘void arrow::internal::AlignedStorage<T>::construct(A&& ...) [with A = {std::shared_ptr<arrow::Buffer>}; T = std::optional<std::shared_ptr<arrow::Buffer> >]’ at /home/raulcd/code/arrow/cpp/src/arrow/util/aligned_storage.h:52:5,
    inlined from ‘void arrow::Result<T>::ConstructValue(U&&) [with U = std::shared_ptr<arrow::Buffer>; T = std::optional<std::shared_ptr<arrow::Buffer> >]’ at /home/raulcd/code/arrow/cpp/src/arrow/result.h:448:23,
    inlined from ‘arrow::Result<T>::Result(U&&) [with U = std::shared_ptr<arrow::Buffer>; E = void; T = std::optional<std::shared_ptr<arrow::Buffer> >]’ at /home/raulcd/code/arrow/cpp/src/arrow/result.h:165:19,
    inlined from ‘arrow::Result<std::optional<_Up> > arrow::TransformIterator<T, V>::Pump() [with T = std::shared_ptr<arrow::Buffer>; V = std::shared_ptr<arrow::Buffer>]’ at /home/raulcd/code/arrow/cpp/src/arrow/util/iterator.h:306:27:
/usr/include/c++/13/bits/shared_ptr_base.h:1532:9: warning: ‘*(std::__shared_ptr<arrow::Buffer, __gnu_cxx::_S_atomic>*)((char*)&next + offsetof(arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >,arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >::yield_value_.std::optional<std::shared_ptr<arrow::Buffer> >::<unnamed>.std::_Optional_base<std::shared_ptr<arrow::Buffer>, false, false>::<unnamed>)).std::__shared_ptr<arrow::Buffer, __gnu_cxx::_S_atomic>::_M_ptr’ may be used uninitialized [-Wmaybe-uninitialized]
 1532 |       : _M_ptr(__r._M_ptr), _M_refcount()
      |         ^~~~~~~~~~~~~~~~~~
In file included from /home/raulcd/code/arrow/cpp/src/arrow/record_batch.h:30,
                 from /home/raulcd/code/arrow/cpp/src/arrow/csv/reader.h:24:
/home/raulcd/code/arrow/cpp/src/arrow/util/iterator.h: In member function ‘arrow::Result<std::optional<_Up> > arrow::TransformIterator<T, V>::Pump() [with T = std::shared_ptr<arrow::Buffer>; V = std::shared_ptr<arrow::Buffer>]’:
/home/raulcd/code/arrow/cpp/src/arrow/util/iterator.h:295:12: note: ‘*(std::__shared_ptr<arrow::Buffer, __gnu_cxx::_S_atomic>*)((char*)&next + offsetof(arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >,arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >::yield_value_.std::optional<std::shared_ptr<arrow::Buffer> >::<unnamed>.std::_Optional_base<std::shared_ptr<arrow::Buffer>, false, false>::<unnamed>)).std::__shared_ptr<arrow::Buffer, __gnu_cxx::_S_atomic>::_M_ptr’ was declared here
  295 |       auto next = *next_res;
      |            ^~~~
In destructor ‘std::__shared_count<_Lp>::~__shared_count() [with __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’,
    inlined from ‘std::__shared_ptr<_Tp, _Lp>::~__shared_ptr() [with _Tp = arrow::Buffer; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/13/bits/shared_ptr_base.h:1524:7,
    inlined from ‘std::shared_ptr<arrow::Buffer>::~shared_ptr()’ at /usr/include/c++/13/bits/shared_ptr.h:175:11,
    inlined from ‘constexpr void std::_Optional_payload_base<_Tp>::_M_destroy() [with _Tp = std::shared_ptr<arrow::Buffer>]’ at /usr/include/c++/13/optional:287:35,
    inlined from ‘constexpr void std::_Optional_payload_base<_Tp>::_M_reset() [with _Tp = std::shared_ptr<arrow::Buffer>]’ at /usr/include/c++/13/optional:318:14,
    inlined from ‘constexpr void std::_Optional_payload_base<_Tp>::_M_reset() [with _Tp = std::shared_ptr<arrow::Buffer>]’ at /usr/include/c++/13/optional:315:7,
    inlined from ‘std::_Optional_payload<_Tp, false, _Copy, _Move>::~_Optional_payload() [with _Tp = std::shared_ptr<arrow::Buffer>; bool _Copy = false; bool _Move = false]’ at /usr/include/c++/13/optional:441:65,
    inlined from ‘std::_Optional_base<std::shared_ptr<arrow::Buffer>, false, false>::~_Optional_base()’ at /usr/include/c++/13/optional:512:12,
    inlined from ‘std::optional<std::shared_ptr<arrow::Buffer> >::~optional()’ at /usr/include/c++/13/optional:707:11,
    inlined from ‘arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >::~TransformFlow()’ at /home/raulcd/code/arrow/cpp/src/arrow/util/iterator.h:220:8,
    inlined from ‘arrow::Result<std::optional<_Up> > arrow::TransformIterator<T, V>::Pump() [with T = std::shared_ptr<arrow::Buffer>; V = std::shared_ptr<arrow::Buffer>]’ at /home/raulcd/code/arrow/cpp/src/arrow/util/iterator.h:308:5:
/usr/include/c++/13/bits/shared_ptr_base.h:1071:28: warning: ‘((std::__shared_count<__gnu_cxx::_S_atomic>*)((char*)&next + offsetof(arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >,arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >::yield_value_.std::optional<std::shared_ptr<arrow::Buffer> >::<unnamed>.std::_Optional_base<std::shared_ptr<arrow::Buffer>, false, false>::_M_payload.std::_Optional_payload<std::shared_ptr<arrow::Buffer>, false, false, false>::<unnamed>.std::_Optional_payload<std::shared_ptr<arrow::Buffer>, true, false, false>::<unnamed>.std::_Optional_payload_base<std::shared_ptr<arrow::Buffer> >::_M_payload)))[1].std::__shared_count<>::_M_pi’ may be used uninitialized [-Wmaybe-uninitialized]
 1071 |           _M_pi->_M_release();
      |           ~~~~~~~~~~~~~~~~~^~
/home/raulcd/code/arrow/cpp/src/arrow/util/iterator.h: In member function ‘arrow::Result<std::optional<_Up> > arrow::TransformIterator<T, V>::Pump() [with T = std::shared_ptr<arrow::Buffer>; V = std::shared_ptr<arrow::Buffer>]’:
/home/raulcd/code/arrow/cpp/src/arrow/util/iterator.h:295:12: note: ‘((std::__shared_count<__gnu_cxx::_S_atomic>*)((char*)&next + offsetof(arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >,arrow::TransformFlow<std::shared_ptr<arrow::Buffer> >::yield_value_.std::optional<std::shared_ptr<arrow::Buffer> >::<unnamed>.std::_Optional_base<std::shared_ptr<arrow::Buffer>, false, false>::_M_payload.std::_Optional_payload<std::shared_ptr<arrow::Buffer>, false, false, false>::<unnamed>.std::_Optional_payload<std::shared_ptr<arrow::Buffer>, true, false, false>::<unnamed>.std::_Optional_payload_base<std::shared_ptr<arrow::Buffer> >::_M_payload)))[1].std::__shared_count<>::_M_pi’ was declared here
  295 |       auto next = *next_res;
      |            ^~~~

Component(s)

C++

kou commented 5 hours ago

Issue resolved by pull request 44789 https://github.com/apache/arrow/pull/44789