unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Philipp Stephani <phst@google.com>
Cc: Emacs development discussions <emacs-devel@gnu.org>
Subject: Re: Silence two Clang warnings
Date: Tue, 13 Jun 2017 13:42:09 -0700	[thread overview]
Message-ID: <1e61fe6d-4646-b2ea-9dc1-7b782fc91e05@cs.ucla.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 738 bytes --]

Part of the attached patch, recently installed into master, would be 
automatically reverted the next time we merged from gnulib, since 
strftime.c is copied from Gnulib. I'm not getting a warning when 
compiling with Clang, so I'm puzzled as to why the patch was needed. 
Here's how I build (on Fedora 25):

./configure --enable-gcc-warnings CC=clang

Fedora 25 is running clang version 3.9.1 (tags/RELEASE_391/final).

Background: I would rather avoid the need for this sort of patch, as we 
shouldn't have to complicate the code just to pacify a Clang false 
alarm. If an older Clang is generating a false alarm, let's just ignore 
the diagnostic. If it's a newer Clang, let's change the options to Clang 
to suppress the diagnostic.


[-- Attachment #2: 0001-Silence-two-Clang-warnings-by-introducing-additional.patch --]
[-- Type: text/x-patch, Size: 2298 bytes --]

From e408e9aa030a00cb1a61acdc729e8d6786b25fe3 Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Tue, 13 Jun 2017 13:55:44 +0200
Subject: [PATCH] Silence two Clang warnings by introducing additional local
 variables

* lib/strftime.c (libc_hidden_def):
* lib-src/make-docfile.c (put_filename): Introduce local variables to
silence Clang warnings.
---
 lib-src/make-docfile.c |  6 +++++-
 lib/strftime.c         | 27 ++++++++++++++++-----------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index 9470bd6..85bcc8b 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -224,7 +224,11 @@ put_filename (char *filename)
 
   for (tmp = filename; *tmp; tmp++)
     {
-      if (IS_DIRECTORY_SEP (*tmp))
+      /* Use separate variable to silence a Clang warning on macOS.
+         Clang takes offence of the additional set of parantheses
+         generated by the macro.  */
+      bool is_sep = IS_DIRECTORY_SEP (*tmp);
+      if (is_sep)
 	filename = tmp + 1;
     }
 
diff --git a/lib/strftime.c b/lib/strftime.c
index 99bee4e..18c899d 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1123,18 +1123,23 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
           if (modifier == L_('E'))
             goto bad_format;
 
-          number_value = ns;
-          if (width == -1)
-            width = 9;
-          else
-            {
-              /* Take an explicit width less than 9 as a precision.  */
-              int j;
-              for (j = width; j < 9; j++)
-                number_value /= 10;
-            }
+          {
+            /* Use a new variable here instead of reusing number_value
+               because Clang complains about the self-assignment
+               generated by DO_NUMBER.  */
+            ptrdiff_t n = ns;
+            if (width == -1)
+              width = 9;
+            else
+              {
+                /* Take an explicit width less than 9 as a precision.  */
+                int j;
+                for (j = width; j < 9; j++)
+                  n /= 10;
+              }
 
-          DO_NUMBER (width, number_value);
+            DO_NUMBER (width, n);
+          }
 #endif
 
         case L_('n'):
-- 
2.9.4


             reply	other threads:[~2017-06-13 20:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-13 20:42 Paul Eggert [this message]
2017-06-15 13:11 ` Silence two Clang warnings Philipp Stephani
2017-06-15 18:56   ` Paul Eggert
2017-06-15 19:23     ` Philipp Stephani
2017-06-15 19:35       ` Paul Eggert
2017-06-16 16:53         ` Philipp Stephani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1e61fe6d-4646-b2ea-9dc1-7b782fc91e05@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=phst@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).