Skip to content
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

A lot of warnings from GCC 14.2 #1818

Open
FitzRoyX opened this issue Feb 6, 2025 · 7 comments
Open

A lot of warnings from GCC 14.2 #1818

FitzRoyX opened this issue Feb 6, 2025 · 7 comments

Comments

@FitzRoyX
Copy link
Contributor

FitzRoyX commented Feb 6, 2025

Note that when I reported the warnings to ymfm, he basically said it's a problem on our end

-- Configuring done (33.1s)
-- Generating done (0.5s)
-- Build files have been written to: C:/_Downloads/ares-master/build
[80/285] Building CXX object thirdparty/CMakeFiles/ymfm.dir/ymfm/src/ymfm_opl.cpp.obj
In file included from C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_opl.cpp:32:
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.ipp: In member function 'void ymfm::fm_engine_base<RegisterType>::engine_timer_expired(uint32_t) [with RegisterType = ymfm::opl_registers_base<3>]':
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.ipp:1525:31: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 1525 |         m_timer_running[tnum] = false;
      |         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_opl.h:38,
                 from C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_opl.cpp:31:
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.h:448:17: note: at offset 2 into destination object 'ymfm::fm_engine_base<ymfm::opl_registers_base<3> >::m_timer_running' of size 2
  448 |         uint8_t m_timer_running[2];      // current timer running state
      |                 ^~~~~~~~~~~~~~~
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.ipp: In member function 'void ymfm::fm_engine_base<RegisterType>::engine_timer_expired(uint32_t) [with RegisterType = ymfm::opl_registers_base<4>]':
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.ipp:1525:31: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 1525 |         m_timer_running[tnum] = false;
      |         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.h:448:17: note: at offset 2 into destination object 'ymfm::fm_engine_base<ymfm::opl_registers_base<4> >::m_timer_running' of size 2
  448 |         uint8_t m_timer_running[2];      // current timer running state
      |                 ^~~~~~~~~~~~~~~
[83/285] Building CXX object thirdparty/CMakeFiles/ymfm.dir/ymfm/src/ymfm_opq.cpp.obj
In file included from C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_opq.cpp:32:
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.ipp: In member function 'void ymfm::fm_engine_base<RegisterType>::engine_timer_expired(uint32_t) [with RegisterType = ymfm::opq_registers]':
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.ipp:1525:31: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 1525 |         m_timer_running[tnum] = false;
      |         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_opq.h:37,
                 from C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_opq.cpp:31:
C:/_Downloads/ares-master/thirdparty/ymfm/src/ymfm_fm.h:448:17: note: at offset 2 into destination object 'ymfm::fm_engine_base<ymfm::opq_registers>::m_timer_running' of size 2
  448 |         uint8_t m_timer_running[2];      // current timer running state
      |                 ^~~~~~~~~~~~~~~
[84/285] Building CXX object nall/CMakeFiles/nall.dir/nall.cpp.obj
In file included from C:/_Downloads/ares-master/nall/string/core.hpp:7,
                 from C:/_Downloads/ares-master/nall/string.hpp:348,
                 from C:/_Downloads/ares-master/nall/inode.hpp:7,
                 from C:/_Downloads/ares-master/nall/file-buffer.hpp:6,
                 from C:/_Downloads/ares-master/nall/file.hpp:3,
                 from C:/_Downloads/ares-master/nall/directory.hpp:3,
                 from C:/_Downloads/ares-master/nall/directory.cpp:1,
                 from C:/_Downloads/ares-master/nall/nall.cpp:9:
