Main Content

Fix Polyspace Compilation Errors Related to Keil or IAR Compiler

Missing Identifiers

If you use the compiler, keil or iar, you can encounter this issue. For more information on the Polyspace® option for compiler specification, see Compilation toolchain (Static analysis).

Issue

The analysis stops with the error message, expected an identifier, as if an identifier is missing. However, in your source code, you can see the identifier.

Cause

If you select Keil or IAR as your compiler, the software removes certain keywords during preprocessing. If you use these keywords as identifiers such as variable names, a compilation error occurs.

For a list of keywords that are removed, see Keil or IAR Language Extensions Supported with Polyspace.

Solution

Specify that Polyspace must not remove the keywords during preprocessing. Define the macros __PST_KEIL_NO_KEYWORDS__ or __PST_IAR_NO_KEYWORDS__.

For more information, see Preprocessor definitions (-D).

Unsupported Constructs

If you use the compiler, iar-ew, you can encounter issues because of missing support for specific language extensions. For more information on the Polyspace option for compiler specification, see Compilation toolchain (Static analysis).

  • Polyspace does not support the use of $Super$$ and $Sub$$ to patch symbol definitions. For instance, the following code compiles correctly, but Polyspace considers that main() calls the extern func ($Super$$func) instead of the function func defined in this code ($Sub$$func):

    /* void func() declared in another file */
    extern void $Super$$func(int i);
    
    int setup = 0;
    
    void setup_func(int i) {
      setup = i;
    }
    
    /* this function should be called instead of the original extern func() */
    void $Sub$$func(int i) {
      setup_foo(i); 
      /* does some extra setup work */   
      /* ... */
    }
    
    int main() {
      assert(setup = 0);
      func(1); // Should call $Sub$$func instead of $Super$$func
      assert(setup = 1);
      return 0;
    }
    To make sure that Polyspace calls the correct function when analyzing your code, replace all instance of $Sub$$ with an empty string in all your files after preprocessing. See Command/script to apply to preprocessed files (-post-preprocessing-command).

  • Polyspace does not support some constructs specific to the IAR compiler.

    For the list of unsupported constructs, see codeprover_limitations.pdf in polyspaceroot\polyspace\verifier\code_prover_desktop. Here, polyspaceroot is the MATLAB® installation folder, for instance, C:\Program Files\Polyspace\R2019a.