Main Content

Fix Polyspace Compilation Errors Related to Diab Compiler

If you choose diab for the option Compiler (-compiler), 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

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.

  • restrict keyword:

    You typically use the compiler flag -Xlibc-new or -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 vector type 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, bool and 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 packed keyword.