In member function 'nall::string::type& nall::string::resize(u32)',
    inlined from 'nall::string& nall::string::_append(const nall::stringify<T>&) [with T = char*]' at C:/_Downloads/ares-master/nall/string/core.hpp:66:9,
    inlined from 'nall::string& nall::string::append(const T&, P&& ...) [with T = char [38]; P = {}]' at C:/_Downloads/ares-master/nall/string/core.hpp:54:10,
    inlined from 'nall::string::string(T&&, P&& ...) [with T = const char (&)[38]; P = {}]' at C:/_Downloads/ares-master/nall/string.hpp:156:11,
    inlined from 'void nall::print(P&& ...) [with P = {const char (&)[38]}]' at C:/_Downloads/ares-master/nall/string/format.hpp:72:10,
    inlined from 'nall::TCP::Socket::open(u32, bool)::<lambda()>' at C:/_Downloads/ares-master/nall/tcptext/tcp-socket.cpp:97:16,
    inlined from 'constexpr _Res std::__invoke_impl(__invoke_other, _Fn&&, _Args&& ...) [with _Res = void; _Fn = nall::TCP::Socket::open(u32, bool)::<lambda()>; _Args = {}]' at C:/mingw64/include/c++/14.2.0/bits/invoke.h:61:36,
    inlined from 'constexpr typename std::__invoke_result<_Functor, _ArgTypes>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = nall::TCP::Socket::open(u32, bool)::<lambda()>; _Args = {}]' at C:/mingw64/include/c++/14.2.0/bits/invoke.h:96:40,
    inlined from 'typename std::thread::_Invoker<_Tuple>::__result<_Tuple>::type std::thread::_Invoker<_Tuple>::_M_invoke(std::_Index_tuple<_Ind ...>) [with long long unsigned int ..._Ind = {0}; _Tuple = std::tuple<nall::TCP::Socket::open(u32, bool)::<lambda()> >]' at C:/mingw64/include/c++/14.2.0/bits/std_thread.h:301:26,
    inlined from 'typename std::thread::_Invoker<_Tuple>::__result<_Tuple>::type std::thread::_Invoker<_Tuple>::operator()() [with _Tuple = std::tuple<nall::TCP::Socket::open(u32, bool)::<lambda()> >]' at C:/mingw64/include/c++/14.2.0/bits/std_thread.h:308:20,
    inlined from 'void std::thread::_State_impl<_Callable>::_M_run() [with _Callable = std::thread::_Invoker<std::tuple<nall::TCP::Socket::open(u32, bool)::<lambda()> > >]' at C:/mingw64/include/c++/14.2.0/bits/std_thread.h:253:20:
C:/_Downloads/ares-master/nall/string/allocator/adaptive.hpp:64:23: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   64 |   get()[_size = size] = 0;
      |   ~~~~~~~~~~~~~~~~~~~~^~~
In file included from C:/_Downloads/ares-master/nall/string.hpp:350:
C:/_Downloads/ares-master/nall/string/format.hpp: In member function 'void std::thread::_State_impl<_Callable>::_M_run() [with _Callable = std::thread::_Invoker<std::tuple<nall::TCP::Socket::open(u32, bool)::<lambda()> > >]':
C:/_Downloads/ares-master/nall/string/format.hpp:72:10: note: at offset 37 into destination object 's' of size 32
   72 |   string s{std::forward<P>(p)...};
      |          ^
