views:

172

answers:

3

I'm writing a lot of code for the HiTech C compiler. I'm sure that my code would benefit from a static checker like splint, but splint itself trips up on some of HiTech's extensions, like cp0 and sfr declarations. I can't just tell splint to skip the HiTech headers, though, because then it has no idea where most of my identifiers are from.

Does anyone know of a static checker that can cope with this?

Added: examples of extensions: Mostly it's just new type qualifiers and absolute addressing, eg.

extern volatile cp0 unsigned int cp0_Config @ __REGADDR(16,0);
extern volatile sfr unsigned long OC2R @ 0xBF803210;

(There's also the persistent type qualifier.)

There are also the interrupt and fast qualifiers for functions:

void interrupt ExceptionHandler(void) @GENERAL_EXCEPTION
{
    ...
}

Added:

I finally got around to trying Doug Currie's approach below. I used a shell script with SED to strip out any trailing "... @ ...;" absolute positioning declarations, and ran split with

splint -D__32MX460F512L__ -Dsfr= -Dcp0= -Dmips32r2= -I ~/HiTechStripped mymodule.c

Depending on the module, splint complains:

< Location unknown >: Field name reused: 
  Code cannot be parsed.  For help on parse errors, see splint -help
  parseerrors. (Use -syntax to inhibit warning)
< Location unknown >: Previous use of 
< Location unknown >: Previous use of 
< Location unknown >: Previous use of
[this goes on for about 100 lines...]

On other modules, I get:

../../../../HiTechStripped/stdlib.h:140:39: mismatched parentheses in #if
  Preprocessing error. (Use -preproc to inhibit warning)

It's wrong about this, as far as I can tell:

#if defined(_XA_) && sizeof(double) == 8

I think perhaps I should give up on the static checking. Thanks for the answers.

+2  A: 

One workaround is to create new header files that declare the identifiers from the HiTech headers, and that are only used with splint. This worked for me with the HiTech PIC18 compiler. You should be able to automate the generation of the alternate headers once you find the substitutions you need to make.

Doug Currie
See comments for results of attempting this.
detly
+1  A: 

I believe Cppcheck should be able to analyse the code.

Daniel
cppcheck seems to run fine, but doesn't give me any warnings or errors whatsoever.
detly
A: 

With all static checkers you have to specify which command line macros are to be defined, so you can work-around extensions with conditional compilation by defining a macro when running the checker, say STATIC_ANLAYSIS, and then using that to block out offending constructs or provide replacements. Some extensions you could simply redefine on the static analyser command line to something that will pass the checker.

I am not familiar with the compiler or what extensions it provides; perhaps if you gave a few examples, specific work arounds could be suggested?

Clifford