From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 10CDC38485A6; Wed, 11 May 2022 10:48:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10CDC38485A6 From: "andrey.vihrov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/105562] New: [12 Regression] std::function::_M_invoker may be used uninitialized in std:regex move with -fno-strict-aliasing Date: Wed, 11 May 2022 10:48:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andrey.vihrov at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2022 10:48:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105562 Bug ID: 105562 Summary: [12 Regression] std::function::_M_invoker may be used uninitialized in std:regex move with -fno-strict-aliasing Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: andrey.vihrov at gmail dot com Target Milestone: --- Consider the following sample: #include int main() { std::regex a("."); std::regex b(std::move(a)); } Since GCC 12.1, compiling this code with "g++ -Wall -O1 -fno-strict-aliasing x.cpp" gives In file included from /usr/include/c++/12.1.0/regex:48, from x.cpp:1: In constructor 'std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes ...)>&&) [with _Res =3D bool; _ArgTypes =3D {char}]', inlined from 'std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type= >&&) [with _Char_type =3D char]' at /usr/include/c++/12.1.0/bits/regex_automaton.h:149:4, inlined from 'std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_end() [with _TraitsT =3D std::__cxx11::regex_traits]' at /usr/include/c++/12.1.0/bits/regex_automaton.h:290:24: /usr/include/c++/12.1.0/bits/std_function.h:405:42: warning: '*(std::function*)((char*)&__tmp + offsetof(std::__detail::_Sta= teT, std::__detail::_State::.std::__detail::_State_base::)).std::function::_M_invoker' may be used uninitialized [-Wmaybe-uninitialized] 405 | : _Function_base(), _M_invoker(__x._M_invoker) | ~~~~^~~~~~~~~~ In file included from /usr/include/c++/12.1.0/regex:63: /usr/include/c++/12.1.0/bits/regex_automaton.h: In member function 'std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_end() [with _TraitsT =3D std::__cxx11::regex_traits]': /usr/include/c++/12.1.0/bits/regex_automaton.h:287:17: note: '__tmp' declar= ed here 287 | _StateT __tmp(_S_opcode_subexpr_end); | ^~~~~ In member function 'bool std::_Function_base::_M_empty() const', inlined from 'std::function<_Res(_ArgTypes ...)>::operator bool() const [with _Res =3D bool; _ArgTypes =3D {char}]' at /usr/include/c++/12.1.0/bits/std_function.h:574:25, inlined from 'std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes ...)>&&) [with _Res =3D bool; _ArgTypes =3D {char}]' at /usr/include/c++/12.1.0/bits/std_function.h:407:6, inlined from 'std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type= >&&) [with _Char_type =3D char]' at /usr/include/c++/12.1.0/bits/regex_automaton.h:149:4, inlined from 'std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_end() [with _TraitsT =3D std::__cxx11::regex_traits]' at /usr/include/c++/12.1.0/bits/regex_automaton.h:290:24: /usr/include/c++/12.1.0/bits/std_function.h:247:37: warning: '*(const std::_Function_base*)((char*)&__tmp + offsetof(std::__detail::_StateT, std::__detail::_State::.std::__detail::_State_base::)).std::_Function_base::_M_manager' may be used uninitialized [-Wmaybe-uninitialized] 247 | bool _M_empty() const { return !_M_manager; } | ^~~~~~~~~~ /usr/include/c++/12.1.0/bits/regex_automaton.h: In member function 'std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_end() [with _TraitsT =3D std::__cxx11::regex_traits]': /usr/include/c++/12.1.0/bits/regex_automaton.h:287:17: note: '__tmp' declar= ed here 287 | _StateT __tmp(_S_opcode_subexpr_end); | ^~~~~ There are no warnings with -fstrict-aliasing. Related resources: * https://gcc.gnu.org/pipermail/gcc/2021-July/236851.html * https://gcc.gnu.org/g:c22bcfd2f7dc9bb5ad394720f4a612327dc898ba=