summaryrefslogtreecommitdiffstats
path: root/liblog
diff options
context:
space:
mode:
authorChih-Hung Hsieh2018-07-18 18:23:02 -0500
committerChih-Hung Hsieh2018-07-18 19:07:45 -0500
commitfdd3f5ec747dee08325b2367a6269054a003dd5e (patch)
treec3e6d5160287aa6436f7995e77aa18547fa7ab95 /liblog
parent54f40303d5632e7f5852cd9f467454281c4f979a (diff)
downloadplatform-system-core-fdd3f5ec747dee08325b2367a6269054a003dd5e.tar.gz
platform-system-core-fdd3f5ec747dee08325b2367a6269054a003dd5e.tar.xz
platform-system-core-fdd3f5ec747dee08325b2367a6269054a003dd5e.zip
Use __VA_ARGS__ when in clang static analyzer.
Clang static analyzer can optimize out if (false) ... and report unused variables in __VA_ARGS__. Bug: 111614304 Test: make with WITH_TIDY=1 Change-Id: I214ced736230fda847031fd4eee23015fd988ffc
Diffstat (limited to 'liblog')
-rw-r--r--liblog/include/log/log_main.h40
1 files changed, 26 insertions, 14 deletions
diff --git a/liblog/include/log/log_main.h b/liblog/include/log/log_main.h
index 21fc7cca0..f1ff31aa0 100644
--- a/liblog/include/log/log_main.h
+++ b/liblog/include/log/log_main.h
@@ -40,6 +40,17 @@ __BEGIN_DECLS
40#endif 40#endif
41#endif 41#endif
42 42
43/*
44 * Use __VA_ARGS__ if running a static analyzer,
45 * to avoid warnings of unused variables in __VA_ARGS__.
46 */
47
48#ifdef __clang_analyzer__
49#define __FAKE_USE_VA_ARGS(...) ((void)(__VA_ARGS__))
50#else
51#define __FAKE_USE_VA_ARGS(...) ((void)(0))
52#endif
53
43/* --------------------------------------------------------------------- */ 54/* --------------------------------------------------------------------- */
44 55
45/* 56/*
@@ -112,7 +123,7 @@ __BEGIN_DECLS
112#define LOG_ALWAYS_FATAL_IF(cond, ...) \ 123#define LOG_ALWAYS_FATAL_IF(cond, ...) \
113 ((__predict_false(cond)) \ 124 ((__predict_false(cond)) \
114 ? ((void)android_printAssert(#cond, LOG_TAG, ##__VA_ARGS__)) \ 125 ? ((void)android_printAssert(#cond, LOG_TAG, ##__VA_ARGS__)) \
115 : (void)0) 126 : __FAKE_USE_VA_ARGS(__VA_ARGS__))
116#endif 127#endif
117 128
118#ifndef LOG_ALWAYS_FATAL 129#ifndef LOG_ALWAYS_FATAL
@@ -128,10 +139,10 @@ __BEGIN_DECLS
128#if LOG_NDEBUG 139#if LOG_NDEBUG
129 140
130#ifndef LOG_FATAL_IF 141#ifndef LOG_FATAL_IF
131#define LOG_FATAL_IF(cond, ...) ((void)0) 142#define LOG_FATAL_IF(cond, ...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
132#endif 143#endif
133#ifndef LOG_FATAL 144#ifndef LOG_FATAL
134#define LOG_FATAL(...) ((void)0) 145#define LOG_FATAL(...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
135#endif 146#endif
136 147
137#else 148#else
@@ -175,11 +186,12 @@ __BEGIN_DECLS
175#ifndef ALOGV 186#ifndef ALOGV
176#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) 187#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
177#if LOG_NDEBUG 188#if LOG_NDEBUG
178#define ALOGV(...) \ 189#define ALOGV(...) \
179 do { \ 190 do { \
180 if (false) { \ 191 __FAKE_USE_VA_ARGS(__VA_ARGS__); \
181 __ALOGV(__VA_ARGS__); \ 192 if (false) { \
182 } \ 193 __ALOGV(__VA_ARGS__); \
194 } \
183 } while (false) 195 } while (false)
184#else 196#else
185#define ALOGV(...) __ALOGV(__VA_ARGS__) 197#define ALOGV(...) __ALOGV(__VA_ARGS__)
@@ -188,11 +200,11 @@ __BEGIN_DECLS
188 200
189#ifndef ALOGV_IF 201#ifndef ALOGV_IF
190#if LOG_NDEBUG 202#if LOG_NDEBUG
191#define ALOGV_IF(cond, ...) ((void)0) 203#define ALOGV_IF(cond, ...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
192#else 204#else
193#define ALOGV_IF(cond, ...) \ 205#define ALOGV_IF(cond, ...) \
194 ((__predict_false(cond)) ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ 206 ((__predict_false(cond)) ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
195 : (void)0) 207 : __FAKE_USE_VA_ARGS(__VA_ARGS__))
196#endif 208#endif
197#endif 209#endif
198 210
@@ -206,7 +218,7 @@ __BEGIN_DECLS
206#ifndef ALOGD_IF 218#ifndef ALOGD_IF
207#define ALOGD_IF(cond, ...) \ 219#define ALOGD_IF(cond, ...) \
208 ((__predict_false(cond)) ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ 220 ((__predict_false(cond)) ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
209 : (void)0) 221 : __FAKE_USE_VA_ARGS(__VA_ARGS__))
210#endif 222#endif
211 223
212/* 224/*
@@ -219,7 +231,7 @@ __BEGIN_DECLS
219#ifndef ALOGI_IF 231#ifndef ALOGI_IF
220#define ALOGI_IF(cond, ...) \ 232#define ALOGI_IF(cond, ...) \
221 ((__predict_false(cond)) ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ 233 ((__predict_false(cond)) ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
222 : (void)0) 234 : __FAKE_USE_VA_ARGS(__VA_ARGS__))
223#endif 235#endif
224 236
225/* 237/*
@@ -232,7 +244,7 @@ __BEGIN_DECLS
232#ifndef ALOGW_IF 244#ifndef ALOGW_IF
233#define ALOGW_IF(cond, ...) \ 245#define ALOGW_IF(cond, ...) \
234 ((__predict_false(cond)) ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ 246 ((__predict_false(cond)) ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
235 : (void)0) 247 : __FAKE_USE_VA_ARGS(__VA_ARGS__))
236#endif 248#endif
237 249
238/* 250/*
@@ -245,7 +257,7 @@ __BEGIN_DECLS
245#ifndef ALOGE_IF 257#ifndef ALOGE_IF
246#define ALOGE_IF(cond, ...) \ 258#define ALOGE_IF(cond, ...) \
247 ((__predict_false(cond)) ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ 259 ((__predict_false(cond)) ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
248 : (void)0) 260 : __FAKE_USE_VA_ARGS(__VA_ARGS__))
249#endif 261#endif
250 262
251/* --------------------------------------------------------------------- */ 263/* --------------------------------------------------------------------- */