Subject: bug#33544: closed (Re: bug#33544: gzip 1.9 alignment compile failure on cast)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 01 Dec 2018 00:28:02 +0000

Your bug report

#33544: gzip 1.9 alignment compile failure on cast

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

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

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

Subject: Re: bug#33544: gzip 1.9 alignment compile failure on cast
From: Paul Eggert <[email-masked]>
To: "Adler, Mark" <[email-masked]>
Cc: Gnulib bugs <[email-masked]>, [email-masked]
Date: Fri, 30 Nov 2018 16:27:23 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Thanks, I installed the attached patch into Gnulib.
>From fff1ad350b7d1a10c136b0aa00cba9b0776cc2c7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 30 Nov 2018 16:25:38 -0800
Subject: [PATCH] memrchr: port better to clang

* lib/memrchr.c (__memrchr): Cast to void * instead of to
longword *, to pacify clang -Wcast-align (Bug#33544).
---
 ChangeLog     | 6 ++++++
 lib/memrchr.c | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index d0ccda7cc..85e987842 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-30  Paul Eggert  <[email-masked]>
+
+	memrchr: port better to clang
+	* lib/memrchr.c (__memrchr): Cast to void * instead of to
+	longword *, to pacify clang -Wcast-align (Bug#33544).
+
 2018-11-29  Eric Blake  <[email-masked]>
 
 	docs: mention printf %m considerations
diff --git a/lib/memrchr.c b/lib/memrchr.c
index 99acfd9c5..2efc7cb97 100644
--- a/lib/memrchr.c
+++ b/lib/memrchr.c
@@ -68,7 +68,7 @@ __memrchr (void const *s, int c_in, size_t n)
     if (*--char_ptr == c)
       return (void *) char_ptr;
 
-  longword_ptr = (const longword *) char_ptr;
+  longword_ptr = (const void *) char_ptr;
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to any size longwords.  */
-- 
2.19.2

Subject: gzip 1.9 alignment compile failure on cast
From: "Adler, Mark" <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Wed, 28 Nov 2018 19:22:56 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Compiling gzip 1.9 on macOS 10.13.6 using Xcode 10.1 with clang (Apple LLVM version 10.0.0 (clang-1000.11.45.5)), I get this error after ./configure and make:

memrchr.c:71:18: error: cast from 'const unsigned char *' to 'const longword *'
      (aka 'const unsigned long *') increases required alignment from 1 to 8
      [-Werror,-Wcast-align]
  longword_ptr = (const longword *) char_ptr;

I resolved it with this patch:

@@ -68,7 +68,7 @@ __memrchr (void const *s, int c_in, size_t n)
     if (*--char_ptr == c)
       return (void *) char_ptr;
 
-  longword_ptr = (const longword *) char_ptr;
+  longword_ptr = (const void *) char_ptr;
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to any size longwords.  */

Mark