I am looking for a free static checker for C99 code (including GCC extensions) with the ability to explicitly say "these preprocessor macros are always defined."
I need that last part because I am compiling embedded code for a single target processor. The compiler (Microchip's C32, GCC based) sets a macro based on the selected processor, which is then used in the PIC32 header files to select a processor-specific header file to include. cppcheck therefore fails because it detects the 30 different #ifdef
s used to select one of the many possible PIC32 processors, tries to analyse all possible combinations of these plus all other #define
s, and fails.
For example, if splint could process C99 code, I would use
splint -D__PIC32_FEATURE_SET__=460 -D__32MX460F512L__ \
-D__LANGUAGE_C__ -I/path/to/my/includes source.c
An additional problem is that the PIC32 toolchain compiler is called pic32-gcc
and not just gcc
, although I haven't yet gotten to the point of needing to account for this.
Update #1 - One thing I'm interested in, but is orthogonal to this question, is Eclipse integration (it'd be nice not to have to write a makefile for 30+ compilation units). I asked about this on the Eclipse forums (although the discussion there is more about integration into Eclipse). Nothing groundbreaking.
Update #2 - just tried scan-build
from clang, using:
scan-build --use-cc=/usr/local/bin/pic32-gcc make -B -k all
...(also without the --use-cc
flag) but all I got was the typical build output, an example of which is:
Building file: ../src/MoreMath.c
Invoking: PIC C32 C Compiler
pic32-gcc -D__DEBUG -I/usr/local/pic32-libs/include -O0 -Wall -c -fmessage-length=0 -std=gnu99 -Werror-implicit-function-declaration -MMD -MP -MF"src/MoreMath.d" -MT"src/MoreMath.d" -mprocessor=32MX460F512L -D__DEBUG -g -o"src/MoreMath.o" "../src/MoreMath.c"
Finished building: ../src/MoreMath.c
...and at the end:
Building target: MyBinary.elf
Invoking: PIC C32 C Linker
pic32-gcc -Wl,-Map,MyBinary.map -mprocessor=32MX460F512L --defsym=__MPLAB_DEBUG=1 -o"MyBinary.elf" <<ALL OF MY *.o FILES HERE>>
Finished building target: MyBinary.elf
scan-build: Removing directory '/tmp/scan-build-2010-06-21-1' because it contains no reports.
So either my code is perfect according to scan-build
, or it's not doing anything. I'm not sure what a good test might be to see if it is working.