At global scope:
cc1plus.exe: note: unrecognized command-line option '-Wno-deprecated-literal-operator' may have been intended to silence earlier diagnostics
cc1plus.exe: note: unrecognized command-line option '-Wno-comma' may have been intended to silence earlier diagnostics
cc1plus.exe: note: unrecognized command-line option '-Wno-shorten-64-to-32' may have been intended to silence earlier diagnostics
[109/285] Linking CXX executable sourcery\rundir\sourcery.exe
Copy binary sourcery to rundir
[258/285] Building CXX object ares/CMakeFiles/ares.dir/component/processor/sh2/sh2.cpp.obj
In file included from C:/_Downloads/ares-master/ares/component/processor/sh2/sh2.cpp:28:
C:/_Downloads/ares-master/ares/component/processor/sh2/instructions.cpp:516:20: warning: declaration of 'void ares::SH2::MOVWI(u32, u32)' with attribute 'noinline' follows inline declaration [-Wattributes]
  516 | NALL_NOINLINE auto SH2::MOVWI(u32 d, u32 n) -> void {
      |                    ^~~
In file included from C:/_Downloads/ares-master/ares/component/processor/sh2/sh2.cpp:5:
C:/_Downloads/ares-master/ares/component/processor/sh2/sh2.hpp:132:15: note: previous declaration of 'void ares::SH2::MOVWI(u32, u32)' here
  132 |   inline auto MOVWI(u32 d, u32 n) -> void;
      |               ^~~~~
C:/_Downloads/ares-master/ares/component/processor/sh2/instructions.cpp:522:20: warning: declaration of 'void ares::SH2::MOVLI(u32, u32)' with attribute 'noinline' follows inline declaration [-Wattributes]
  522 | NALL_NOINLINE auto SH2::MOVLI(u32 d, u32 n) -> void {
      |                    ^~~
C:/_Downloads/ares-master/ares/component/processor/sh2/sh2.hpp:133:15: note: previous declaration of 'void ares::SH2::MOVLI(u32, u32)' here
  133 |   inline auto MOVLI(u32 d, u32 n) -> void;
      |               ^~~~~
C:/_Downloads/ares-master/ares/component/processor/sh2/instructions.cpp:528:20: warning: declaration of 'void ares::SH2::MOVA(u32)' with attribute 'noinline' follows inline declaration [-Wattributes]
  528 | NALL_NOINLINE auto SH2::MOVA(u32 d) -> void {
      |                    ^~~
C:/_Downloads/ares-master/ares/component/processor/sh2/sh2.hpp:134:15: note: previous declaration of 'void ares::SH2::MOVA(u32)' here
  134 |   inline auto MOVA(u32 d) -> void;
      |               ^~~~
[264/285] Building CXX object ares/CMakeFiles/ares.dir/component/processor/z80/z80.cpp.obj
In file included from C:/_Downloads/ares-master/ares/component/processor/z80/z80.cpp:6:
C:/_Downloads/ares-master/ares/component/processor/z80/disassembler.cpp:2:53: warning: 'optnone' attribute directive ignored [-Wattributes]
    2 | auto Z80::disassembleInstruction(maybe<n16> _pc) -> string {
      |                                                     ^~~~~~
C:/_Downloads/ares-master/ares/component/processor/z80/disassembler.cpp:43:35: warning: 'optnone' attribute directive ignored [-Wattributes]
   43 | auto Z80::disassembleContext() -> string {
      |                                   ^~~~~~
C:/_Downloads/ares-master/ares/component/processor/z80/disassembler.cpp:102:54: warning: 'optnone' attribute directive ignored [-Wattributes]
  102 | auto Z80::disassemble(n16 pc, n8 prefix, n8 code) -> string {
      |                                                      ^~~~~~
C:/_Downloads/ares-master/ares/component/processor/z80/disassembler.cpp:386:56: warning: 'optnone' attribute directive ignored [-Wattributes]
  386 | auto Z80::disassembleCB(n16 pc, n8 prefix, n8 code) -> string {
      |                                                        ^~~~~~
C:/_Downloads/ares-master/ares/component/processor/z80/disassembler.cpp:676:63: warning: 'optnone' attribute directive ignored [-Wattributes]
  676 | auto Z80::disassembleCBd(n16 pc, n8 prefix, i8 d, n8 code) -> string {
      |                                                               ^~~~~~
C:/_Downloads/ares-master/ares/component/processor/z80/disassembler.cpp:944:56: warning: 'optnone' attribute directive ignored [-Wattributes]
  944 | auto Z80::disassembleED(n16 pc, n8 prefix, n8 code) -> string {
      |                                                        ^~~~~~
[281/285] Building CXX object mia/CMakeFiles/mia.dir/mia.cpp.obj
In file included from C:/_Downloads/ares-master/nall/string/core.hpp:7,
                 from C:/_Downloads/ares-master/nall/string.hpp:348,
                 from C:/_Downloads/ares-master/nall/arithmetic.hpp:9,
                 from C:/_Downloads/ares-master/nall/nall.hpp:11,
                 from C:/_Downloads/ares-master/mia/mia.hpp:1,
                 from C:/_Downloads/ares-master/mia/mia.cpp:1:
In member function 'nall::string::type& nall::string::resize(u32)',
    inlined from 'nall::string& nall::string::_append(const nall::stringify<T>&) [with T = char*]' at C:/_Downloads/ares-master/nall/string/core.hpp:66:9,
    inlined from 'nall::string& nall::string::append(const T&, P&& ...) [with T = char [46]; P = {unsigned int&, const char (&)[2]}]' at C:/_Downloads/ares-master/nall/string/core.hpp:54:10,
    inlined from 'nall::string::string(T&&, P&& ...) [with T = const char (&)[46]; P = {unsigned int&, const char (&)[2]}]' at C:/_Downloads/ares-master/nall/string.hpp:156:11,
    inlined from 'void nall::print(P&& ...) [with P = {const char (&)[46], unsigned int&, const char (&)[2]}]' at C:/_Downloads/ares-master/nall/string/format.hpp:72:10,
    inlined from 'nall::vector<unsigned char> nall::Decode::CHD::read(u32) const' at C:/_Downloads/ares-master/nall/decode/chd.hpp:223:8,
    inlined from 'nall::vfs::cdrom::loadChd(const nall::string&)::<lambda(uintptr)>' at C:/_Downloads/ares-master/nall/vfs/cdrom.hpp:242:42,
    inlined from 'R nall::function<R(P ...)>::lambda<L>::operator()(P ...) const [with L = nall::vfs::cdrom::loadChd(const nall::string&)::<lambda(uintptr)>; R = void; P = {long long unsigned int}]' at C:/_Downloads/ares-master/nall/function.hpp:65:55:
C:/_Downloads/ares-master/nall/string/allocator/adaptive.hpp:64:23: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   64 |   get()[_size = size] = 0;
      |   ~~~~~~~~~~~~~~~~~~~~^~~
In file included from C:/_Downloads/ares-master/nall/string.hpp:350:
C:/_Downloads/ares-master/nall/string/format.hpp: In member function 'R nall::function<R(P ...)>::lambda<L>::operator()(P ...) const [with L = nall::vfs::cdrom::loadChd(const nall::string&)::<lambda(uintptr)>; R = void; P = {long long unsigned int}]':
C:/_Downloads/ares-master/nall/string/format.hpp:72:10: note: at offset 45 into destination object 's' of size 32
   72 |   string s{std::forward<P>(p)...};
      |          ^
[285/285] Linking CXX executable desktop-ui\rundir\ares.exe
Copy dependencies to binary directory (C:/_Downloads/ares-master/build)...
Copy binary desktop-ui to rundir
Press any key to continue . . .```
@jcm93
Copy link
Contributor

jcm93 commented Feb 6, 2025

The stringop-overflow heuristic being buggy is indeed an issue, it was silenced a couple days ago.

@jcm93
Copy link
Contributor

jcm93 commented Feb 6, 2025

The inline/noinline collisions and other attribute issues seem at first glance like things that should legitimately be fixed, but I haven't looked at them in detail yet. In any case, generally, warning and compiler settings are something I am paying attention to and are likely to evolve. Generally gcc diagnostic flags are less kept up than clang and MSVC ones at present.

@LukeUsher
Copy link
Member

Regarding the YMFM warnings, the only place we call that timer function is within a for loop with a range of 2, meaning we only pass 0 or 1.

Most likely scenario is the compiler is having trouble detecting that the only values passed at 0 or 1 due to template shenanigans in nall.

@omarandlorraine
Copy link

There is a related issue #1399 which I raised some time ago.

I'm interested in fixing some of these warnings, if I can. Would the project accept a pull-request which:

  • remedies some of the warnings
  • adds a workflow to reject code that generates warnings
    ?

@jcm93
Copy link
Contributor

jcm93 commented Feb 10, 2025

adds a workflow to reject code that generates warnings

I would recommend against this; compiler strictness is still a moving target in the new build system, and PRs will already show inline warning annotations (though only from clang).

@omarandlorraine
Copy link

adds a workflow to reject code that generates warnings

I would recommend against this; compiler strictness is still a moving target in the new build system, and PRs will already show inline warning annotations (though only from clang).

Doesn't have to be a moving target, a well-configured workflow could reject specific warnings. Here is something I do in my day job: I use clang-tidy to make sure that the core guidelines I care about are enforced. Many other lints are of course ignored.

Something like this is my .clang-tidy configuration:

Checks: >
  -*,
  clang-analyzer-*,
  bugprone-*,
  -bugprone-branch-clone,
  -bugprone-easily-swappable-parameters,
  misc-*,
  -misc-non-private-member-variables-in-classes,
  readability-*,
  -readability-magic-numbers,
  -readability-identifier-length,
  -readability-identifier-length,
  -readability-function-cognitive-complexity,
  cppcoreguidelines-*,
  -cppcoreguidelines-avoid-magic-numbers,
  -cppcoreguidelines-avoid-non-const-global-variables,
  -cppcoreguidelines-pro-type-vararg,
  -cppcoreguidelines-macro-usage,
  -cppcoreguidelines-avoid-c-arrays,
  -cppcoreguidelines-pro-bounds-constant-array-index,
  -cppcoreguidelines-pro-bounds-pointer-arithmetic,
  -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
  -cppcoreguidelines-pro-type-cstyle-cast,
  -cppcoreguidelines-non-private-member-variables-in-classes,
WarningsAsErrors: '*'
HeaderFilterRegex: '^(?!.*(/usr/|/lib/|/include)).*'

I might also enable new lints as and when the code improves

@jcm93
Copy link
Contributor

jcm93 commented Feb 12, 2025

Doesn't have to be a moving target

Moving target might have been the slightly wrong term to use. My point is more so that integrating increased code strictness and code quality tools is a work in progress at the moment, and that that work has to be undertaken carefully and methodically, with an eye toward what is appropriate for ares in particular, given its idiosyncratic codebase and code style as well as the need to continually consider the wide array of toolchains ares supports.

My top priority at the moment is giving us the ability to effectively isolate diagnostic flags in nall from the rest of our targets (we cannot do this at the moment because every target is effectively also compiling nall). From there, I want to work on the clang diagnostic flags (and potentially other toolchain diagnostic flags) in some targets to address the things that seem to have the highest probability of being actual bugs (as well as any issues uncovered by the clang analyzer, though we are mostly ok on this front). These are mostly things like suspicious implicit conversions, potential aliasing issues, unused warnings, signed/unsigned comparisons, and generally the extent to which ares plays fast and loose with types. Many of these issues do overlap with checks that exist in clang-tidy, just occurring at compile time.

Linting tools like clang-tidy might have value for ares, but at the moment I consider them less of a priority (other than the analyzer and the overlap with actual compiler diagnostics) because of their being more challenging to integrate with ares and having more of a style focus. As mentioned, ares has an idiosyncratic style, but that style is well-established and developers are well-acquainted with it. Unless the tool is identifying things that have a high probability of being genuine application bugs, rather than style differences between ares and LLVM (and admittedly this can be something of a grey area), I think there may be more important fish that need frying first. Regardless, I would definitely welcome experimentation with its output to see if it can deliver useful feedback not already provided by the analyzer and clang itself!

Though you didn't mention it directly, a word on formatting as well: I think ideally, codifying ares's code style into something understood by clang-format would be nice, it would also be challenging to integrate across the codebase for various reasons, and introduce more complexity. I think the focus should be on what problem the enforced formatting would solve. At the moment, ares's style is pretty uniform, and radically different styles coming from different contributors, or in different areas of the codebase, does not seem to be an issue at present. As such, I do not see a pressing need to introduce enforced formatting, though in the long term it may be a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants