Subject: bug#77828: LTO build fails with grep 3.12

From: Christian Hesse <[email-masked]>
Date: Tue, 15 Apr 2025 19:01:59 +0200

Hello everybody,

I am building grep 3.12 in a clean build environment for Arch Linux. That
fails when building with link time optimization is enabled:

  CCLD     grep
In function 'dfaoptimize',
    inlined from 'dfaanalyze' at ../lib/dfa.c:2873:3:
../lib/dfa.c:2606:12: error: writing 1 byte into a region of size 0
  [-Werror=stringop-overflow=] 2606 |   flags[0] |= OPT_QUEUED;
      |            ^
In function 'icalloc',
    inlined from 'xicalloc' at ../lib/xmalloc.c:304:10,
    inlined from 'xizalloc' at ../lib/xmalloc.c:289:10,
    inlined from 'dfaoptimize' at ../lib/dfa.c:2589:17,
    inlined from 'dfaanalyze' at ../lib/dfa.c:2873:3:
../lib/ialloc.h:91:10: note: destination object of size [0,
  9223372036854775807] allocated by 'calloc' 91 |   return calloc (n, s);
      |          ^
lto1: all warnings being treated as errors

The build succeed as soon as I disable link time optimization. Would be nice
to have a fix for this to reenable lto. Let me know if I can provide more
information on this. Thanks!
-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)
putchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}