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

GCC complains about possibly uninitialized variables when compiling with CXXFLAGS='-Og -g' #8280

Closed
techgeeknz opened this issue Jul 22, 2020 · 0 comments · Fixed by #8281
Closed

Comments

@techgeeknz
Copy link
Contributor

Version of OpenTTD

Since f44a9a5, I expect.

Expected result

The project compiles without issues, as it does with -O2 or -O3.

Actual result

Compiler logs this warning:

In file included from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/station_map.h:13:0,
                 from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:12:
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/rail_map.h: In function ‘void UpdateSignalsAroundSegment(SigFlags)’:
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/rail_map.h:452:68: warning: ‘trackdir’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   SetSignalStates(tile, GetSignalStates(tile) | SignalAlongTrackdir(trackdir));
                                                 ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:411:11: note: ‘trackdir’ was declared here
  Trackdir trackdir;
           ^~~~~~~~
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp: In function ‘SigFlags ExploreSegment(Owner)’:
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:343:26: warning: ‘enterdir’ may be used uninitialized in this function [-Wmaybe-uninitialized]
      if (dir != enterdir && (tracks & _enterdir_to_trackbits[dir])) { // any track incidating?
          ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:121:4: warning: ‘tile’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (this->data[i].tile == tile && this->data[i].dir == dir) {
    ^~
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:271:12: note: ‘tile’ was declared here
  TileIndex tile;
            ^~~~
In file included from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/tile_map.h:14:0,
                 from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/rail_map.h:17,
                 from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/station_map.h:13,
                 from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:12:
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/map_func.h: In function ‘SigSegState UpdateSignalsInBuffer(Owner)’:
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/map_func.h:345:29: warning: ‘dir’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  assert(IsValidDiagDirection(dir));
                             ^
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:478:16: note: ‘dir’ was declared here
  DiagDirection dir;
                ^~~
In file included from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/station_map.h:13:0,
                 from /home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:12:
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/rail_map.h:39:30: warning: ‘tile’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  return (RailTileType)GB(_m[t].m5, 6, 2);
                              ^
/home/user/projects/openttd-jgrpp/OpenTTD-patches/src/signal.cpp:477:12: note: ‘tile’ was declared here
  TileIndex tile;
            ^~~~

Steps to reproduce

Check out master, run cmake with CXXFLAGS='-Og -g'. Note this is the only warning produced.

Notes

I have had a preliminary look at the code, and this appears to be a benign warning; so possibly just initializing the variables appropriately upon declaration is enough to silence it.

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

Successfully merging a pull request may close this issue.

1 participant