Subject: bug#77828: closed (Re: bug#77828: LTO build fails with grep 3.12)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 20 Apr 2025 06:42:02 +0000

Your bug report

#77828: LTO build fails with grep 3.12

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
77828: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77828
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#77828: LTO build fails with grep 3.12
From: Paul Eggert <[email-masked]>
To: Christian Hesse <[email-masked]>
Cc: [email-masked]
Date: Sat, 19 Apr 2025 23:41:17 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On 2025-04-15 10:01, Christian Hesse wrote:

> The build succeed as soon as I disable link time optimization. Would be nice
> to have a fix for this to reenable lto.

Thanks for reporting that. It's a false alarm from GCC. I worked around 
the problem by installing the attached patch into Gnulib to pacify GCC, 
and I'm closing the grep bug report.

From 60d9b4134f8661dc25134dbe54be15f6138718c8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Tue, 15 Apr 2025 13:50:32 -0700
Subject: [PATCH] dfa: pacify gcc -Wstringop-overflow

Problem reported by Christian Hesse in:
https://bugs.gnu.org/77828
* lib/dfa.c (dfaanalyze): Pacify gcc -flto -Wstringop-overflow.
---
 ChangeLog | 7 +++++++
 lib/dfa.c | 1 +
 2 files changed, 8 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 7d255be3a2..28322a2655 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-04-15  Paul Eggert  <[email-masked]>
+
+	dfa: pacify gcc -Wstringop-overflow
+	Problem reported by Christian Hesse in:
+	https://bugs.gnu.org/77828
+	* lib/dfa.c (dfaanalyze): Pacify gcc -flto -Wstringop-overflow.
+
 2025-04-15  Bruno Haible  <[email-masked]>
 
 	gnulib-tool.py: Fix exception during --update with changed macro-prefix.
diff --git a/lib/dfa.c b/lib/dfa.c
index 684043dd8f..cbacdc04cf 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2699,6 +2699,7 @@ dfaanalyze (struct dfa *d, bool searchflag)
 
   addtok (d, CAT);
   idx_t tindex = d->tindex;
+  assume (0 < tindex);
 
 #ifdef DEBUG
   fprintf (stderr, "dfaanalyze:\n");
-- 
2.48.1

Subject: LTO build fails with grep 3.12
From: Christian Hesse <[email-masked]>
To: [email-masked]
Date: Tue, 15 Apr 2025 19:01:59 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

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);}