dosemu2 / comcom64

64bit command.com
https://github.com/dosemu2/comcom32/
GNU General Public License v3.0
32 stars 5 forks source link

Warning during build with i586-pc-msdosdjgpp-gcc (GCC) 12.2.0 #65

Closed andrewbird closed 8 months ago

andrewbird commented 2 years ago
i586-pc-msdosdjgpp-gcc -Wall -O2 -finline-functions -Wmissing-declarations -Wwrite-strings -march=i386  -c command.c -o command.o
command.c: In function 'perform_shift':
command.c:3416:5: warning: 'strcpy' accessing 1 byte at offsets [0, 327680] and [0, 327680] overlaps 1 byte at offset [0, 327679] [-Wrestrict]
 3416 |     strcpy(bat_arg[stack_level][i], bat_arg[stack_level][i + 1]);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stsp commented 2 years ago

I think this is a gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102919 We may also ask @jwt27 if maybe he knows whether the fix from the url above is included or not into the current bundle.

jwt27 commented 2 years ago

That patch is present in 12.2. But I don't think it's the same issue. I can also replicate it with native gcc 12.2 using -m32.

stsp commented 2 years ago

Thanks, so if you already made a native test-case, then maybe you are the one to fill in the upstream report? :)

jwt27 commented 2 years ago

You can use the following:

$ cat test.c
#include <string.h>

extern char bat_arg[20][32][512];
extern int stack_level;

void perform_shift()
  {
  int i;
  for (i = 0; i < 32 - 1; i++)
    {
    strcpy(bat_arg[stack_level][i], bat_arg[stack_level][i + 1]);
    if (!bat_arg[stack_level][i + 1][0])
      break;
    }
  }

$ gcc -Wrestrict -m32 -O3 -c test.c
test.c: In function ‘perform_shift’:
test.c:11:5: warning: ‘strcpy’ accessing 1 byte at offsets [0, 327680] and [0, 327680] overlaps 1 byte at offset [0, 327679] [-Wrestrict]
   11 |     strcpy(bat_arg[stack_level][i], bat_arg[stack_level][i + 1]);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Without -m32 the warning also triggers, but only at -O1.

stsp commented 2 years ago

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107477

stsp commented 8 months ago

Resolved on our side. Whoever wants to track the upstream ticket, should subscribe to the aforementioned gcc bugzilla ticket.