@cryptotaxi247 / netdata-1 / commits / adb7026b1

Make use of GCC's __attribute__((unused)) (#6392)

* configure.ac: Add support for GCC's __attribute__((unused)) When compiling under GCC with -Wextra (along with -Wall) there are a lot of compiler warnings such as collectors/cgroups.plugin/cgroup-network.c:89:45: warning: unused parameter ‘scope’ [-Wunused-parameter] 89 | struct iface *read_proc_net_dev(const char *scope, const char *prefix) { | ~~~~~~~~~~~~^~~~~ Some arguments may be able to be got rid off, others won't. GCC (and at least clang[0]) provide an __attribute__((unused)) annotation that can be used on function parameters (also on variables, functions, labels, enums, structs etc) to inform the compiler of such and will squash warnings of the above nature. A check is added to configure.ac for the use of GCC (I believe $GCC will be set to 'yes' for clang also) and if found it creates __always_unused & __maybe_unused #define's set to __attribute__((unused)) otherwise it just sets them empty. If other compilers have a similar feature this check can be adjusted to accommodate them. The reason for the two defines is that some variables may always be unused in a function, others may or may not depending on #ifdef's for example. So we are able to document both cases. Subsequent commits will start making use of these to squash such compiler warnings. [0]: https://clang.llvm.org/docs/AttributeReference.html#maybe-unused-unused Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * collectors/statsd.plugin: Mark a function argument as __maybe_unused In collectors/statsd.plugin/statsd.c the app function argument to STATSD_APP_CHART_DIM() might be unused if NETDATA_INTERNAL_CHECKS is not defined, then the debug() macro that it's used in from libnetdata/log/log.h will be defined to a dummy function where none of the arguments are used. This fixes a compiler warning [-Wunused-parameter] when compiling with -Wextra *and* -Wall. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * collectors/apps.plugin: Mark a function argument as __maybe_unused In collectors/apps.plugin/apps_plugin.c the function debug_print_process_tree() takes an argument 'msg' that might be unused if NETDATA_INTERNAL_CHECKS is not defined, then debug_log() will be set to a dummy function that takes no arguments. This fixes a compiler warning [-Wunused-parameter] when compiling with -Wextra *and* -Wall. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * libnetdata/locks/locks: Mark function arguments as __maybe_unused In libnetdata/locks/locks.c there a number of functions that take arguments 'file', 'function' & 'line' that might be unused if NETDATA_INTERNAL_CHECKS is not defined, then the debug() macro that it's used in from libnetdata/log/log.h will be defined to a dummy function where none of the arguments are used. This fixes compiler warnings [-Wunused-parameter] when compiling with -Wextra *and* -Wall. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * libnetdata/socket/security: Mark a function argument as __maybe_unused In libnetdata/socket/security.c the function security_info_callback() takes an argument 'ret' that might be unused if NETDATA_INTERNAL_CHECKS is not defined, then the debug() macro that it's used in from libnetdata/log/log.h will be defined to a dummy function where none of the arguments are used. This fixes a compiler warning [-Wunused-parameter] when compiling with -Wextra *and* -Wall. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * collectors/cgroups.plugin: Mark a function argument as __maybe_unused In collectors/cgroups.plugin/cgroup-network.c the function read_proc_net_dev() takes an argument 'scope' that might be unused if the NETDATA_INTERNAL_CHECKS is not defined. This fixes a compiler warning [-Wunused-parameter] when compiling with -Wextra *and* -Wall". Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * database/rrddim: Mark function arguments as __maybe_unused In database/rrddim.c there a couple of functions that take a 'st' argument that might be unused if NETDATA_INTERNAL_CHECKS is not defined, then the debug() macro that it's used in from libnetdata/log/log.h will be defined to a dummy function where none of the arguments are used. This fixes compiler warnings [-Wunused-parameter] when compiling with -Wextra *and* -Wall. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net> * database/rrdvar: Mark a function argument as __maybe_unused In database/rrdvar.c the function rrdvar_create_and_index() take an argument 'scope' that might be unused if NETDATA_INTERNAL_CHECKS is not defined, then the debug() macro that it's used in from libnetdata/log/log.h will be defined to a dummy function where none of the arguments are used. This fixes a compiler warning [-Wunused-parameter] when compiling with -Wextra *and* -Wall. Signed-off-by: Andrew Clayton <andrew@zeta.digital-domain.net>

