[PATCH] libcamera: v4l2_subdevice: Work around false positive warning
Stefan Klug
stefan.klug at ideasonboard.com
Mon Jan 20 09:10:41 CET 2025
Hi Laurent,
Thank you for the patch.
On Tue, Jan 14, 2025 at 04:36:22PM +0200, Laurent Pinchart wrote:
> gcc 13.3.0, as provided by buildroot 2024.11.1, chokes when compiling
> v4l2_subdevice.cpp with ASan enabled, due to the usage of the C++
> standard library regex header:
>
> In file included from /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/functional:59,
> from ../../include/libcamera/base/utils.h:12,
> from ../../include/libcamera/base/log.h:15,
> from ../../include/libcamera/internal/v4l2_subdevice.h:20,
> from ../../src/libcamera/v4l2_subdevice.cpp:8:
> In constructor ‘std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes ...)>&&) [with _Res = bool; _ArgTypes = {char}]’,
> inlined from ‘std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type>&&) [with _Char_type = char]’ at /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h:149:4,
> inlined from ‘std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_begin() [with _TraitsT = std::__cxx11::regex_traits<char>]’ at /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h:281:24:
> /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/std_function.h:405:42: error: ‘*(std::function<bool(char)>*)((char*)&__tmp + offsetof(std::__detail::_StateT, std::__detail::_State<char>::<unnamed>.std::__detail::_State_base::<unnamed>)).std::function<bool(char)>::_M_invoker’ may be used uninitialized [-Werror=maybe-uninitialized]
> 405 | : _Function_base(), _M_invoker(__x._M_invoker)
> | ~~~~^~~~~~~~~~
> In file included from /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/regex:65,
> from ../../src/libcamera/v4l2_subdevice.cpp:11:
> /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h: In member function ‘std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_begin() [with _TraitsT = std::__cxx11::regex_traits<char>]’:
> /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h:279:17: note: ‘__tmp’ declared here
> 279 | _StateT __tmp(_S_opcode_subexpr_begin);
> | ^~~~~
> In member function ‘bool std::_Function_base::_M_empty() const’,
> inlined from ‘std::function<_Res(_ArgTypes ...)>::operator bool() const [with _Res = bool; _ArgTypes = {char}]’ at /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/std_function.h:574:25,
> inlined from ‘std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes ...)>&&) [with _Res = bool; _ArgTypes = {char}]’ at /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/std_function.h:407:6,
> inlined from ‘std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type>&&) [with _Char_type = char]’ at /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h:149:4,
> inlined from ‘std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_begin() [with _TraitsT = std::__cxx11::regex_traits<char>]’ at /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h:281:24:
> /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/std_function.h:247:37: error: ‘*(const std::_Function_base*)((char*)&__tmp + offsetof(std::__detail::_StateT, std::__detail::_State<char>::<unnamed>.std::__detail::_State_base::<unnamed>)).std::_Function_base::_M_manager’ may be used uninitialized [-Werror=maybe-uninitialized]
> 247 | bool _M_empty() const { return !_M_manager; }
> | ^~~~~~~~~~
> /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h: In member function ‘std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_begin() [with _TraitsT = std::__cxx11:
> /host/aarch64-buildroot-linux-gnu/include/c++/13.3.0/bits/regex_automaton.h:279:17: note: ‘__tmp’ declared here
> 279 | _StateT __tmp(_S_opcode_subexpr_begin);
> | ^~~~~
>
> This is a false positive that previously occurred with gcc 12.1.0 and
> was fixed in 12.2 (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562),
> and it seems to have now reappeared. The bug report indicates that the
> probability of such false positives increase when using sanitizers. As
> this isn't caught by CI, which compiles libcamera with gcc 13.3.0, the
> chance that such compilation failures will appear in environments
> without a clear pattern is relatively high. Work around the problem by
> disabling the warning around the inclusiong of the regex header.
>
> If the regex header needs to be included in other source files, creating
> a wrapped in libcamera-base may be a cleaner alternative.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Looking at the bug report (especially
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562#c29 ) it might be
sensible to disable -Werror globally when using sanitizers. Let's see
how often it pops up.
Reviewed-by: Stefan Klug <stefan.klug at ideasonboard.com>
Cheers,
Stefan
> ---
> src/libcamera/v4l2_subdevice.cpp | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 7a064d87da41..33279654db8c 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -8,12 +8,18 @@
> #include "libcamera/internal/v4l2_subdevice.h"
>
> #include <fcntl.h>
> -#include <regex>
> #include <sstream>
> #include <string.h>
> #include <sys/ioctl.h>
> #include <unistd.h>
>
> +#pragma GCC diagnostic push
> +#if defined __SANITIZE_ADDRESS__ && defined __OPTIMIZE__
> +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
> +#endif
> +#include <regex>
> +#pragma GCC diagnostic pop
> +
> #include <linux/media-bus-format.h>
> #include <linux/v4l2-subdev.h>
>
>
> base-commit: 2ae7b2ff7438a4deecff2a8b5de685cc14e5cd44
> --
> Regards,
>
> Laurent Pinchart
>
More information about the libcamera-devel
mailing list