Manual: Add chapter about speeding up Cppcheck analysis

This commit is contained in:
Daniel Marjamäki 2019-03-11 13:11:17 +01:00
parent 729f57d8f1
commit 7fd34ac8a2
1 changed files with 81 additions and 0 deletions

View File

@ -593,6 +593,87 @@ Newline
Carriage return
## Speeding up Cppcheck
It is possible to speed up Cppcheck analysis in a few different ways.
### Preprocessor configurations
Imagine this source code:
void foo()
{
int x;
#ifdef __GNUC__
x = 0;
#endif
#ifdef __MSCVER
x = 1;
#endif
return x;
}
By default Cppcheck will try to check all the configurations. There are 3 important configurations here:
* Neither `__GNUC__` nor `__MSCVER` is defined
* `__GNUC__` is defined
* `__MSCVER` is defined
When you run Cppcheck, the output will be something like:
$ cppcheck test.c
Checking test.c ...
[test.c:10]: (error) Uninitialized variable: x
Checking test.c: __GNUC__...
Checking test.c: __MSCVER...
Now if you want you can limit the analysis. You probably know what the target compiler is. If `-D` is supplied and you do not specify `--force` then Cppcheck will only check the configuration you give.
$ cppcheck -D __GNUC__ test.c
Checking test.c ...
Checking test.c: __GNUC__=1...
### Unused templates
If you think Cppcheck is slow and you are using templates, then you should try how it works to remove unused templates.
Imagine this code:
template <class T> struct Foo {
T x = 100;
};
template <class T> struct Bar {
T x = 200 / 0;
};
int main() {
Foo<int> foo;
return 0;
}
Cppcheck says:
$ cppcheck test.cpp
Checking test.cpp ...
[test.cpp:7]: (error) Division by zero.
It complains about division by zero in `Bar` even though `Bar` is not instantiated.
You can use the option `--remove-unused-templates` to remove unused templates from Cppcheck analysis.
Example:
$ cppcheck --remove-unused-templates test.cpp
Checking test.cpp ...
This lost message is in theory not critical, since `Bar` is not instantiated the division by zero should not occur in your real program.
The speedup you get can be remarkable.
### Check headers
TBD
## Misra