Code analysis (Static Analysis)

Before a project is loaded onto the target system, TwinCAT 3 PLC uses "Static Code Analysis" to check whether the source code follows specified coding guidelines.

The license-free version of the static code analysis is called "Static Analysis Light". The checks configured in the analysis function are performed automatically whenever code is generated. Further information can be found in section “Static Analysis Light”.

The licensed version of the static code analysis is the "Static Analysis", which has a greatly extended range of functions and configurations in comparison with the Light version. The static code analysis can be triggered manually or performed automatically during the code generation. Further information on this extension can be found in the documentation “TE1200 | TC3 PLC Static Analysis”.

Static Analysis Light vs. Static Analysis Full

An overview of the different features of the license-free and license-managed variants of Static Analysis is provided below.

Functional aspect

Static Analysis Light
(without TE1200 license)

Static Analysis Full
(with TE1200 license)

License required

No, usable free of charge

Yes, TE1200 license required

Save/export and load/import (rule) configuration

Not possible, coupled to PLC project properties

Possible

(using the Load/Save buttons in the Settings)

Execution is coupled to the compilation process

Yes, not configurable

Configurable

(using the Perform static analysis automatically option in the Settings;

Manual execution with the help of the command Command 'Run static analysis')

Checking for unused objects (e.g. within a library project)

Not possible

Possible

(with the help of the command Command 'Run static analysis [Check all objects]')

Maximum number of reported errors

500 (not configurable)

(Further information on the significance of 500 as the maximum number of errors can be found in the Settings)

Configurable

(using the setting Maximum number of errors in the Settings)

Maximum number of reported warnings

Output of warnings not possible (see following line)

Configurable

(using the setting Maximum number of warnings in the Settings)

Rules: Activation options

  • Active and output as error
  • Inactive
  • Active and output as error
  • Active and output as warning
  • Inactive

Rules: scope

7 coding rules

  • SA0033: Unused variables
  • SA0028: Overlapping memory areas
  • SA0006: Write access to multiple tasks
  • SA0004: Multiple writes access on output
  • SA0027: Multiple usage of name
  • SA0167: Report temporary FunctionBlock instances
  • SA0175: Suspicious operation on string

More than 100 coding rules

Rules: Precompile wavy underline, QuickFix

Not available

Available

Naming conventions

Not available

Available

Metrics

Not available

Available

Forbidden symbols

Not available

Available

Pragmas and attributes for temporary deactivation of rules

Yes, available in the Light scope:

  • Pragma {analysis ...}
  • Attribute {attribute 'no-analysis'}
  • Attribute {attribute 'analysis' := '...'}

Yes, available in full scope:

  • Pragma {analysis ...}
  • Attribute {attribute 'no-analysis'}
  • Attribute {attribute 'analysis' := '...'}
  • Attribute {attribute 'naming' := '...'}
  • Attribute {attribute 'nameprefix' := '...'}
  • Attribute {attribute 'analysis:report-multiple-instance-calls'}