We are trying to hide preprocessor code from being checked by cppcheck(As seeing more execution time for cppcheck to expand & validate the preprocessor code). But that is not working as expected. So created a sample code and attached to this thread to demonstrate.
hmm.. Cppcheck expects that -I points out a include path. I assume Cppcheck would find the bug if the parameter is: -IC:\Users\Desktop\Cppcheck\Include
Maybe we need to adapt Cppcheck to handle this strange iccarm command line parameter better..
Last edit: Daniel Marjamäki 2021-12-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With the --project option it is reporting an error. Actually, we are trying to hide a group of macros that are defined in some header files and these macros included in all source files. These macros get assigned with a unique constant value at the preprocessing stage. We observed these header files causing more time execution for cppcheck. But the above hiding a piece of code is not working for us(You can see our conversation here - https://sourceforge.net/p/cppcheck/discussion/general/thread/83bb029837/?limit=25&page=1#174f).
Please clarify below points:
1. Is it because of preprocessing stage doing by cppcheck?
2. Is there a way to know preprocessing execution time for every file?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I feel that it's unlikely that it's the preprocessor itself that takes much time.
If you run like this:
./cppcheck --showtime=summary .. file
then cppcheck will print some timing statistics. I believe the preprocessing is covered by item "Tokenizer::createTokens". If you look at the bottom is says "Overall time:".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
From above data, It is evident that removing those included paths from database file is saving so much time.
Another surprise is if I run with --file-filter for a single source file the overall time it is showing negligible and for the same file it is taking 9 sec if I run with complete database file.
Removing a included paths from database file is not reporting some of the real errors and hiding those macros using -D not saving time.
Any suggestion is helpful.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
PFA for overall summary when run cppcheck passing database file as it is and when removing 2 included paths(-I) which havig the bunch of macros defined header files.
Observed Tokenizer::simplifyTokens1 is taking 13 mins in first case. What stage it is? Can be able to optimize this?
-D method is not saving the time and removing the included paths from database file is not reporting the some actual cppcheck errors
Looking forward for optimized solution by analysing the attached timing summary.
Observed Tokenizer::simplifyTokens1 is taking 13 mins in first case. What stage it is? Can be able to optimize this?
Feel free to profile.
The Tokenizer::simplifyTokens1 is one of the most heavy functions in Cppcheck. It is known that most of the time is spent in that.
its the whole conversion from "raw tokens from preprocessor" to "full cppcheck data" that happens in that stage.
During Tokenizer::simplifyTokens1 it runs valueflow and simplifytypedef and setvarid and creates symboldatabase and ast.. and more.. so more than half of that 796s is accounted for in the other items.. but there are ~200s if I count correctly that are not accounted for and I am not sure what it might do during those 200s. There are various other transformations.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi @danielmarjamaki,
We are trying to hide preprocessor code from being checked by cppcheck(As seeing more execution time for cppcheck to expand & validate the preprocessor code). But that is not working as expected. So created a sample code and attached to this thread to demonstrate.
I'm running the below command
cppcheck.exe --enable=warning --enable=style --quiet --language=c --enable=performance --xml --inline-suppr --suppress=preprocessorErrorDirective -iC:\Users\Desktop\Cppcheck\private -DCPPCHECK_TEST .\Cppcheck\
In the attachment there is a main.h which includes the following piece of code
As i'm using the -DCPPCHECK_TEST with cppcheck here i'm expecting it should report OVERFLOW error. But it's not happening.
Same checked with 2.4 & 2.6 versions.
Thanks
If you don't use the OVERFLOW macro then no warning is written. Cppcheck preprocesses the code.
Hi @danielmarjamaki,
Thanks for the reply.
But that was using in main.c
This command is strange:
-IC:\Users\Desktop\Cppcheck\Include\main.h
hmm.. Cppcheck expects that -I points out a include path. I assume Cppcheck would find the bug if the parameter is:
-IC:\Users\Desktop\Cppcheck\Include
Maybe we need to adapt Cppcheck to handle this strange iccarm command line parameter better..
Last edit: Daniel Marjamäki 2021-12-03
Hi @danielmarjamaki,
I have fixed include path and tried, still not reporting overflow error.
Please find the attachment.
command that I have used -
cppcheck.exe --enable=warning --enable=style --quiet --language=c --enable=performance --xml --inline-suppr --suppress=preprocessorErrorDirective -iD:\Cppcheck\private -DCPPCHECK_TEST D:\Cppcheck\
Thanks
ok I was confused I thought the json file was imported..
Can you please add a
-I
so the main.h file is found.Hi @danielmarjamaki,
In the json file main.h path was added already.
Last edit: Krishna 2021-12-03
If you intend to use json file.. remove the
D:\Cppcheck
from the command and add--project=config.json
.. something like:Hi @danielmarjamaki,
With the --project option it is reporting an error. Actually, we are trying to hide a group of macros that are defined in some header files and these macros included in all source files. These macros get assigned with a unique constant value at the preprocessing stage. We observed these header files causing more time execution for cppcheck. But the above hiding a piece of code is not working for us(You can see our conversation here - https://sourceforge.net/p/cppcheck/discussion/general/thread/83bb029837/?limit=25&page=1#174f).
Please clarify below points:
1. Is it because of preprocessing stage doing by cppcheck?
2. Is there a way to know preprocessing execution time for every file?
Thanks.
I feel that it's unlikely that it's the preprocessor itself that takes much time.
If you run like this:
then cppcheck will print some timing statistics. I believe the preprocessing is covered by item "Tokenizer::createTokens". If you look at the bottom is says "Overall time:".
Hi @danielmarjamaki,
Here is the overall summary of our code with cppcheck
It is evident that Tokenizer::simplifyTokens1 taking 13 mins approximately.
However if I remove the 2 included paths from database file path(-I based) which have defined many macros, following is the overall cppcheck summary
From above data, It is evident that removing those included paths from database file is saving so much time.
Another surprise is if I run with --file-filter for a single source file the overall time it is showing negligible and for the same file it is taking 9 sec if I run with complete database file.
Removing a included paths from database file is not reporting some of the real errors and hiding those macros using -D not saving time.
Any suggestion is helpful.
Thanks
Hi @danielmarjamaki,
PFA for overall summary when run cppcheck passing database file as it is and when removing 2 included paths(-I) which havig the bunch of macros defined header files.
Observed Tokenizer::simplifyTokens1 is taking 13 mins in first case. What stage it is? Can be able to optimize this?
-D method is not saving the time and removing the included paths from database file is not reporting the some actual cppcheck errors
Looking forward for optimized solution by analysing the attached timing summary.
Thanks.
Feel free to profile.
The Tokenizer::simplifyTokens1 is one of the most heavy functions in Cppcheck. It is known that most of the time is spent in that.
its the whole conversion from "raw tokens from preprocessor" to "full cppcheck data" that happens in that stage.
During Tokenizer::simplifyTokens1 it runs valueflow and simplifytypedef and setvarid and creates symboldatabase and ast.. and more.. so more than half of that 796s is accounted for in the other items.. but there are ~200s if I count correctly that are not accounted for and I am not sure what it might do during those 200s. There are various other transformations.