Skip to content

unwindset parsing: Work around spurious GCC 12 warning #7540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

tautschnig
Copy link
Collaborator

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<char>&; _U2 = unsigned int&; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = 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<unsigned int>,nonstd::optional_lite::optional<unsigned int>::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<unsigned int>,nonstd::optional_lite::optional<unsigned int>::contained))’ was declared here
   35 |   optionalt<unsigned> thread_nr;
      |                       ^~~~~~~~~

when using GCC 12: g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

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<char>&; _U2 = unsigned int&; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = 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<unsigned int>,nonstd::optional_lite::optional<unsigned int>::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<unsigned int>,nonstd::optional_lite::optional<unsigned int>::contained))’ was declared here
   35 |   optionalt<unsigned> thread_nr;
      |                       ^~~~~~~~~
```
when using GCC 12: g++ (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frustrating but understandable.

@NlightNFotis
Copy link
Contributor

Would it be better if instead of complicating the code to suppress the warning, we just suppressed the warning using a pragma for that file only, like this:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
    write(foo, bar, baz);
#pragma GCC diagnostic pop

?

https://stackoverflow.com/a/26003732

@thomasspriggs
Copy link
Contributor

I would much prefer suppressing the warning rather than working around it by removing usage of optionalt. The compilers analysis is clearly incorrect in this case. I also get a variation of this error from other at least one other part of the code base when I try to build locally. This suppressing the warning be done across the build as a quick work-around by adding the following to cmake - -DCMAKE_CXX_FLAGS="-Wno-maybe-uninitialized"

@codecov
Copy link

codecov bot commented Feb 15, 2023

Codecov Report

Base: 78.49% // Head: 78.49% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (f4dfdd1) compared to base (5678ed6).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #7540   +/-   ##
========================================
  Coverage    78.49%   78.49%           
========================================
  Files         1667     1667           
  Lines       191437   191440    +3     
========================================
+ Hits        150261   150264    +3     
  Misses       41176    41176           
Impacted Files Coverage Δ
src/goto-instrument/unwindset.cpp 85.84% <100.00%> (+0.41%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@thomasspriggs
Copy link
Contributor

Alternative approach here - #7542

@TGWDB TGWDB mentioned this pull request Feb 15, 2023
7 tasks
@tautschnig
Copy link
Collaborator Author

Closing in favour of #7542.

@tautschnig tautschnig closed this Feb 16, 2023
@tautschnig tautschnig deleted the cleanup/gcc12-warning branch February 16, 2023 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants