Closed alfonsoespinosa closed 4 months ago
Hi @alfonsoespinosa! We appreciate you submitting your first issue for our open-source project. 🌟
Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙
For the Cortex-M I am dealing with, in order to prevent cppcheck
from triggering the #error
directives that raise in zephyr/toolchain.h, zephyr/toolchain/gcc.h, zephyr/sys/util.h, zephyr/arch/arm/aarch32/error.h, and zephyr/kernel.h these are the definitions I need to provide as arguments to the analyzer.
-D__GNUC__ -D__BYTE_ORDER__=1234 -DCONFIG_ARM -D__CHAR_BIT__=8 -D__SIZEOF_LONG__=4 -D__SIZEOF_LONG_LONG__=8 -DCONFIG_ARMV7_M_ARMV8_M_MAINLINE -DCONFIG_NUM_COOP_PRIORITIES=16 -DCONFIG_NUM_PREEMPT_PRIORITIES=15
They can be placed in a file to let CodeChecker analyze
forward them to cppcheck
with option --cppcheckargs
. That can be added to the input arguments in https://github.com/zephyrproject-rtos/zephyr/blob/a6eef0ba3755f2530c5ce93524e5ac4f5be30194/cmake/sca/codechecker/sca.cmake#L22 so I will probably try to figure out how to generate automatically the file with the definitions, depending some of them from the compiler type, architecture or kernel priorities configuration
-D__GNUC__ -D__BYTE_ORDER__=1234 -DCONFIG_ARM -D__CHAR_BIT__=8 -D__SIZEOF_LONG__=4 -D__SIZEOF_LONG_LONG__=8 -DCONFIG_ARMV7_M_ARMV8_M_MAINLINE -DCONFIG_NUM_COOP_PRIORITIES=16 -DCONFIG_NUM_PREEMPT_PRIORITIES=15
They can be placed in a file to let
CodeChecker analyze
forward them tocppcheck
with option--cppcheckargs
. That can be added to the input arguments in
Thanks @alfonsoespinosa for the investigation, it does look like the generated Kconfig
symbols are not taken into account? Is it possible that cppcheck
isn't including the generated autoconf.h
file?
Thanks @alfonsoespinosa for the investigation, it does look like the generated
Kconfig
symbols are not taken into account? Is it possible thatcppcheck
isn't including the generatedautoconf.h
file?
It's not being added to the command line arguments by CodeChecker analyze
, but indeed that is the purpose of cppcheck
option --include
:
--include=<file>
Force inclusion of a file before the checked file. Can
be used for example when checking the Linux kernel,
where autoconf.h needs to be included for every file
compiled. Works the same way as the GCC -include
option.
So it could be also added from CodeChecker analyze
in the file passed with --cppcheckargs
, and at least the 3 Kconfig
-related missing defines would be solved.
Bad news is that doing this causes a really weird collateral damage:
zephyr/include/zephyr/devicetree.h:4231:0: error: failed to expand '_EXC_IRQ_DEFAULT_PRIO', Invalid ## usage when expanding 'DT_CAT3'.
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.
We have bumped to Zephyr 3.5 and the behaviour changes slightly. The workaround in my previous comment is not working anymore. Apart from now having to define manually also CONFIG_CPU_CORTEX_M
(otherwise preprocessor fails here), there are a couple of __ASSERT
that do not work in the Memory Management Internal APIs header file (in this case probably an issue with Nordic's porting).
I will try to catch up to 3.5 and then later try to work out something for newer versions
Could you please remove the stale label @MaureenHelm ?
Getting back to this on v3.5.0, cppcheck
is giving
`error: failed to expand '__ASSERT', it is invalid to use a preprocessor directive as macro parameter [preprocessorErrorDirective]
here and here in include/zephyr/sys/mem_manage.h
. One possible solution is to put the preprocessor directive outside, conditionally defining some macro that later would be used in the __ASSERT()
, like this diff does.
There is later an error: failed to expand '_EXC_IRQ_DEFAULT_PRIO', Invalid ## usage when expanding 'DT_CAT3': Unexpected token ')' [preprocessorErrorDirective]
here in include/zephyr/arch/arm/cortex_m/exc.h
, that seems to be a cppcheck
bug about failing to handle ## in macro definitions: https://github.com/danmar/simplecpp/issues/228
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.
No news about this? Having trouble checking my projects.
Bug description
When running static analysis through CodeChecker support in the build system (
-DZEPHYR_SCA_VARIANT=codechecker
), Cppcheck fails to analyze the code.Found on 3.4, but also verified to fail in 3.5.
To Reproduce Steps to reproduce the behavior:
zephyr/samples/hello_world/src/main.c
west build -b qemu_x86 -- -DZEPHYR_SCA_VARIANT=codechecker
west build
), and no defect is found for the source file containing the issueExpected behavior Native integration of static code analysis should work when including Zephyr headers. Otherwise, it offers no functionality for real projects
Impact I can temporarily get static code analysis with a workaround using a script that removes
zephyr/include
from the list of include paths (-I
parameter) for the call tocppcheck
executableEnvironment (please complete the following information):
arm-zephyr-eabi
andx86_64-zephyr-elf
)a6eef0ba3755f2530c5ce93524e5ac4f5be30194
)Additional context I have tried running
CodeChecker analyze
with the same arguments set by the build system. Then, when I omit the Cppcheck option--suppress=preprocessorErrorDirective
, error#error "Invalid/unknown toolchain configuration"
is raising inzephyr/include/zephyr/toolchain.h
. When<zephyr/kernel.h>
is not included in sample source file, probablyzephyr/toolchain.h
gets never included, because even removing--suppress=preprocessorErrorDirective
, this#error
is not thrown, performing the static code analysis as expected.Ccing @pdgendt