Subject: bug#18743: 25.0.50; Clang 3.0 fails to compile src/fns.c, GCC 4.8 cannot dump emacs

From: Noam Postavsky <[email-masked]>
Date: Sun, 03 Dec 2017 14:24:22 -0500

Peter Dyballa <[email-masked]> writes:

> With Clang 3.0 I still get this error:

> Other versions of Clang build GNU Emacs.

So only 3.0 fails with this, while both earlier and later versions
succeed?

> 	fns.c:1929:16: error: read-only variable is not assignable
> 	          *dest++ = *a++;
> 	                     ~^
>

I guess the following should fix it, though I'm not sure if it's worth
doing.

>From b7e08e341c19e1d2c8b1105ea1d94979577dbd02 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Tue, 28 Nov 2017 20:54:00 -0500
Subject: [PATCH] Don't increment array (Bug#18743)

* src/fns.c (merge_vectors): Use integer indexes instead of
incrementing pointers.
---
 src/fns.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/fns.c b/src/fns.c
index 9db9bea9f7..e4ff0924b9 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1812,27 +1812,26 @@ merge_vectors (Lisp_Object pred,
 	       Lisp_Object dest[VLA_ELEMS (alen + blen)])
 {
   eassume (0 < alen && 0 < blen);
-  Lisp_Object const *alim = a + alen;
-  Lisp_Object const *blim = b + blen;
 
+  ptrdiff_t ai = 0, bi = 0, di = 0;
   while (true)
     {
-      if (inorder (pred, a[0], b[0]))
+      if (inorder (pred, a[ai], b[bi]))
 	{
-	  *dest++ = *a++;
-	  if (a == alim)
+          dest[di++] = a[ai++];
+	  if (ai >= alen)
 	    {
 	      if (dest != b)
-		memcpy (dest, b, (blim - b) * sizeof *dest);
+		memcpy (&dest[di], &b[bi], (blen - bi) * sizeof *dest);
 	      return;
 	    }
 	}
       else
 	{
-	  *dest++ = *b++;
-	  if (b == blim)
+	  dest[di++] = b[bi++];
+	  if (bi >= blen)
 	    {
-	      memcpy (dest, a, (alim - a) * sizeof *dest);
+	      memcpy (&dest[di], &a[ai], (alen - ai) * sizeof *dest);
 	      return;
 	    }
 	}
-- 
2.11.0