capstone-engine / capstone

Capstone disassembly/disassembler framework for ARM, ARM64 (ARMv8), Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
http://www.capstone-engine.org
7.62k stars 1.56k forks source link

Enable `-Wshadow=local` for CI #2170

Open XVilka opened 1 year ago

XVilka commented 1 year ago

Overshadowing variables is often a common reason for errors. Enabling this warning could help to avoid such mistakes. And example from the older version:

In file included from ../subprojects/capstone-next/arch/AArch64/AArch64InstPrinter.c:33:
../subprojects/capstone-next/arch/AArch64/AArch64AddressingModes.h: In function ‘AArch64_AM_processLogicalImmediate’:
../subprojects/capstone-next/arch/AArch64/AArch64AddressingModes.h:207:26: error: declaration of ‘Mask’ shadows a previous local [-Werror=shadow=compatible-local]
  207 |                 uint64_t Mask;
      |                          ^~~~
../subprojects/capstone-next/arch/AArch64/AArch64AddressingModes.h:197:18: note: shadowed declaration is here
  197 |         uint64_t Mask, NImms;
      |                  ^~~~
../subprojects/capstone-next/arch/AArch64/AArch64InstPrinter.c: In function ‘AArch64_printInst’:
../subprojects/capstone-next/arch/AArch64/AArch64InstPrinter.c:394:29: error: declaration of ‘LSB’ shadows a previous local [-Werror=shadow=compatible-local]
  394 |                         int LSB = (BitWidth - ImmR) % BitWidth;
      |                             ^~~
../subprojects/capstone-next/arch/AArch64/AArch64InstPrinter.c:132:13: note: shadowed declaration is here
  132 |         int LSB, Width;
      |             ^~~
../subprojects/capstone-next/arch/AArch64/AArch64InstPrinter.c:395:29: error: declaration of ‘Width’ shadows a previous local [-Werror=shadow=compatible-local]
  395 |                         int Width = ImmS + 1;
      |                             ^~~~~
../subprojects/capstone-next/arch/AArch64/AArch64InstPrinter.c:132:18: note: shadowed declaration is here
  132 |         int LSB, Width;
      |                  ^~~~~
cc1: all warnings being treated as errors
[5/2046] Compiling C object subprojects/capstone-next/libcapstone.a.p/arch_AArch64_AArch64Disassembler.c.o
FAILED: subprojects/capstone-next/libcapstone.a.p/arch_AArch64_AArch64Disassembler.c.o 
gcc-12 -Isubprojects/capstone-next/libcapstone.a.p -I../subprojects/capstone-next/include -I../subprojects/capstone-next/include/capstone -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -O2 -g --std=gnu99 -Werror=sizeof-pointer-memaccess -fvisibility=hidden -DASAN=1 -DRZ_ASSERT_STDOUT=1 -Wno-cpp -Wtype-limits -Wwrite-strings -Warray-bounds -Wshadow=local -fsanitize=bounds -fsanitize-undefined-trap-on-error -ftrivial-auto-var-init=pattern -funsigned-char -fPIC -DCAPSTONE_X86_ATT_DISABLE_NO -DCAPSTONE_X86_REDUCE_NO -DCAPSTONE_USE_SYS_DYN_MEM -DCAPSTONE_DIET_NO -DCAPSTONE_HAS_ARM -DCAPSTONE_HAS_ARM64 -DCAPSTONE_HAS_M68K -DCAPSTONE_HAS_M680X -DCAPSTONE_HAS_MIPS -DCAPSTONE_HAS_POWERPC -DCAPSTONE_HAS_SPARC -DCAPSTONE_HAS_SYSZ -DCAPSTONE_HAS_X86 -DCAPSTONE_HAS_XCORE -DCAPSTONE_HAS_TMS320C64X -DCAPSTONE_HAS_TRICORE -MD -MQ subprojects/capstone-next/libcapstone.a.p/arch_AArch64_AArch64Disassembler.c.o -MF subprojects/capstone-next/libca...
In file included from ../subprojects/capstone-next/arch/AArch64/AArch64Disassembler.c:35:
../subprojects/capstone-next/arch/AArch64/AArch64AddressingModes.h: In function ‘AArch64_AM_processLogicalImmediate’:
../subprojects/capstone-next/arch/AArch64/AArch64AddressingModes.h:207:26: error: declaration of ‘Mask’ shadows a previous local [-Werror=shadow=compatible-local]
  207 |                 uint64_t Mask;
      |                          ^~~~
../subprojects/capstone-next/arch/AArch64/AArch64AddressingModes.h:197:18: note: shadowed declaration is here
  197 |         uint64_t Mask, NImms;
      |                  ^~~~
cc1: all warnings being treated as errors

cc @Rot127

Rot127 commented 1 year ago

Will add it to the AArch64 PR. Never mind. There are also warnings in ARM. So it need to be its own PR.