From f4dfdd1a39e3300b001d47758fea702499e99426 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Wed, 15 Feb 2023 15:25:02 +0000 Subject: [PATCH] unwindset parsing: Work around spurious GCC 12 warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 12 wrongly complains about the use of an uninitialized variable. Work around by doing a poor man's version of a variable with an accompanying Boolean. The build failure was: ``` In file included from /usr/include/c++/12/bits/stl_algobase.h:64, from /usr/include/c++/12/bits/stl_tree.h:63, from /usr/include/c++/12/map:60, from ../util/symbol_table_base.h:9, from ../util/symbol_table.h:9, from ../goto-programs/goto_model.h:15, from unwindset.h:15, from unwindset.cpp:9: In constructor ‘constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = std::__cxx11::basic_string&; _U2 = unsigned int&; typename std::enable_if<(std::_PCC::_MoveConstructiblePair<_U1, _U2>() && std::_PCC::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type = true; _T1 = dstringt; _T2 = unsigned int]’, inlined from ‘void unwindsett::parse_unwindset_one_loop(std::string, message_handlert&)’ at unwindset.cpp:174:28: /usr/include/c++/12/bits/stl_pair.h:535:42: error: ‘*(unsigned int*)((char*)&thread_nr + offsetof(nonstd::optional_lite::optionalt,nonstd::optional_lite::optional::contained))’ may be used uninitialized [-Werror=maybe-uninitialized] 535 | : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ unwindset.cpp: In member function ‘void unwindsett::parse_unwindset_one_loop(std::string, message_handlert&)’: unwindset.cpp:39:23: note: ‘*(unsigned int*)((char*)&thread_nr + offsetof(nonstd::optional_lite::optionalt,nonstd::optional_lite::optional::contained))’ was declared here 35 | optionalt thread_nr; | ^~~~~~~~~ ``` when using GCC 12: g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4) --- src/goto-instrument/unwindset.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/goto-instrument/unwindset.cpp b/src/goto-instrument/unwindset.cpp index eebd8c5682d..95e73247ef4 100644 --- a/src/goto-instrument/unwindset.cpp +++ b/src/goto-instrument/unwindset.cpp @@ -36,7 +36,9 @@ void unwindsett::parse_unwindset_one_loop( if(val.empty()) return; - optionalt thread_nr; + // we should use optionalt here, but then GCC 12 wrongly complains that we may be using an uninitialized variable + unsigned thread_nr = 0; + bool thread_nr_is_set = false; if(isdigit(val[0])) { auto c_pos = val.find(':'); @@ -44,6 +46,7 @@ void unwindsett::parse_unwindset_one_loop( { std::string nr = val.substr(0, c_pos); thread_nr = unsafe_string2unsigned(nr); + thread_nr_is_set = true; val.erase(0, nr.size() + 1); } } @@ -171,8 +174,10 @@ void unwindsett::parse_unwindset_one_loop( else uw = unsafe_string2unsigned(uw_string); - if(thread_nr.has_value()) - thread_loop_map[std::pair(id, *thread_nr)] = uw; + if(thread_nr_is_set) + { + thread_loop_map[std::make_pair(id, thread_nr)] = uw; + } else loop_map[id] = uw; }