Andrew Clayton committed Jul 23, 2019 at 13:12 UTC adb7026b14fea7bbebee93c8958d92ee9cf1efaf
8 files changed +38 -18
collectors/apps.plugin/apps_plugin.c
+1 -1
@@ -2227,7 +2227,7 @@ static inline int debug_print_process_and_parents(struct pid_stat *p, usec_t tim
2227 return indent + 1;
2228 }
2229
2230 -static inline void debug_print_process_tree(struct pid_stat *p, char *msg) {
2230 +static inline void debug_print_process_tree(struct pid_stat *p, char *msg __maybe_unused) {
2231 debug_log("%s: process %s (%d, %s) with parents:", msg, p->comm, p->pid, p->updated?"running":"exited");
2232 debug_print_process_and_parents(p, p->stat_collected_usec);
2233 }
collectors/cgroups.plugin/cgroup-network.c
+1 -1
@@ -86,7 +86,7 @@ unsigned int read_iface_ifindex(const char *prefix, const char *iface) {
86 return (unsigned int)ifindex;
87 }
88
89 -struct iface *read_proc_net_dev(const char *scope, const char *prefix) {
89 +struct iface *read_proc_net_dev(const char *scope __maybe_unused, const char *prefix) {
90 if(!prefix) prefix = "";
91
92 procfile *ff = NULL;
collectors/statsd.plugin/statsd.c
+1 -1
@@ -1067,7 +1067,7 @@ static const char *valuetype2string(STATSD_APP_CHART_DIM_VALUE_TYPE type) {
1067 }
1068
1069 static STATSD_APP_CHART_DIM *add_dimension_to_app_chart(
1070 - STATSD_APP *app
1070 + STATSD_APP *app __maybe_unused
1071 , STATSD_APP_CHART *chart
1072 , const char *metric_name
1073 , const char *dim_name
configure.ac
+8
@@ -437,6 +437,14 @@ else
437 AC_DEFINE_UNQUOTED([unlikely(x)], [(x)], [gcc branch optimization])
438 fi
439
440 +if test "${GCC}" = "yes"; then
441 + AC_DEFINE([__always_unused], [__attribute__((unused))], [gcc unused attribute])
442 + AC_DEFINE([__maybe_unused], [__attribute__((unused))], [gcc unused attribute])
443 +else
444 + AC_DEFINE([__always_unused], [], [dummy unused attribute])
445 + AC_DEFINE([__maybe_unused], [], [dummy unused attribute])
446 +fi
447 +
448 if test "${enable_pedantic}" = "yes"; then
449 enable_strict="yes"
450 CFLAGS="${CFLAGS} -pedantic -Wall -Wextra -Wno-long-long"
database/rrddim.c
+2 -2
@@ -466,7 +466,7 @@ inline void rrddim_is_obsolete(RRDSET *st, RRDDIM *rd) {
466 rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE_DIMENSIONS);
467 }
468
469 -inline void rrddim_isnot_obsolete(RRDSET *st, RRDDIM *rd) {
469 +inline void rrddim_isnot_obsolete(RRDSET *st __maybe_unused, RRDDIM *rd) {
470 debug(D_RRD_CALLS, "rrddim_isnot_obsolete() for chart %s, dimension %s", st->name, rd->name);
471
472 rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE);
@@ -475,7 +475,7 @@ inline void rrddim_isnot_obsolete(RRDSET *st, RRDDIM *rd) {
475 // ----------------------------------------------------------------------------
476 // RRDDIM - collect values for a dimension
477
478 -inline collected_number rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number value) {
478 +inline collected_number rrddim_set_by_pointer(RRDSET *st __maybe_unused, RRDDIM *rd, collected_number value) {
479 debug(D_RRD_CALLS, "rrddim_set_by_pointer() for chart %s, dimension %s, value " COLLECTED_NUMBER_FORMAT, st->name, rd->name, value);
480
481 now_realtime_timeval(&rd->last_collected_time);
database/rrdvar.c
+2 -1
@@ -68,7 +68,8 @@ inline void rrdvar_free(RRDHOST *host, avl_tree_lock *tree, RRDVAR *rv) {
68 freez(rv);
69 }
70
71 -inline RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, RRDVAR_TYPE type, RRDVAR_OPTIONS options, void *value) {
71 +inline RRDVAR *rrdvar_create_and_index(const char *scope __maybe_unused, avl_tree_lock *tree, const char *name,
72 + RRDVAR_TYPE type, RRDVAR_OPTIONS options, void *value) {
73 char *variable = strdupz(name);
74 rrdvar_fix_name(variable);
75 uint32_t hash = simple_hash(variable);
libnetdata/locks/locks.c
+22 -11
@@ -82,7 +82,8 @@ int __netdata_mutex_unlock(netdata_mutex_t *mutex) {
82 return ret;
83 }
84
85 -int netdata_mutex_init_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
85 +int netdata_mutex_init_debug(const char *file __maybe_unused, const char *function __maybe_unused,
86 + const unsigned long line __maybe_unused, netdata_mutex_t *mutex) {
87 usec_t start = 0;
88 (void)start;
89
@@ -98,7 +99,8 @@ int netdata_mutex_init_debug( const char *file, const char *function, const unsi
99 return ret;
100 }
101
101 -int netdata_mutex_lock_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
102 +int netdata_mutex_lock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
103 + const unsigned long line __maybe_unused, netdata_mutex_t *mutex) {
104 usec_t start = 0;
105 (void)start;
106
@@ -114,7 +116,8 @@ int netdata_mutex_lock_debug( const char *file, const char *function, const unsi
116 return ret;
117 }
118
117 -int netdata_mutex_trylock_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
119 +int netdata_mutex_trylock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
120 + const unsigned long line __maybe_unused, netdata_mutex_t *mutex) {
121 usec_t start = 0;
122 (void)start;
123
@@ -130,7 +133,8 @@ int netdata_mutex_trylock_debug( const char *file, const char *function, const u
133 return ret;
134 }
135
133 -int netdata_mutex_unlock_debug( const char *file, const char *function, const unsigned long line, netdata_mutex_t *mutex) {
136 +int netdata_mutex_unlock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
137 + const unsigned long line __maybe_unused, netdata_mutex_t *mutex) {
138 usec_t start = 0;
139 (void)start;
140
@@ -219,7 +223,8 @@ int __netdata_rwlock_trywrlock(netdata_rwlock_t *rwlock) {
223 }
224
225
222 -int netdata_rwlock_destroy_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
226 +int netdata_rwlock_destroy_debug(const char *file __maybe_unused, const char *function __maybe_unused,
227 + const unsigned long line __maybe_unused, netdata_rwlock_t *rwlock) {
228 usec_t start = 0;
229 (void)start;
230
@@ -235,7 +240,8 @@ int netdata_rwlock_destroy_debug( const char *file, const char *function, const
240 return ret;
241 }
242
238 -int netdata_rwlock_init_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
243 +int netdata_rwlock_init_debug(const char *file __maybe_unused, const char *function __maybe_unused,
244 + const unsigned long line __maybe_unused, netdata_rwlock_t *rwlock) {
245 usec_t start = 0;
246 (void)start;
247
@@ -251,7 +257,8 @@ int netdata_rwlock_init_debug( const char *file, const char *function, const uns
257 return ret;
258 }
259
254 -int netdata_rwlock_rdlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
260 +int netdata_rwlock_rdlock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
261 + const unsigned long line __maybe_unused, netdata_rwlock_t *rwlock) {
262 usec_t start = 0;
263 (void)start;
264
@@ -267,7 +274,8 @@ int netdata_rwlock_rdlock_debug( const char *file, const char *function, const u
274 return ret;
275 }
276
270 -int netdata_rwlock_wrlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
277 +int netdata_rwlock_wrlock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
278 + const unsigned long line __maybe_unused, netdata_rwlock_t *rwlock) {
279 usec_t start = 0;
280 (void)start;
281
@@ -283,7 +291,8 @@ int netdata_rwlock_wrlock_debug( const char *file, const char *function, const u
291 return ret;
292 }
293
286 -int netdata_rwlock_unlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
294 +int netdata_rwlock_unlock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
295 + const unsigned long line __maybe_unused, netdata_rwlock_t *rwlock) {
296 usec_t start = 0;
297 (void)start;
298
@@ -299,7 +308,8 @@ int netdata_rwlock_unlock_debug( const char *file, const char *function, const u
308 return ret;
309 }
310
302 -int netdata_rwlock_tryrdlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
311 +int netdata_rwlock_tryrdlock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
312 + const unsigned long line __maybe_unused, netdata_rwlock_t *rwlock) {
313 usec_t start = 0;
314 (void)start;
315
@@ -315,7 +325,8 @@ int netdata_rwlock_tryrdlock_debug( const char *file, const char *function, cons
325 return ret;
326 }
327
318 -int netdata_rwlock_trywrlock_debug( const char *file, const char *function, const unsigned long line, netdata_rwlock_t *rwlock) {
328 +int netdata_rwlock_trywrlock_debug(const char *file __maybe_unused, const char *function __maybe_unused,
329 + const unsigned long line __maybe_unused, netdata_rwlock_t *rwlock) {
330 usec_t start = 0;
331 (void)start;
332
libnetdata/socket/security.c
+1 -1
@@ -20,7 +20,7 @@ int netdata_validate_server = NETDATA_SSL_VALID_CERTIFICATE;
20 * @param where the variable with the flags set.
21 * @param ret the return of the caller
22 */
23 -static void security_info_callback(const SSL *ssl, int where, int ret) {
23 +static void security_info_callback(const SSL *ssl, int where, int ret __maybe_unused) {
24 (void)ssl;
25 if (where & SSL_CB_ALERT) {
26 debug(D_WEB_CLIENT,"SSL INFO CALLBACK %s %s", SSL_alert_type_string(ret), SSL_alert_desc_string_long(ret));