Fix Polyspace Compilation Errors Related to Diab Compiler
If you choose diab for the option Compilation toolchain (Static analysis), you can encounter
this issue.
Issue
During Polyspace® analysis, you see an error related to a keyword specific to the Diab compiler. For instance, you see an error related to the restrict keyword.
Cause
You typically use a compiler flag to enable the keyword. The Polyspace analysis does not enable these keywords by default. You have to make Polyspace aware of your compiler flags.
The Polyspace analysis does not enable these keywords by default to prevent compilation errors. Another user might not enable the keyword and instead use the keyword name as a regular identifier. If Polyspace treats the identifier as a keyword, a compilation error will occur.
Solution
Define Compiler Flag for Polyspace Analysis
Use the command-line option -compiler-parameter in your Polyspace analysis as follows. You use this command-line option to make Polyspace aware of your compiler flags. In the user interface of the Polyspace desktop products, you can enter the command-line option in the field Other. You can enter the option multiple times.
The argument of -compiler-parameter depends on the keyword that causes the error. Once you enable the keyword, do not use the keyword name as a regular identifier. For instance, once you enable the keyword pixel, do not use pixel as a variable name. The statement int pixel = 1 causes a compilation error.
restrictkeyword:You typically use the compiler flag
-Xlibc-newor-Xc-new. For your Polyspace analysis, use-compiler-parameter -Xc-new
The following code will not compile with Polyspace unless you specify the compiler flag.
int sscanf(const char *restrict, const char *restrict, ...);
PowerPC AltiVec vector extensions such as the
vectortype qualifier:You typically use the compiler flag
-tPPCALLAV:. For your Polyspace analysis, use-compiler-parameter -tPPCALLAV:
The following code will not compile with Polyspace unless you specify the compiler flag.
vector unsigned char vbyte; vector bool vbool; vector pixel vpx; int main(int argc, char** argv) { return 0; }Extended keywords such as
pascal,inline,packed,interrupt,extended,__X,__Y,vector,pixel,booland others:You typically use the compiler flag
-Xkeywords=. For your Polyspace analysis, use-compiler-parameter -Xkeywords=0xFFFFFFFF
The following code will not compile with Polyspace unless you specify the above option:
packed(4) struct s2_t { char b; int i; } s2; packed(4,2) struct s3_t { char b; } s3; int pascal foo = 4; int main(int argc, char** argv) { foo++; return 0; }Note that the Polyspace option only allows the code to be compiled. The analysis does not fully support the semantics behind the
packedkeyword.
Avoid Unsupported Language Extensions
Polyspace static analysis tools do not support these Diab compiler features:
The preprocessor directives
#assertand#unassert. Your code compiles but the software does not interpret these directives semantically.Single-character constants in
#ifdirectives having the same value as the same character constant in the execution character set. Your code compiles but Polyspace does not consider that the character constants have the same value.The extended
sizeof()syntax using two arguments. For example,sizeof(char, 2). Your code does not compile with Polyspace when you use this feature.Statement expressions. For example,
({int y; y=foo(); y;}). Your code does not compile with Polyspace when you use this feature.The use of regular expressions with the
definedpreprocessor operator. For example#if defined ("BSP_HW*"). Your code does not compile with Polyspace when you use this feature.