Commit 3c75cf51 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Pavel Emelyanov

zdtm: compile fix for clang

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: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent e48a46f3
...@@ -72,7 +72,8 @@ extern void __push_opt(struct long_opt *opt); ...@@ -72,7 +72,8 @@ extern void __push_opt(struct long_opt *opt);
static struct long_opt __long_opt_##name = { \ static struct long_opt __long_opt_##name = { \
#name, #type, doc, is_required, parse_opt_##type, &name }; \ #name, #type, doc, is_required, parse_opt_##type, &name }; \
static void __init_opt_##name(void) __attribute__ ((constructor)); \ 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) \ #define __param_check(name, p, type) \
static inline type *__check_##name(void) { return(p); } static inline type *__check_##name(void) { return(p); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment