Project Settings - Static Analysis Light

Overview

Static analysis in EcoStruxure Machine Expert means that before a project can be downloaded to the target system without build errors, the source code is searched for deviations from certain coding directives. To this purpose, a set of rules to be respected can be configured in the project settings. An automatic verification, according to those defined rules, is performed at code generation.

The results of the analysis are displayed as errors in the Messages view with the prefix SA.

NOTE: The analysis is only performed on the application code in the project. Libraries are not considered. For GVL (global variable list) variables, if there are multiple applications in the project, only the objects below the active one are analyzed. If there is only one application, the objects in the common pool of POUs are analyzed.

Unused variables (SA0033):

Detect variables, which are declared, but not used within the compiled program code.

Overlapping memory areas (SA0028):

Detect an allocation of two or more variables to the same memory location.

For example, this occurs if there are the following declarations: var1 AT %QB21: INT and var2 AT %QD5: DWORD. In this case, both variables use byte 21 that is the memory areas of the variables overlap.

Write access from several tasks (SA0006):

Detect variables which are written by more than 1 task.

Example (SA0006):

FUNCTION_BLOCK ADD_FB
g_iTemp1 := g_iTemp1 + INT#1;
PROGRAM PLC_PRG  //controlled by MainTask
g_iTemp1 := g_iTemp1 + INT#2;
g_xTemp2 := g_iTemp1 > INT#10;
PROGRAM PLC_PRG_1  //controlled by SubTask
g_iTemp1 := g_iTemp1 - INT#3;
g_xTemp2 := g_iTemp1 < INT#-10;

Multiple write access on output (SA0004):

Detect outputs which are written at more than one position.

Example (SA0004):

VAR_GLOBAL
    g_xVar AT %QX0.0 : BOOL ; 
    g_iTest AT %QW0 : INT ;
END_VAR
PROGRAM PLC_PRG
IF iCondition < INT#0 THEN
    g_xVar := TRUE;
    g_iTest := INT#12;
END_IF
CASE iCondition OF
    INT#1:
        g_xVar := FALSE;
    INT#2:
        g_iTest := INT#11;
    ELSE
        g_xVar := TRUE;
        g_iTest := INT#9;
END_CASE

Multiple uses of identifiers (SA0027):

Detect multiple use of a name/identifier for a variable or object (POU) within the scope of a project.

The following cases are detected:

oThe name of an enumeration constant is the same as the one used in another enumeration in the application or in an included library.

oThe name of a variable is the same as the one of an object in the application or in an included library.

oThe name of a variable is the same as the one of an enumeration constant in the application or in an included library.

oThe name of an object is the same as the one of an object in the application or in an included library.

Example (SA0027):

PROGRAM PLC_PRG
VAR
ton : INT;     // error SA0027
END_VAR

The Standard.library is included in the project and provides the function block TON resulting in a multiple usage of a name.

Report temporary Function Block instances (SA0167):

The test detects function block instances that are declared as temporary variables. This applies to instances that are declared in a method, or in a function, or as VAR_TEMP, and that are therefore reinitialized in each processing cycle and for each POU call.

Example (SA0167):

PROGRAM PLC_PRG
VAR
END_VAR
VAR_TEMP
    yafb: AFB;
END_VAR
FUNCTION Fun : INT
VAR_INPUT
END_VAR
VAR
    funafb: AFB;
END_VAR
METHOD METH : INT
VAR_INPUT
END_VAR
VAR
    methafb: AFB;
END_VAR

NOTE: AFB is a function block.