From 8762e52438d46d81e518179e4f9bd8a939463ddb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Mon, 23 Sep 2013 09:12:01 +0200 Subject: [PATCH] Suppress some unhelpful warnings when using clang. * 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 | 5 +++++ configure.ac | 28 ++++++++++++++++++---------- src/ChangeLog | 7 +++++++ src/conf_post.h | 8 ++++++++ src/filelock.c | 16 ++++++++++++---- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 67f3f926b9c..d2a27b7b6ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-09-23 Jan Djärv + + * 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 * configure.ac: Check for valgrind headers. diff --git a/configure.ac b/configure.ac index c63627d18d4..16259f01ed2 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/ChangeLog b/src/ChangeLog index 668ebeb8537..29cd8676584 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2013-09-23 Jan Djärv + + * 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 * w32console.c (initialize_w32_display): Remove unused variable hlinfo. diff --git a/src/conf_post.h b/src/conf_post.h index 14af38ce70b..7d4e1f43ed7 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -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 diff --git a/src/filelock.c b/src/filelock.c index df72eff5950..2f53047f526 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -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); -- 2.39.2