]> git.eshelyaron.com Git - emacs.git/commitdiff
Suppress some unhelpful warnings when using clang.
authorJan Djärv <jan.h.d@swipnet.se>
Mon, 23 Sep 2013 07:12:01 +0000 (09:12 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Mon, 23 Sep 2013 07:12:01 +0000 (09:12 +0200)
* configure.ac: With clang, check for and use -Wno-switch,
-Wno-tautological-constant-out-of-range-compare and -Wno-pointer-sign.

* conf_post.h(assume): Use __builtin_unreachable for clang.

* src/filelock.c (lock_file_1): Rearrange to remove compiler warning
about excess arguments to snprintf.

ChangeLog
configure.ac
src/ChangeLog
src/conf_post.h
src/filelock.c

index 67f3f926b9c66b2ec3b5d5afdd2cc2ec6c34050b..d2a27b7b6ee4c1d3b44b667607e3258b1a4357a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-09-23  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * configure.ac: With clang, check for and use -Wno-switch,
+       -Wno-tautological-constant-out-of-range-compare and -Wno-pointer-sign.
+
 2013-09-23  Daniel Colascione  <dancol@dancol.org>
 
        * configure.ac: Check for valgrind headers.
index c63627d18d484608231ef8b7e4e5b0143d503908..16259f01ed27b2fe6b760353e5d81555fcf65ab3 100644 (file)
@@ -787,10 +787,28 @@ AC_DEFUN([gl_GCC_VERSION_IFELSE],
   ]
 )
 
+# clang is unduly picky about some things.
+AC_CACHE_CHECK([whether the compiler is clang], [emacs_cv_clang],
+  [AC_COMPILE_IFELSE(
+     [AC_LANG_PROGRAM([[
+         #ifndef __clang__
+           #error "not clang"
+         #endif
+        ]])],
+     [emacs_cv_clang=yes],
+     [emacs_cv_clang=no])])
+
 # When compiling with GCC, prefer -isystem to -I when including system
 # include files, to avoid generating useless diagnostics for the files.
 if test "$gl_gcc_warnings" != yes; then
   isystem='-I'
+  if test "$emacs_cv_clang" = yes
+  then
+     # Turn off some warnings if supported.
+     gl_WARN_ADD([-Wno-switch])
+     gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
+     gl_WARN_ADD([-Wno-pointer-sign])
+  fi
 else
   isystem='-isystem '
 
@@ -840,16 +858,6 @@ else
   nw="$nw -Wtype-limits"
   nw="$nw -Wunused-parameter"
 
-  # clang is unduly picky about some things.
-  AC_CACHE_CHECK([whether the compiler is clang], [emacs_cv_clang],
-    [AC_COMPILE_IFELSE(
-       [AC_LANG_PROGRAM([[
-           #ifndef __clang__
-             #error "not clang"
-           #endif
-          ]])],
-       [emacs_cv_clang=yes],
-       [emacs_cv_clang=no])])
   if test $emacs_cv_clang = yes; then
     nw="$nw -Wcast-align"
   fi
index 668ebeb8537f2cd073fe588a56783a803f06d6fc..29cd86765844d1e7233544dbfa31dbb8d09a125a 100644 (file)
@@ -1,3 +1,10 @@
+2013-09-23  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * filelock.c (lock_file_1): Rearrange to remove compiler warning
+       about excess arguments to snprintf.
+
+       * conf_post.h(assume): Use __builtin_unreachable for clang.
+
 2013-09-23  Juanma Barranquero  <lekktu@gmail.com>
 
        * w32console.c (initialize_w32_display): Remove unused variable hlinfo.
index 14af38ce70ba0de001c206fb079df6fa6944b079..7d4e1f43ed7b31d37b8fa3a7c39077c33f696e16 100644 (file)
@@ -248,12 +248,20 @@ extern void _DebPrint (const char *fmt, ...);
 # define FLEXIBLE_ARRAY_MEMBER 1
 #endif
 
+#ifdef __clang__
+# ifndef __has_builtin
+#  define __has_builtin(x) 0
+# endif
+#endif
+
 /* assume(cond) tells the compiler (and lint) that a certain condition
  * will always hold, and that it should optimize (or check) accordingly. */
 #if defined lint
 # define assume(cond) ((cond) ? (void) 0 : abort ())
 #elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || __GNUC__ > 4
 # define assume(cond) ((cond) || (__builtin_unreachable(), 0))
+#elif defined (__clang__) && __has_builtin (__builtin_unreachable)
+# define assume(cond) ((cond) || (__builtin_unreachable(), 0))
 #elif defined __MSC_VER
 # define assume(cond) __assume ((cond))
 #else
index df72eff5950e6f11ec477c809199fb1a63b77f7a..2f53047f52615dd704a6fa134b855c86444f1c8c 100644 (file)
@@ -459,10 +459,18 @@ lock_file_1 (char *lfname, bool force)
   char lock_info_str[MAX_LFINFO + 1];
   printmax_t pid = getpid ();
 
-  if (sizeof lock_info_str
-      <= snprintf (lock_info_str, sizeof lock_info_str,
-                  boot ? "%s@%s.%"pMd":%"pMd : "%s@%s.%"pMd,
-                  user_name, host_name, pid, boot))
+  if (boot)
+    {
+      if (sizeof lock_info_str
+          <= snprintf (lock_info_str, sizeof lock_info_str,
+                       "%s@%s.%"pMd":%"pMd,
+                       user_name, host_name, pid, boot))
+        return ENAMETOOLONG;
+    }
+  else if (sizeof lock_info_str
+           <= snprintf (lock_info_str, sizeof lock_info_str,
+                        "%s@%s.%"pMd,
+                        user_name, host_name, pid))
     return ENAMETOOLONG;
 
   return create_lock_file (lfname, lock_info_str, force);