Closed tsafin closed 2 years ago
checkpatch.pl produces totally bogus warning about side-effect of macro arguments use:
checkpatch.pl
https://github.com/tarantool/tarantool/runs/5660642327?check_suite_focus=true#step:3:118
--------------------------------------------------------------------- Commit f7f555ade4c3 ("datetime: datetime_increment_by in C from Lua") --------------------------------------------------------------------- ERROR: Macro argument reuse 'a' - possible side-effects? #46: FILE: src/lib/core/datetime.c:17: +#define MOD(a, b) (unlikely((a) < 0) ? ((b) + ((a) % (b))) : ((a) % (b))) ERROR: Macro argument reuse 'b' - possible side-effects? #46: FILE: src/lib/core/datetime.c:17: +#define MOD(a, b) (unlikely((a) < 0) ? ((b) + ((a) % (b))) : ((a) % (b))) ERROR: Macro argument reuse 'a' - possible side-effects? #47: FILE: src/lib/core/datetime.c:18: +#define DIV(a, b) (unlikely((a) < 0) ? (((a) - (b) + 1) / (b)) : ((a) / (b))) ERROR: Macro argument reuse 'b' - possible side-effects? #47: FILE: src/lib/core/datetime.c:18: +#define DIV(a, b) (unlikely((a) < 0) ? (((a) - (b) + 1) / (b)) : ((a) / (b)))
I looked around and some suggest to introduce absolutely useless tricks to shut this warning out, like
https://patchwork.ozlabs.org/project/uboot/patch/20180313075715.5676-1-uboot@andestech.com/
diff --git a/arch/riscv/include/asm/encoding.h b/arch/riscv/include/asm/encoding.h index 5ff6d59..dbf8d45 100644 --- a/arch/riscv/include/asm/encoding.h +++ b/arch/riscv/include/asm/encoding.h @@ -121,7 +121,9 @@ #define PTE_SW(PTE) ((0x88888880U >> ((PTE) & 0x1F)) & 1) #define PTE_SX(PTE) ((0xA0A0A000U >> ((PTE) & 0x1F)) & 1) -#define PTE_CHECK_PERM(PTE, SUPERVISOR, STORE, FETCH) \ +#define PTE_CHECK_PERM(_PTE, _SUPERVISOR, STORE, FETCH) \ + typeof(_PTE) (PTE) = (_PTE); \ + typeof(_SUPERVISOR) (SUPERVISOR) = (_SUPERVISOR); \ ((STORE) ? ((SUPERVISOR) ? PTE_SW(PTE) : PTE_UW(PTE)) : \ (FETCH) ? ((SUPERVISOR) ? PTE_SX(PTE) : PTE_UX(PTE)) : \ ((SUPERVISOR) ? PTE_SR(PTE) : PTE_UR(PTE)))
i.e. we introduce local variable inside of macro body typed as typeof of argument, just to make it to allow to use this argument multiple times. This make no much sense and this warning is simply bug. Please disable it
typeof
checkpatch.pl
produces totally bogus warning about side-effect of macro arguments use:https://github.com/tarantool/tarantool/runs/5660642327?check_suite_focus=true#step:3:118
I looked around and some suggest to introduce absolutely useless tricks to shut this warning out, like
https://patchwork.ozlabs.org/project/uboot/patch/20180313075715.5676-1-uboot@andestech.com/
i.e. we introduce local variable inside of macro body typed as
typeof
of argument, just to make it to allow to use this argument multiple times. This make no much sense and this warning is simply bug. Please disable it