SDL-Hercules-390 / hyperion

The SDL Hercules 4.x Hyperion version of the System/370, ESA/390, and z/Architecture Emulator
Other
237 stars 89 forks source link

Compiler warnings when building with gcc version 11.4.0 - a minor issue #637

Closed Peter-J-Jansen closed 5 months ago

Peter-J-Jansen commented 5 months ago

When building with gcc version 11.4.0 under Ubuntu 22.04, some warnings show up; I assume they can be ignored though.

ckddasd.c: In function 'DefineExtent.constprop':
ckddasd.c:6944:34: warning: 'orig_e7_iobuf' may be used uninitialized in this function [-Wmaybe-uninitialized]
 6944 |                 || (orig_e7_iobuf[LRE(17)] & CKDOPER_CODE) == CKDOPER_RDANY
      |                     ~~~~~~~~~~~~~^~~~~~~~~
[...]
In file included from dasdload64.c:31:
dasdload2.h: In function 'process_iebcopy_file.constprop':
dasdload2.h:2206:25: warning: array subscript 'DATABLK[0]' is partly outside array bounds of 'unsigned char[276]' [-Warray-bounds]
 2206 |               blkp->rec = rec;
      |               ~~~~~~~~~~^~~~~
dasdload2.h:2181:22: note: referencing an object of size 276 allocated by 'malloc'
 2181 |     blkp = (DATABLK*)malloc(blklen);
      |                      ^~~~~~~~~~~~~~
[...]
In file included from dasdload.c:31:
dasdload2.h: In function 'process_iebcopy_file.constprop':
dasdload2.h:2206:25: warning: array subscript 'DATABLK[0]' is partly outside array bounds of 'unsigned char[276]' [-Warray-bounds]
 2206 |               blkp->rec = rec;
      |               ~~~~~~~~~~^~~~~
dasdload2.h:2181:22: note: referencing an object of size 276 allocated by 'malloc'
 2181 |     blkp = (DATABLK*)malloc(blklen);
      |                      ^~~~~~~~~~~~~~

Cheers,

Peter

Fish-Git commented 5 months ago

Fixed by commit 873c8ba587be8404dd47cae0604a07ee3d9d385e.

Closing.

wrljet commented 5 months ago

Here's a bunch I just ran into, on Debian 12, with gcc 12.2.0.

Using commit: https://github.com/SDL-Hercules-390/hyperion/commit/140a0cf89cff61e91b7bd9b1de5850b6c1ea9cd1

 CC       dat.lo
In file included from ../hercules.h:104,
                 from ../cpu.c:43:
../cpu.c: In function ‘s370_process_interrupt’:
../cpu.c:1876:29: warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 9 has type ‘char *’ [-Wformat=]
 1876 |                     "auto-" );
      |                     ~~~~~~~ ^
      |                     |
      |                     char *
../msgenu.h:99:98: note: in definition of macro ‘PFWRITEMSG’
   99 | #define PFWRITEMSG( pan, f, fmt, ... ) fwritemsg( __FILE__, __LINE__, __FUNCTION__, pan,   f,    fmt, ## __VA_ARGS__ )
      |                                                                                                  ^~~
../msgenu.h:108:36: note: in expansion of macro ‘PWRITEMSG’
  108 | #define  LOGMSG(      fmt,   ... ) PWRITEMSG(  WRMSG_NORMAL,       fmt,                 ## __VA_ARGS__ )
      |                                    ^~~~~~~~~
../msgenu.h:110:36: note: in expansion of macro ‘LOGMSG’
  110 | #define  WRMSG(     id, sev, ... ) LOGMSG(                      #id "%s " id "\n", sev, ## __VA_ARGS__ )
      |                                    ^~~~~~
../cpu.c:1875:17: note: in expansion of macro ‘WRMSG’
 1875 |                 WRMSG( HHC00826, "W", PTYPSTR( sysblk.pcpu ),
      |                 ^~~~~
../cpu.c:1876:29: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
 1876 |                     "auto-" );
      |                             ^
../msgenu.h:99:98: note: in definition of macro ‘PFWRITEMSG’
   99 | #define PFWRITEMSG( pan, f, fmt, ... ) fwritemsg( __FILE__, __LINE__, __FUNCTION__, pan,   f,    fmt, ## __VA_ARGS__ )
      |                                                                                                  ^~~
