[tor-commits] [tor/maint-0.3.4] Merge branch 'maint-0.2.9' into maint-0.3.3

nickm at torproject.org nickm at torproject.org
Mon Oct 15 14:53:23 UTC 2018


commit dff7d3d00ad5e3f9e59cd4b11f302601790d1061
Merge: f7e93cf2e b11339965
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Oct 15 10:37:49 2018 -0400

    Merge branch 'maint-0.2.9' into maint-0.3.3

 changes/bug27709      |  4 ++++
 src/common/util_bug.h | 57 +++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 48 insertions(+), 13 deletions(-)

diff --cc src/common/util_bug.h
index be549fde0,f3e5b7c96..c274355f3
--- a/src/common/util_bug.h
+++ b/src/common/util_bug.h
@@@ -53,8 -27,37 +53,37 @@@
   * security-critical properties.
   */
  #error "Sorry; we don't support building with NDEBUG."
 -#endif
 +#endif /* defined(NDEBUG) */
  
+ #if defined(TOR_UNIT_TESTS) && defined(__GNUC__)
+ /* We define this GCC macro as a replacement for PREDICT_UNLIKELY() in this
+  * header, so that in our unit test builds, we'll get compiler warnings about
+  * stuff like tor_assert(n = 5).
+  *
+  * The key here is that (e) is wrapped in exactly one layer of parentheses,
+  * and then passed right to a conditional.  If you do anything else to the
+  * expression here, or introduce any more parentheses, the compiler won't
+  * help you.
+  *
+  * We only do this for the unit-test build case because it interferes with
+  * the likely-branch labeling.  Note below that in the other case, we define
+  * these macros to just be synonyms for PREDICT_(UN)LIKELY.
+  */
+ #define ASSERT_PREDICT_UNLIKELY_(e)             \
+   ({                                            \
+     int tor__assert_tmp_value__;                \
+     if (e)                                      \
+       tor__assert_tmp_value__ = 1;              \
+     else                                        \
+       tor__assert_tmp_value__ = 0;              \
+     tor__assert_tmp_value__;                    \
+   })
+ #define ASSERT_PREDICT_LIKELY_(e) ASSERT_PREDICT_UNLIKELY_(e)
+ #else
+ #define ASSERT_PREDICT_UNLIKELY_(e) PREDICT_UNLIKELY(e)
+ #define ASSERT_PREDICT_LIKELY_(e) PREDICT_LIKELY(e)
+ #endif
+ 
  /* Sometimes we don't want to use assertions during branch coverage tests; it
   * leads to tons of unreached branches which in reality are only assertions we
   * didn't hit. */
@@@ -140,10 -143,10 +172,10 @@@ extern int bug_macro_deadcode_dummy__
    }                                                                     \
    STMT_END
  #define BUG(cond)                                                       \
-   (PREDICT_UNLIKELY(cond) ?                                             \
+   (ASSERT_PREDICT_UNLIKELY_(cond) ?                                     \
     (tor_bug_occurred_(SHORT_FILE__,__LINE__,__func__,"!("#cond")",0), 1) \
     : 0)
 -#endif
 +#endif /* defined(ALL_BUGS_ARE_FATAL) || ... */
  
  #ifdef __GNUC__
  #define IF_BUG_ONCE__(cond,var)                                         \
@@@ -155,11 -158,11 +187,11 @@@
          tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__,             \
                            "!("#cond")", 1);                             \
        }                                                                 \
-       PREDICT_UNLIKELY(bool_result); } ))
+       bool_result; } ))
 -#else
 +#else /* !(defined(__GNUC__)) */
  #define IF_BUG_ONCE__(cond,var)                                         \
    static int var = 0;                                                   \
-   if (PREDICT_UNLIKELY(cond) ?                                          \
+   if ((cond) ?                                                          \
        (var ? 1 :                                                        \
         (var=1,                                                          \
          tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__,             \
@@@ -196,7 -199,6 +228,6 @@@ void tor_capture_bugs_(int n)
  void tor_end_capture_bugs_(void);
  const struct smartlist_t *tor_get_captured_bug_log_(void);
  void tor_set_failed_assertion_callback(void (*fn)(void));
 -#endif
 +#endif /* defined(TOR_UNIT_TESTS) */
  
 -#endif
 +#endif /* !defined(TOR_UTIL_BUG_H) */
- 





More information about the tor-commits mailing list