[CRIU] [PATCH 06/23] zdtm: compile fix for clang

Kir Kolyshkin kir at openvz.org
Tue Oct 11 18:46:44 PDT 2016


clang complains about an unused function:

> clang -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
> -iquote ./arch/x86/include  -c -o parseargs.o parseargs.c
> parseargs.c:12:1: error: unused function '__check_help'
> [-Werror,-Wunused-function]
> TEST_OPTION(help, bool, "print help message and exit", 0);
> ^
> ./zdtmtst.h:71:2: note: expanded from macro 'TEST_OPTION'
>         param_check_##type(name, &(name));
> \
>         ^
> <scratch space>:46:1: note: expanded from here
> param_check_bool
> ^
> ./zdtmtst.h:84:35: note: expanded from macro 'param_check_bool'
> #define param_check_bool(name, p) __param_check(name, p, int)
>                                   ^
> ./zdtmtst.h:78:22: note: expanded from macro '__param_check'
>         static inline type *__check_##name(void) { return(p); }
>                             ^
> <scratch space>:47:1: note: expanded from here
> __check_help
> ^
> 1 error generated.
> <builtin>: recipe for target 'parseargs.o' failed

As far as I can tell, the functions __check_##name are generated in
order to check the argument type by the compiler.

For gcc, the "inline" keyword is enough to suppress the "unused function"
warning even when -Wunused-function is used. For clang, it's not the
case (see https://llvm.org/bugs/show_bug.cgi?id=22712).

A way to "use" the function is to use its name as a pointer and cast it
to void. This is what this patch does.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 test/zdtm/lib/zdtmtst.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
index 929db8d..8a6f6ba 100644
--- a/test/zdtm/lib/zdtmtst.h
+++ b/test/zdtm/lib/zdtmtst.h
@@ -72,7 +72,8 @@ extern void __push_opt(struct long_opt *opt);
 	static struct long_opt __long_opt_##name = {				\
 		#name, #type, doc, is_required, parse_opt_##type, &name };	\
 	static void __init_opt_##name(void) __attribute__ ((constructor));	\
-	static void __init_opt_##name(void) { __push_opt(&__long_opt_##name); }
+	static void __init_opt_##name(void) \
+	{ (void)__check_##name; __push_opt(&__long_opt_##name); }
 
 #define __param_check(name, p, type) \
 	static inline type *__check_##name(void) { return(p); }
-- 
2.7.4



More information about the CRIU mailing list