Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9911e280 authored by Chih-Hung Hsieh's avatar Chih-Hung Hsieh
Browse files

Allow LOG_ALWAYS_FATAL_IF in constexpr functions

* When __FAKE_USE_VA_ARGS has args that are not constexpr,
  reaching it in a constexpr function will be make the
  constexpr function invalid.
  To allow LOG_ALWAYS_FATAL_IF in a constexpr functions when
  the tested condition is false, it should call __FAKE_USE_VA_ARGS
  only when the tested condition is true.
* Other ALOG*_IF macros are also changed to call
  __FAKE_USE_VA_ARGS only when the tested condition is true.

Bug: 148548418
Test: WITH_TIDY=1 make
Change-Id: Ie8a444dffbf9cbef78e5e0b49b44f4092bcf9982
parent 077839ab
Loading
Loading
Loading
Loading
+25 −20
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ __BEGIN_DECLS
/*
 * Use __VA_ARGS__ if running a static analyzer,
 * to avoid warnings of unused variables in __VA_ARGS__.
 * Use contexpr function in C++ mode, so these macros can be used
 * Use constexpr function in C++ mode, so these macros can be used
 * in other constexpr functions without warning.
 */
#ifdef __clang_analyzer__
@@ -132,9 +132,9 @@ extern int __fake_use_va_args(int, ...);
 */
#ifndef LOG_ALWAYS_FATAL_IF
#define LOG_ALWAYS_FATAL_IF(cond, ...)                                                    \
  ((__predict_false(cond))                                          \
       ? ((void)android_printAssert(#cond, LOG_TAG, ##__VA_ARGS__)) \
       : __FAKE_USE_VA_ARGS(__VA_ARGS__))
  ((__predict_false(cond)) ? (__FAKE_USE_VA_ARGS(__VA_ARGS__),                            \
                              ((void)android_printAssert(#cond, LOG_TAG, ##__VA_ARGS__))) \
                           : ((void)0))
#endif

#ifndef LOG_ALWAYS_FATAL
@@ -214,8 +214,9 @@ extern int __fake_use_va_args(int, ...);
#define ALOGV_IF(cond, ...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
#else
#define ALOGV_IF(cond, ...)                                                               \
  ((__predict_false(cond)) ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
  ((__predict_false(cond))                                                                \
       ? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
       : ((void)0))
#endif
#endif

@@ -228,8 +229,9 @@ extern int __fake_use_va_args(int, ...);

#ifndef ALOGD_IF
#define ALOGD_IF(cond, ...)                                                             \
  ((__predict_false(cond)) ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
  ((__predict_false(cond))                                                              \
       ? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
       : ((void)0))
#endif

/*
@@ -241,8 +243,9 @@ extern int __fake_use_va_args(int, ...);

#ifndef ALOGI_IF
#define ALOGI_IF(cond, ...)                                                            \
  ((__predict_false(cond)) ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
  ((__predict_false(cond))                                                             \
       ? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
       : ((void)0))
#endif

/*
@@ -254,8 +257,9 @@ extern int __fake_use_va_args(int, ...);

#ifndef ALOGW_IF
#define ALOGW_IF(cond, ...)                                                            \
  ((__predict_false(cond)) ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
  ((__predict_false(cond))                                                             \
       ? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
       : ((void)0))
#endif

/*
@@ -267,8 +271,9 @@ extern int __fake_use_va_args(int, ...);

#ifndef ALOGE_IF
#define ALOGE_IF(cond, ...)                                                             \
  ((__predict_false(cond)) ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
  ((__predict_false(cond))                                                              \
       ? (__FAKE_USE_VA_ARGS(__VA_ARGS__), (void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
       : ((void)0))
#endif

/* --------------------------------------------------------------------- */