summaryrefslogtreecommitdiff
path: root/configure
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 /configure
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 'configure')
-rwxr-xr-xconfigure51
1 files changed, 51 insertions, 0 deletions
diff --git a/configure b/configure
index 3eba815e..a369590d 100755
--- a/configure
+++ b/configure
@@ -3794,6 +3794,57 @@ fi
$as_echo "$ac_cv___attribute___format_function_pointer" >&6; }
fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether __attribute__((fallthrough)) can be used without warnings" >&5
+$as_echo_n "checking whether __attribute__((fallthrough)) can be used without warnings... " >&6; }
+if ${ac_cv___attribute___fallthrough+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+
+save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+
+#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;
+}
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv___attribute___fallthrough=yes
+else
+ ac_cv___attribute___fallthrough=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+CFLAGS="$save_CFLAGS"
+if test "$ac_cv___attribute___fallthrough" = "yes"; then
+
+$as_echo "#define __ATTRIBUTE___FALLTHROUGH_OK 1" >>confdefs.h
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv___attribute___fallthrough" >&5
+$as_echo "$ac_cv___attribute___fallthrough" >&6; }
+
fi
ac_ext=c