../msgenu.h:108:36: note: in expansion of macro ‘PWRITEMSG’
  108 | #define  LOGMSG(      fmt,   ... ) PWRITEMSG(  WRMSG_NORMAL,       fmt,                 ## __VA_ARGS__ )
      |                                    ^~~~~~~~~
../msgenu.h:110:36: note: in expansion of macro ‘LOGMSG’
  110 | #define  WRMSG(     id, sev, ... ) LOGMSG(                      #id "%s " id "\n", sev, ## __VA_ARGS__ )
      |                                    ^~~~~~
../cpu.c:1875:17: note: in expansion of macro ‘WRMSG’
 1875 |                 WRMSG( HHC00826, "W", PTYPSTR( sysblk.pcpu ),
      |                 ^~~~~
../cpu.c: In function ‘s390_process_interrupt’:
../cpu.c:1876:29: warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 9 has type ‘char *’ [-Wformat=]
 1876 |                     "auto-" );
      |                     ~~~~~~~ ^
      |                     |
      |                     char *
../msgenu.h:99:98: note: in definition of macro ‘PFWRITEMSG’
   99 | #define PFWRITEMSG( pan, f, fmt, ... ) fwritemsg( __FILE__, __LINE__, __FUNCTION__, pan,   f,    fmt, ## __VA_ARGS__ )
      |                                                                                                  ^~~
../msgenu.h:108:36: note: in expansion of macro ‘PWRITEMSG’
  108 | #define  LOGMSG(      fmt,   ... ) PWRITEMSG(  WRMSG_NORMAL,       fmt,                 ## __VA_ARGS__ )
      |                                    ^~~~~~~~~
../msgenu.h:110:36: note: in expansion of macro ‘LOGMSG’
  110 | #define  WRMSG(     id, sev, ... ) LOGMSG(                      #id "%s " id "\n", sev, ## __VA_ARGS__ )
      |                                    ^~~~~~
../cpu.c:1875:17: note: in expansion of macro ‘WRMSG’
 1875 |                 WRMSG( HHC00826, "W", PTYPSTR( sysblk.pcpu ),
      |                 ^~~~~
../cpu.c:1876:29: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
 1876 |                     "auto-" );
      |                             ^
../msgenu.h:99:98: note: in definition of macro ‘PFWRITEMSG’
   99 | #define PFWRITEMSG( pan, f, fmt, ... ) fwritemsg( __FILE__, __LINE__, __FUNCTION__, pan,   f,    fmt, ## __VA_ARGS__ )
      |                                                                                                  ^~~
../msgenu.h:108:36: note: in expansion of macro ‘PWRITEMSG’
  108 | #define  LOGMSG(      fmt,   ... ) PWRITEMSG(  WRMSG_NORMAL,       fmt,                 ## __VA_ARGS__ )
      |                                    ^~~~~~~~~
../msgenu.h:110:36: note: in expansion of macro ‘LOGMSG’
  110 | #define  WRMSG(     id, sev, ... ) LOGMSG(                      #id "%s " id "\n", sev, ## __VA_ARGS__ )
      |                                    ^~~~~~
../cpu.c:1875:17: note: in expansion of macro ‘WRMSG’
 1875 |                 WRMSG( HHC00826, "W", PTYPSTR( sysblk.pcpu ),
      |                 ^~~~~
../cpu.c: In function ‘z900_process_interrupt’:
../cpu.c:1876:29: warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 9 has type ‘char *’ [-Wformat=]
 1876 |                     "auto-" );
      |                     ~~~~~~~ ^
      |                     |
      |                     char *
../msgenu.h:99:98: note: in definition of macro ‘PFWRITEMSG’
   99 | #define PFWRITEMSG( pan, f, fmt, ... ) fwritemsg( __FILE__, __LINE__, __FUNCTION__, pan,   f,    fmt, ## __VA_ARGS__ )
      |                                                                                                  ^~~
../msgenu.h:108:36: note: in expansion of macro ‘PWRITEMSG’
  108 | #define  LOGMSG(      fmt,   ... ) PWRITEMSG(  WRMSG_NORMAL,       fmt,                 ## __VA_ARGS__ )
      |                                    ^~~~~~~~~
