On 5/9/20 6:13 PM, Paul Eggert wrote:

> perhaps it'd be better to disable -Wreturn-local-addr instead, at least for 
> this
> compilation unit.

I tried doing that, but with GCC 10.1.0 one cannot disable the warning with a
#pragma! So the GCC bug is pretty bad.

I installed the attached to try to limit the damage to programs compiled with
GCC 10.1.0 (I hope they fix it before 10.2.0 comes out).
>From 45e72160bebba64532ffc8dddf34a0882bcaa110 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 10 May 2020 17:07:47 -0700
Subject: [PATCH] careadlinkat: limit GCC workaround

* lib/careadlinkat.c (careadlinkat): Limit workaround to GCC
10.1.0 and later, since the workaround is pretty bad and the GCC
bug should get fixed.
---
 ChangeLog          | 7 +++++++
 lib/careadlinkat.c | 9 +++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6ef88249c..7468718c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-05-10  Paul Eggert  <egg...@cs.ucla.edu>
+
+	careadlinkat: limit GCC workaround
+	* lib/careadlinkat.c (careadlinkat): Limit workaround to GCC
+	10.1.0 and later, since the workaround is pretty bad and the GCC
+	bug should get fixed.
+
 2020-05-10  Bruno Haible  <br...@clisp.org>
 
 	havelib: Enhance documentation.
diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c
index e1f8305e9..fbed634f9 100644
--- a/lib/careadlinkat.c
+++ b/lib/careadlinkat.c
@@ -71,9 +71,14 @@ careadlinkat (int fd, char const *filename,
   size_t buf_size_max =
     SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
 
-#if defined GCC_LINT || defined lint
+#if (defined GCC_LINT || defined lint) && _GL_GNUC_PREREQ (10, 1)
   /* Pacify preadlinkat without creating a pointer to the stack
-     that gcc -Wreturn-local-addr would cry wolf about.  */
+     that a broken gcc -Wreturn-local-addr would cry wolf about.  See:
+     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95044
+     This workaround differs substantially from the mainline code, but
+     no other way to pacify GCC 10.1.0 is known; even an explicit
+     #pragma does not pacify GCC.  When the GCC bug is fixed this
+     workaround should be limited to the broken GCC versions.  */
   static char initial_buf[1];
   enum { initial_buf_size = 0 }; /* 0 so that initial_buf never changes.  */
 #else
-- 
2.17.1

Reply via email to