]> The Tcpdump Group git mirrors - libpcap/commitdiff
Use __builtin_unreachable(). [skip ci]
authorDenis Ovsienko <[email protected]>
Fri, 6 Aug 2021 22:37:23 +0000 (23:37 +0100)
committerDenis Ovsienko <[email protected]>
Fri, 6 Aug 2021 22:37:23 +0000 (23:37 +0100)
Refine the changes made in commit 3f35396 and use a macro with comments.

diag-control.h
gencode.c
optimize.c

index c1ec5acdb08e600f9932fa0d6fc6183d3e7fa5f8..d1622aa6f81dd121e4e3d14520638749a27e8476 100644 (file)
   #endif
 #endif
 
+/*
+ * GCC needs this on AIX for longjmp().
+ */
+#if PCAP_IS_AT_LEAST_GNUC_VERSION(5,1)
+  /*
+   * Beware that the effect of this builtin is more than just squelching the
+   * warning! GCC trusts it enough for the process to segfault if the control
+   * flow reaches the builtin (an infinite empty loop in the same context would
+   * squelch the warning and ruin the process too, albeit in a different way).
+   * So please remember to use this very carefully.
+   */
+  #define PCAP_UNREACHABLE __builtin_unreachable();
+#else
+  #define PCAP_UNREACHABLE
+#endif
+
 #endif /* _diag_control_h */
index 299d1c632ac79673f60253353575e39b23eadb64..07259a70c2813193e30a954a13e8a60001e36186 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -77,6 +77,7 @@
 #include "pcap/sll.h"
 #include "pcap/ipnet.h"
 #include "arcnet.h"
+#include "diag-control.h"
 
 #include "grammar.h"
 #include "scanner.h"
@@ -476,10 +477,7 @@ bpf_error(compiler_state_t *cstate, const char *fmt, ...)
        longjmp(cstate->top_ctx, 1);
        /*NOTREACHED*/
 #ifdef _AIX
-       /*
-        * Same GCC workaround as in tcpdump.
-        */
-       while (1);
+       PCAP_UNREACHABLE
 #endif /* _AIX */
 }
 
index 199ab5506f7da9a48e204e8547d565d35b7d336d..604e35e8852801a92f6d84692f028856381971bb 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "gencode.h"
 #include "optimize.h"
+#include "diag-control.h"
 
 #ifdef HAVE_OS_PROTO_H
 #include "os-proto.h"
@@ -2422,10 +2423,7 @@ opt_error(opt_state_t *opt_state, const char *fmt, ...)
        longjmp(opt_state->top_ctx, 1);
        /* NOTREACHED */
 #ifdef _AIX
-       /*
-        * Same GCC workaround as in tcpdump.
-        */
-       while (1);
+       PCAP_UNREACHABLE
 #endif /* _AIX */
 }
 
@@ -2932,10 +2930,7 @@ conv_error(conv_state_t *conv_state, const char *fmt, ...)
        longjmp(conv_state->top_ctx, 1);
        /* NOTREACHED */
 #ifdef _AIX
-       /*
-        * Same GCC workaround as in tcpdump.
-        */
-       while (1);
+       PCAP_UNREACHABLE
 #endif /* _AIX */
 }