../msgenu.h:110:36: note: in expansion of macro ‘LOGMSG’
  110 | #define  WRMSG(     id, sev, ... ) LOGMSG(                      #id "%s " id "\n", sev, ## __VA_ARGS__ )
      |                                    ^~~~~~
../cpu.c:1875:17: note: in expansion of macro ‘WRMSG’
 1875 |                 WRMSG( HHC00826, "W", PTYPSTR( sysblk.pcpu ),
      |                 ^~~~~
../cpu.c:1876:29: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
 1876 |                     "auto-" );
      |                             ^
../msgenu.h:99:98: note: in definition of macro ‘PFWRITEMSG’
   99 | #define PFWRITEMSG( pan, f, fmt, ... ) fwritemsg( __FILE__, __LINE__, __FUNCTION__, pan,   f,    fmt, ## __VA_ARGS__ )
      |                                                                                                  ^~~
../msgenu.h:108:36: note: in expansion of macro ‘PWRITEMSG’
  108 | #define  LOGMSG(      fmt,   ... ) PWRITEMSG(  WRMSG_NORMAL,       fmt,                 ## __VA_ARGS__ )
      |                                    ^~~~~~~~~
../msgenu.h:110:36: note: in expansion of macro ‘LOGMSG’
  110 | #define  WRMSG(     id, sev, ... ) LOGMSG(                      #id "%s " id "\n", sev, ## __VA_ARGS__ )
      |                                    ^~~~~~
../cpu.c:1875:17: note: in expansion of macro ‘WRMSG’
 1875 |                 WRMSG( HHC00826, "W", PTYPSTR( sysblk.pcpu ),
      |                 ^~~~~
Fish-Git commented 5 months ago

Fix(es) committed. Please try again.

wrljet commented 5 months ago

Fish,

That worked! Good work!

The only one I see now on that system is this (which I think we've seen before):

  CC       ckddasd.lo
../ckddasd.c: In function ‘PerformSubsystemFunction.constprop’:
../ckddasd.c:6016:9: warning: ‘orig_iobuf’ may be used uninitialized [-Wmaybe-uninitialized]
 6016 |         memmove( &orig_iobuf[0], &iobuf[0], dev->ckdssdlen );
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../ckddasd.c:5661:12: note: ‘orig_iobuf’ was declared here
 5661 |     BYTE*  orig_iobuf;
      |            ^~~~~~~~~~

Bill

Fish-Git commented 5 months ago

The only one I see now on that system is this (which I think we've seen before):

That's supposed to have been fixed by commit 873c8ba587be8404dd47cae0604a07ee3d9d385e!  (And yes, I tested it. Both before the fix and again afterwards.)

What version of gcc are you using? Because as committed, the above fix (workaround) should apply to any gcc version > 11. Maybe we need to change it to some earlier version?

wrljet commented 5 months ago

gcc 12.2

The diff for the commit you've mentioned shows some lines that to me look unchanged, for what it's worth.

Fish-Git commented 5 months ago

The diff for the commit you've mentioned shows some lines that to me look unchanged, for what it's worth.

Really? Because that commit SHOULD show that for gcc >= 11.0.0, the "-Wmaybe-uninitialized" warning is being disabled:

wrljet commented 5 months ago

Fish,

The warning is for lines outside the range being protected.

You're guarding lines 6755 - 6999, and the warnings are at 5661 and 6016..

  CC       ckddasd.lo
../ckddasd.c: In function ‘PerformSubsystemFunction.constprop’:
../ckddasd.c:6016:9: warning: ‘orig_iobuf’ may be used uninitialized [-Wmaybe-uninitialized]
 6016 |         memmove( &orig_iobuf[0], &iobuf[0], dev->ckdssdlen );
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../ckddasd.c:5661:12: note: ‘orig_iobuf’ was declared here
 5661 |     BYTE*  orig_iobuf;
      |            ^~~~~~~~~~
Fish-Git commented 5 months ago

You're guarding lines 6755 - 6999, and the warnings are at 5661 and 6016..

(Oops!) I missed that the first time. Sorry. I'll get that fixed right away. It's the same fix, I just need to wrap it around the PerformSubsystemFunction too. Give me a minute.

Fish-Git commented 5 months ago

Should be fixed now by commit 23c8c460aae3677e82ba43ceff79dc0961eac657.

wrljet commented 5 months ago

Should be fixed now by commit 23c8c46.

Verified -- fixed now.