summaryrefslogtreecommitdiff
path: root/aclocal.m4
diff options
context:
space:
mode:
authorDenis Ovsienko <denis@ovsienko.info>2017-07-21 22:04:15 +0100
committerDenis Ovsienko <denis@ovsienko.info>2017-07-22 19:33:49 +0100
commit6df678ca315946ed6190bc8fe0a80f3c36d246c4 (patch)
treebf24ecf12b3f7a8c9255f229ba956ccc0554f854 /aclocal.m4
parent11fcafcf6928d793411ae3dba9af324e3d027bb2 (diff)
downloadtcpdump-6df678ca315946ed6190bc8fe0a80f3c36d246c4.tar.gz
Check for __attribute__ ((fallthrough)) (GCC 7).
The documentation claims that recent GCC is now better by default at spotting cases of code flow falling through (which is true) and that it avoids false positives by matching nearby source code comments with regexps. However, the latter feature doesn't seem to work as reliably as the manual describes it, so let's have a macro for this purpose. Tested to work on: * x86_64, Fedora 26, GCC 7.1.1 (w/__attribute__, w/fallthrough) * x86_64, Ubuntu 16.04, GCC 5.4.0 (w/__attribute__, w/o fallthrough) * x86_64, FreeBSD 11.0, CLang 3.8.0 (w/__attribute__, w/o fallthrough) * SPARC, Solaris 10, SolStudio 12.4 (w/__attribute__, w/o fallthrough) * SPARC, Solaris 10, SunStudio 11 (w/o __attribute__)
Diffstat (limited to 'aclocal.m4')
-rw-r--r--aclocal.m441
1 files changed, 41 insertions, 0 deletions
diff --git a/aclocal.m4 b/aclocal.m4
index 637054fd..cfd59afd 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1323,6 +1323,47 @@ fi
AC_MSG_RESULT($ac_cv___attribute___noreturn_function_pointer)
])
+dnl
+dnl Test whether __attribute__((fallthrough)) can be used without warnings
+dnl
+
+AC_DEFUN(AC_C___ATTRIBUTE___FALLTHROUGH, [
+AC_MSG_CHECKING([whether __attribute__((fallthrough)) can be used without warnings])
+AC_CACHE_VAL(ac_cv___attribute___fallthrough, [
+save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
+AC_COMPILE_IFELSE([
+ AC_LANG_SOURCE([[
+#include <stdio.h>
+
+int
+main(int argc, char **argv)
+{
+ int x = 1;
+ switch (x)
+ {
+ case 1:
+ printf ("x == %d\n", x);
+ __attribute__ ((fallthrough));
+ case 2:
+ printf ("x == %d\n", x);
+ break;
+ default:
+ return 0;
+ }
+ return x;
+}
+ ]])],
+ac_cv___attribute___fallthrough=yes,
+ac_cv___attribute___fallthrough=no)])
+CFLAGS="$save_CFLAGS"
+if test "$ac_cv___attribute___fallthrough" = "yes"; then
+ AC_DEFINE(__ATTRIBUTE___FALLTHROUGH_OK, 1,
+ [define if your compiler allows __attribute__((fallthrough)) without a warning])
+fi
+AC_MSG_RESULT($ac_cv___attribute___fallthrough)
+])
+
AC_DEFUN(AC_LBL_SSLEAY,
[
#