[tz] [PROPOSED 4/4] Document GCC bug 114833 and workaround

Paul Eggert eggert at cs.ucla.edu
Mon May 27 02:16:31 UTC 2024


Document better how we work around GCC bug 114833,
a false-positive compiler diagnostic, when debugging.
* private.h (ATTRIBUTE_PURE_114833): New macro.
* localtime.c (getzname, getqzname):
* zdump.c (yeartot, sumsize), zic.c (size_sum, size_product, align_to)
(same_parent_dirs, ciequal, itsabbr, ciprefix, oadd, tadd):
Now ATTRIBUTE_PURE_114833, not ATTRIBUTE_PURE.
* zdump.c (xstrsize): No longer needs ATTRIBUTE_PURE.
---
 localtime.c |  4 ++--
 private.h   |  9 +++++++++
 zdump.c     |  6 +++---
 zic.c       | 18 +++++++++---------
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/localtime.c b/localtime.c
index 52d5ee01..c9f0d1a8 100644
--- a/localtime.c
+++ b/localtime.c
@@ -750,7 +750,7 @@ is_digit(char c)
 ** Return a pointer to that character.
 */
 
-ATTRIBUTE_PURE static const char *
+ATTRIBUTE_PURE_114833 static const char *
 getzname(register const char *strp)
 {
 	register char	c;
@@ -771,7 +771,7 @@ getzname(register const char *strp)
 ** We don't do any checking here; checking is done later in common-case code.
 */
 
-ATTRIBUTE_PURE static const char *
+ATTRIBUTE_PURE_114833 static const char *
 getqzname(register const char *strp, const int delim)
 {
 	register int	c;
diff --git a/private.h b/private.h
index cf2370c8..cacbe444 100644
--- a/private.h
+++ b/private.h
@@ -562,6 +562,15 @@ typedef unsigned long uintmax_t;
 # define ATTRIBUTE_PURE __attribute__((pure))
 #endif
 
+/* Avoid GCC bug 114833 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114833>.
+   Remove this macro and its uses when the bug is fixed in a GCC release,
+   because only the latest GCC matters for $(GCC_DEBUG_FLAGS).  */
+#ifdef GCC_LINT
+# define ATTRIBUTE_PURE_114833 ATTRIBUTE_PURE
+#else
+# define ATTRIBUTE_PURE_114833 /* empty */
+#endif
+
 #if (__STDC_VERSION__ < 199901 && !defined restrict \
      && (PORT_TO_C89 || defined _MSC_VER))
 # define restrict /* empty */
diff --git a/zdump.c b/zdump.c
index 86aceb45..e8178733 100644
--- a/zdump.c
+++ b/zdump.c
@@ -97,7 +97,7 @@ static void showextrema(timezone_t, char *, time_t, struct tm *, time_t);
 static void showtrans(char const *, struct tm const *, time_t, char const *,
 		      char const *);
 static const char *tformat(void);
-ATTRIBUTE_PURE static time_t yeartot(intmax_t);
+ATTRIBUTE_PURE_114833 static time_t yeartot(intmax_t);
 
 /* Is C an ASCII digit?  */
 static bool
@@ -134,7 +134,7 @@ size_overflow(void)
 
 /* Return A + B, exiting if the result would overflow either ptrdiff_t
    or size_t.  A and B are both nonnegative.  */
-ATTRIBUTE_PURE static ptrdiff_t
+ATTRIBUTE_PURE_114833 static ptrdiff_t
 sumsize(ptrdiff_t a, ptrdiff_t b)
 {
 #ifdef ckd_add
@@ -151,7 +151,7 @@ sumsize(ptrdiff_t a, ptrdiff_t b)
 /* Return the size of of the string STR, including its trailing NUL.
    Report an error and exit if this would exceed INDEX_MAX which means
    pointer subtraction wouldn't work.  */
-ATTRIBUTE_PURE static ptrdiff_t
+static ptrdiff_t
 xstrsize(char const *str)
 {
   size_t len = strlen(str);
diff --git a/zic.c b/zic.c
index 19a0b953..8d40fe3c 100644
--- a/zic.c
+++ b/zic.c
@@ -470,7 +470,7 @@ size_overflow(void)
   memory_exhausted(_("size overflow"));
 }
 
-ATTRIBUTE_PURE static ptrdiff_t
+ATTRIBUTE_PURE_114833 static ptrdiff_t
 size_sum(size_t a, size_t b)
 {
 #ifdef ckd_add
@@ -484,7 +484,7 @@ size_sum(size_t a, size_t b)
   size_overflow();
 }
 
-ATTRIBUTE_PURE static ptrdiff_t
+ATTRIBUTE_PURE_114833 static ptrdiff_t
 size_product(ptrdiff_t nitems, ptrdiff_t itemsize)
 {
 #ifdef ckd_mul
@@ -499,7 +499,7 @@ size_product(ptrdiff_t nitems, ptrdiff_t itemsize)
   size_overflow();
 }
 
-ATTRIBUTE_PURE static ptrdiff_t
+ATTRIBUTE_PURE_114833 static ptrdiff_t
 align_to(ptrdiff_t size, ptrdiff_t alignment)
 {
   ptrdiff_t lo_bits = alignment - 1, sum = size_sum(size, lo_bits);
@@ -1435,7 +1435,7 @@ relname(char const *target, char const *linkname)
 /* Return true if A and B must have the same parent dir if A and B exist.
    Return false if this is not necessarily true (though it might be true).
    Keep it simple, and do not inspect the file system.  */
-ATTRIBUTE_PURE static bool
+ATTRIBUTE_PURE_114833 static bool
 same_parent_dirs(char const *a, char const *b)
 {
   for (; *a == *b; a++, b++)
@@ -3627,7 +3627,7 @@ lowerit(char a)
 }
 
 /* case-insensitive equality */
-ATTRIBUTE_PURE static bool
+ATTRIBUTE_PURE_114833 static bool
 ciequal(register const char *ap, register const char *bp)
 {
 	while (lowerit(*ap) == lowerit(*bp++))
@@ -3636,7 +3636,7 @@ ciequal(register const char *ap, register const char *bp)
 	return false;
 }
 
-ATTRIBUTE_PURE static bool
+ATTRIBUTE_PURE_114833 static bool
 itsabbr(register const char *abbr, register const char *word)
 {
 	if (lowerit(*abbr) != lowerit(*word))
@@ -3652,7 +3652,7 @@ itsabbr(register const char *abbr, register const char *word)
 
 /* Return true if ABBR is an initial prefix of WORD, ignoring ASCII case.  */
 
-ATTRIBUTE_PURE static bool
+ATTRIBUTE_PURE_114833 static bool
 ciprefix(char const *abbr, char const *word)
 {
   do
@@ -3762,7 +3762,7 @@ time_overflow(void)
   exit(EXIT_FAILURE);
 }
 
-ATTRIBUTE_PURE static zic_t
+ATTRIBUTE_PURE_114833 static zic_t
 oadd(zic_t t1, zic_t t2)
 {
 #ifdef ckd_add
@@ -3776,7 +3776,7 @@ oadd(zic_t t1, zic_t t2)
   time_overflow();
 }
 
-ATTRIBUTE_PURE static zic_t
+ATTRIBUTE_PURE_114833 static zic_t
 tadd(zic_t t1, zic_t t2)
 {
 #ifdef ckd_add
-- 
2.43.0



More information about the tz mailing list