This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] config: Check for and use gcc -Wlogical-op and -Wduplicated-cond.


Both -Wlogical-op and -Wduplicated-cond may produce useful warnings.
But we have to check them first. Older versions of gcc had a -Wlogical-op
that warned on some constructs using macros that are not erronious.
Only GCC6 has -Wduplicated-cond.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 ChangeLog        |  5 +++++
 config/ChangeLog |  6 ++++++
 config/eu.am     | 16 +++++++++++++++-
 configure.ac     | 22 ++++++++++++++++++++++
 4 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 637bc13..d206a8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-98  Mark Wielaard  <mjw@redhat.com>
+
+	* configure.ac: Add checks for sane -Wlogical-op and whether gcc
+	accepts -Wduplicated-cond.
+
 2016-01-08  Mark Wielaard  <mjw@redhat.com>
 
 	* configure.ac: Set version to 0.165.
diff --git a/config/ChangeLog b/config/ChangeLog
index 8e20f1e..8523cb3 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-09  Mark Wielaard  <mjw@redhat.com>
+
+	* eu.am: Check SANE_LOGICAL_OP_WARNING and
+	HAVE_DUPLICATED_COND_WARNING.
+	(AM_CFLAGS): Add LOGICAL_OP_WARNING and DUPLICATED_COND_WARNING.
+
 2016-01-08  Mark Wielaard  <mjw@redhat.com>
 
 	* elfutils.spec.in: Add elfcompress. Update for 0.165.
diff --git a/config/eu.am b/config/eu.am
index 0095da5..c4e9279 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -1,6 +1,6 @@
 ## Common automake fragments for elfutils subdirectory makefiles.
 ##
-## Copyright (C) 2010, 2014 Red Hat, Inc.
+## Copyright (C) 2010, 2014, 2016 Red Hat, Inc.
 ##
 ## This file is part of elfutils.
 ##
@@ -42,8 +42,22 @@ STACK_USAGE_WARNING=-Wstack-usage=262144
 else
 STACK_USAGE_WARNING=
 endif
+
+if SANE_LOGICAL_OP_WARNING
+LOGICAL_OP_WARNING=-Wlogical-op
+else
+LOGICAL_OP_WARNING=
+endif
+
+if HAVE_DUPLICATED_COND_WARNING
+DUPLICATED_COND_WARNING=-Wduplicated-cond
+else
+DUPLICATED_COND_WARNING=
+endif
+
 AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
 	    -Wold-style-definition -Wstrict-prototypes \
+	    $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
 	    $(if $($(*F)_no_Werror),,-Werror) \
 	    $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
 	    $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
diff --git a/configure.ac b/configure.ac
index 9a3301f..d447db7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -291,6 +291,28 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
 CFLAGS="$old_CFLAGS"])
 AM_CONDITIONAL(ADD_STACK_USAGE_WARNING, [test "x$ac_cv_stack_usage" != "xno"])
 
+# -Wlogical-op was too fragile in the past, make sure we get a sane one.
+AC_CACHE_CHECK([whether gcc has a sane -Wlogical-op], ac_cv_logical_op, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wlogical-op -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+	[#define FLAG 1
+	int f (int r, int f) { return (r && (FLAG || (FLAG & f))); }])],
+		  ac_cv_logical_op=yes, ac_cv_logical_op=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(SANE_LOGICAL_OP_WARNING,
+	       [test "x$ac_cv_logical_op" != "xno"])
+
+# -Wduplicated-cond was added by GCC6
+AC_CACHE_CHECK([whether gcc accepts -Wduplicated-cond], ac_cv_duplicated_cond, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wduplicated-cond"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+		  ac_cv_duplicated_cond=yes, ac_cv_duplicated_cond=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_DUPLICATED_COND_WARNING,
+	       [test "x$ac_cv_duplicated_cond" != "xno"])
+
 dnl Check if we have argp available from our libc
 AC_LINK_IFELSE(
 	[AC_LANG_PROGRAM(
-- 
1.8.3.1

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]