The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathW orks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern
theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand
Documentation by the federal government (or other entity acquiring for or through the federal government)
and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the
government’s needs or is inconsistent in any respect with federal procurement law, the government agrees
to return the Program and Docu mentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2009Online OnlyRevised for Version 5.3 (Release 2009a)
September 2009 Online OnlyRevised for Version 5.4 (Release 2009b)
March 2010Online OnlyRevised for Version 5.5 (Release 2010a)
Products for Ada Reference
Option Descriptions
1
General Options ...................................1-2
Overview
Session identifier
Date
Author
Project version
Keep all preliminary results files
Report Generation
Report template name
Output format
Report name
-sources “list_of_files”
-extensions-for-spec-files and -ada-include-dir
-results-dir folder
........................................1-2
..................................1-2
............................................1-4
..........................................1-5
....................................1-6
.....................1-7
.................................1-8
.............................1-8
....................................1-8
.....................................1-9
.............................. 1-10
.......... 1-11
.................................1-12
Contents
Target and Compiler Options
Target processor type
Operating syste m target for Stand a rd Libraries
compatibility
Command/script to apply before start of the code
verification
Command/script to apply after the end of the code
verification
Compliance with Standards Option s
Value of the constant Storage_Unit
Remove compariso n operators ambiguities
Analysis Mode
PolySpace Inner Settings Options
Run a verification unit by unit
Unit common source
Name of the main subprogram
Generate a main
Assumptions
Run verification in 32 or 64-bit mode
Other options
.....................................1-32
................. 1-36
.....................................1-36
Precision Options
Launch code verification from beginning of
To end of
Precision Level
Specific Precision
Max size of global array variables
Improve precision of interprocedural analysis
List of variables to expand
Expansion limit for a structured variable
Multitasking Options (PolySpace Server Only)
Implicit Tasks
Critical section details
Temporal exclusion tasks (separated by space
characters)
Batch Options
-server server_name_or_ip[:port_number]
-h[elp]
-v | -version
-sources-list-file file_name
........................................ 1-41
........................................... 1-55
..................................1-38
............. 1-39
...................................1-43
..................................1-45
.................... 1-46
.......... 1-47
.......................... 1-49
.............. 1-50
....................................1-52
............................. 1-53
.....................................1-54
.....................................1-55
.............. 1-55
......................................1-56
.......................... 1-56
....... 1-52
ivContents
Check Descriptions
2
Colored Source Code for Ada .......................2-2
Non-Initialized Variable: NIV/NIVL
Division by Zero: ZDV
Arithmetic Exceptions: EXCP
Scalar and Float Underflow/Overflow : U OVFL
Scalar and Float Overflow: OVFL
Scalar and Float Underflow: UNFL
Attributes Check: COR
Array Length Check: COR
..............................2-7
............................. 2-15
.......................... 2-17
..................2-3
.......................2-8
......... 2-11
.................... 2-12
................... 2-13
DIGITS Value Check: COR .........................2-19
DELTA Value Length Check: COR
Static Range and Values Check: COR
Discriminant Check: COR
Component Check: COR
Dimension Versus Definition Check: COR
Aggregate Versus Definition Check: COR
Aggregate Array Length Check: COR
Sub-Aggregates Dimension Check: COR
Characters Check: COR
Accessibility Level on Access Type: COR
Explicit Dereference of a Null Pointer: COR
Accessibility of a Tagged Type: COR
Power Arithmetic: POW
User Assertion: ASRT
Non Terminations: Calls and Loops
Unreachable Code: UNR
Value on Assignment: VOA
Inspection Points: IPT
3 From the Date format drop-down list, choose the format that you want.
Command-Line Information
Parameter: date
Type: string
Value: any valid value in
Default: Date on which you launch verification
Shell script example:
dd/mm/yyyy format
polyspace-ada -date "02/01/2002"
1-4
See Also
“Creating a Project” in PolySpace Products for Ada documentation
Author
Specify author o
Settings
Default: user
Command-Line Information
f verification
ID
General Options
Parameter: a
Type: string
Value: any valid value
Default: us
Shell script example:
uthor
er ID
polyspace-ada -author "A. Tester"
See Also
“Creating a Project” in PolySpace Products for Ada documentation
1-5
1 Option Descriptions
Project version
Specify version ID for verification
Settings
Default: 1.0
• Use this parameter to help you identify verifications.
Command-Line Information
Parameter:verif-version
Type: string
Value: any v
Default:
Shell script example: polyspace-ada -verif-version 1.3
See Also
“Creating a Project” in PolySpace Products for Ada documentation
alid value
1.0
1-6
General Options
Keep all p reliminary results files
Specify whether to retain all intermediate results and associated working files.
Settings
Default: Off
On
Retain all intermediate results and associated working files. You can
restart a verification from the end of any complete pass if the source
code remains unchanged.
Off
Erase all intermediate results and associated working files. If you want
to restart a verification, do so from the beginning.
Tips
• This option is applicable only to client verifications. Intermediate results
are always removed before results are downloaded from the PolySpace
server.
• To cleanup intermediate files at a later time, you can select Tools > Clean
Results in the Launcher. This option deletes the preliminary result files
For Linux and Solaris, you can also use the form file1[ file2[ . ..]] for
list_of_files.
1-10
For example,
polyspace-ada -sources "my_folder/mod*.ad[sb]"
With the preceding syntax, the software analyzes only Ada files with the
extensions
.(A|a)d(a|b|s)
However, you can analyze Ada files with other extensions. If you also have,
for example, files with the
-sources "./sources/*.a*,./sources/*.sep"
.sep extension, you can use the following syntax:
To analyse Ada files with any extension, use the following syntax:
-sources "./sources/*.*"
Default: sources/*.(A|a)d(a|b|s)
For specifying files in batch mode, see “-so urce s-lis t-file file_name” on page
1-56.
General Options
-extensions-for-spec-files and -ada-include-dir
The -extensions-for-specs-files option specifies the file extension for files "F"
which are verified to get the type and variables names but which are not
part of the -sources list.
The result of speci fying this option is similar to having a dictionary with
only the list of words and their type (verb, noun, adj) without the definition.
These files allow the product to know the name and the type, but not the
values (dictionary definitions).
The -ada-include-dir specifies the folder where the F files are. Howev er, you
canusetheoptionseveraltimesandyoucanspecifymorethanonefolder.
Note Use both options together.
Benefits:
• Fastercompilationonthesepackages to focus on the -sources packages
specifications and bodies
• Full range for all constants defined in these packages. Consider 1 package
body B and 2 specifications S1 and S2 in the following examples.
Usage examples using the graphical interface:
configuration 1:
• -sources contains B.ada and S1.ada
• -extensions-for-specs-files contains the *.ada filter
• -ada-include-dir contains the TEST folder and the TEST folder contains
S2.ada
configuration 2:
• -sources contains B.ada, S1.ada, S2.ada
• If you use a constant S2.C:
1-11
1 Option Descriptions
- configuration 1: its value is its full range
- configuration 2: its value is the real constant value
This option specifies the folder in which PolySpace writes the results of the
verification. Although you may specify relative folders, be careful with their
use, especially if the tool launches remotely over a network, and when a
project configuration file is copied using the "Save as" option.
“Setting Up a Target” in PolySpace Products for Ada documentation
Target and Compiler Options
Operating system target for Standard Libraries
compatibility
Specify operating system target for which there are implementation-specific
declarations in the Ada Standard Libraries
Settings
PolySpace supplies only gnat include files, which you can find in the ada
include folder within the installation folder. You can verify projects with other
operating systems by using the corresponding include files (not supplied). For
instance, to verify a
• If you are running PolySpace s oftw are Version 5.1 (r2008a) or later on a
Windows system, you cannot use Cygwin ™ shell scripts. Cygwin is no
longer included with PolySpace software, so all files must be executable by
Windows. To support scripting, the PolySpace installation includes Perl.
You can acces s Perl using:
• If you are running PolySpace software Version 5.1 (r2008a) or later on
a Windows system, you cannot use Cygwin she ll scripts. Cygwin is no
longer included with PolySpace software, so all files must be executable by
Windows. To support scripting, the PolySpace installation includes Perl.
You can acces s Perl using:
Specify l ist of files to include with each unit verification
Settings
No Default
• Compile files in the list once, and then link to each unit before verification.
• Stub functions not included in the list.
Command-Line Information
Parameter: unit-by-unit-common-source
Type: string
Value: any valid file name
Shell script example:
c:/polyspace/function.adb
polyspace-ada -unit-by-unit-common-source
1-26
Name of the main subprogram
Specifies the name of the main subprogram
Settings
No Default
• Verify procedure after package elaboration, and before tasks (for a
multi-task application or if
• Cannot be used with the
Command-Line Information
Parameter: main
Shell script example: polyspace-ada -main mainpackage.init
See Also
“Verifying an Application Without a “Main”” in PolySpace Products for Ada
documentation
-entry-points option is specified).
main-generator option.
PolySpace®Inner Settings Options
Generate a main
Specifies whether to automatically generate a main program.
The generated
main program:
• Calls only procedures and functions that are specified in a package.
PolySpace software assigns random, initialized values to all
in and in out
parameters for these procedures and functions.
• Assigns values to global variables that are specified in a package. If a
global variable is initialized in a specification, then PolySpace softw are
assigns this variable a random, initialized value. If a global variable is
not initialized, PolySpace software assigns the global variable a random,
possibly uninitialized, value (specifying the
init-stubbing-vars-random
or init-stubbing-vars-zero-or-random parameters has no effect).
This behavior models the fact that the variable can be changed outside
the package.
• Assigns values to global variables that are declared in a package
body. If a global variable is initialized in a package body, then
PolySpace software assigns this variable a random , initialized value.
If a global variable is not initiali zed, PolySpace software leaves it
uninitialized except when you specify the
init-stubbing-vars-random
or init-stubbing-vars-zero-or-random parameters. In this case, the
variable is assigned a random, initialized value.
This behavior models the fact that the variable can only be changed inside
the package, but the functions of the package can be called several times.
You cannot use this option with the
main option.
Settings
Default: On for PolySpace®Client™; Off for PolySpace®Server™
On
Create a procedure that calls every uninvoked procedure in the code.
Deactivates
main option for PolySpace Server.
1-27
1 Option Descriptions
Off
Selected by PolySpace Client if
main option is activated
Command-Line Information
Parameter: main-generator
Shell script examples:
polyspace-ada -main-generator ...
polyspace-desktop-ada ... (implicit -main-generator active)
polyspace-desktop-ada -main myPack.main ...
(implicit -main-generator canceled by the usage of -main)
See Also
“Initialization of uninitialized global variables” on page 1-32 in Products for
Ada documentation
1-28
Stubbing
• “Treat import as non volatile” on page 1-29
• “Treat export as non volatile” on page 1-30
• “No automatic stubbing” on page 1-31
• “Initialization of uninitialized global variables” on page 1-32
Treatimportasnonvolatile
Specify whether pragma import variable is volatile
See Also. “Stubbing” and “Volatile Variables” in Products for Ada
documentation
export-are-not-volatile
1-30
PolySpace®Inner Settings Options
No automatic stubbing
Specify whether to stub a procedure or function without a body, to allow
verification.
Settings. Default: Off
On
A procedure or function that has n o body (a function that you declare
but do not define) stops verification. Use this option when you want to :
• Make sure that all code is supplied, for example, when verifying a
large piece of code.
• Write stubs yourself, to increase the selectivity and speed of
verification
Off
Stub all procedures and functions automatically according to these rules:
• The generated stub is the most general body derived from its
prototype.
• Implicit and explicit tasks are not stubbed.
• The
main procedure is not stubbed.
• The generated stubs do not have side-effects on global variables. If a
function affects global variables, then stub this function manually.
Dependency. This parameter cannot be used with Initialization of
uninitialized global variables (
-init-stubbing-vars-zero-or-random).
-init-stubbing-vars-random or
Command-Line Information.
Parameter:
-no-automatic-stubbing
Type: string
Value:
on | off
Default: off
Shell script example: polyspace-ada -no-automatic-stubbing
See Also. “Stubbing” in PolySpace Products for Ada d ocumentatio n
1-31
1 Option Descriptions
Initialization of uninitialized global variables
Specify how uninitialized global variables are initialized.
Settings. Default:
The following setting descriptions apply only when the -main-generator
option (Generate a main check box) is not selected. For information on
how the settings apply when you select the
“Generate a main” on page 1-27.
No initialization
Uninitialized global variables produce warning s or errors. No values
assigned.
With random value
Assign random values to uninitialized global variables.
With zero or random value
Assign zero to uninitialized global variables if the type contains zero.
Otherwise, assign random values.
See Also. “Stubbing” in PolySpace Products for Ada d ocumentatio n
Assumptions
• “Continue after non initialized variables” on page 1-33
• “Continue with non-initialzed in/out parameters” on page 1-33
• “Ignorefloatrounding”onpage1-34
• “Procedures known to cause NTC” on page 1-35
PolySpace®Inner Settings Options
Continue after non initialized variables
Specify whether verification detects all non-initialized variables
Settings. Default: Off
On
Detect all non-initialized variables (NIV). In the following code, the
software detects all three NIVs in the first verification run.
procedure Main is
I,T,No: Integer;
begin
if (No = 0)-- red NIV, with or without option
then
I := 1/I;-- red NIV with option, grey otherwise
end if;
if (T = 0)-- red NIV with option, grey otherwise
then
I := 12312409 /120;
end if;
end Main;
You lose precision when using this option. Use this option only for the
first verification run of a project.
Off
Verification stops after the first red non-initialized variable (NIV).
Command-Line Information.
Parameter:
continue-with-all-niv
Continue with non-initialzed in/out parameters
Specify whether to continue with verification if in and out parameters of a
procedure are not initialized.
Settings. Default: Off
1-33
1 Option Descriptions
On
In Ada, the
in and out parameters of a procedure must be initialized.
With this option, if the software detects one of the parameters as
a red NIV, then subsequent code is not declared unreachable (the
software does not color the code gray). The red error does not affect
the verification.
procedure test(x : in out Integer) is
begin
x := 10;
end
procedure main is
T : integer;
begin
test(T);-- red NIV on T with or without the option
See Also. “Float Rounding” in PolySpace Products for Ada documentation
Procedures known to cause NTC
Filter known non-terminating calls (NTC) to functions
Settings. Default: Empty. All NTCs appear as red errors.
• There can be functions that "never terminate". Some functions, such as
tasks and threads, contain infinite loops by design, while functions that
halt the program, such as
often stubbed by an infinite loop. If there are many of these functions, or
you want to present results to a third party, you may want to filter certain
types of NTCs in the Viewer. Specify these NTCs before a verification.
They appear in the Viewer within the known-NTC category.
Command-Line Information.
Parameter:
known-NTC
Type: string
Value: any valid value, for example,
Default: Empty
• PolySpace supplies these flags, which depend on your verification
requirements.
• Use
ada95-extra-flags for Ada95 only.
Command-Line Information
Parameter:extra-flags | ada95-extra-flags
Value: Supplied by PolySpace but depend on your requirements
Default: None
See Also
“Preparing Source Code for Verification” in PolySpace Products for Ada
documentation
1-37
1 Option Descriptions
Precision Op tions
In this section...
“Launch code verificat ion from beginning of” on page 1-39
“Toendof”onpage1-41
“Precision Level” on page 1-43
“Specific Precision” o n page 1-45
“Max size of global array variables” on page 1-46
“Improve precision of interprocedural analysis” on page 1-47
“List of variables to expand” on page 1-49
“Expansion limit for a structured variable” on page 1-50
1-38
Precision Options
Launch code verification from beginning of
Specify starting point of verification
Settings
• Use with the to option.
• Use only on a verification that you have run partially, to specify the
restart point of the verification. For example, if you have previously run
a verification to
restart the verification at this point. You do not have to run the verification
from
scratch.
• Use only for client-based verification (server-based verification always
starts from
• Use only for restarting a verification launched w ith the option
keep-all-files (unless you restart from scratch).
• You cannot use this option if you modify the source code between
verifications.
Software Safety Analysis level 1 (pass1 ), you can
scratch).
Default:
scratch
scratch
The starting point for a new verification
Source Compliance Checking
Correspondstothecommand-lineoptioncompile
Control and Data Flow Analysis
Corresponds to the command-line option pass0 or CDFA
Software Safety Analysis level 1
Corresponds to the command-line option pass1
Software Safety Analysis level 2
Corresponds to the command-line option pass2
Software Safety Analysis level 3
Corresponds to the command-line option pass3
Software Safety Analysis level 4
Corresponds to the command-line option pass4
1-39
1 Option Descriptions
Other
For levels greater than pass4 but less than pass20
Command-Line Information
Parameter: from
Type: string
Value:
| other
Default: scratch
Shell s cript example: polyspace-ada -from pass0
“Reducing Orange Checks in Your Results” in PolySpace Products for Ada
documentation
1-45
1 Option Descriptions
Max s ize of global array variables
Force PolySpace software to verify each cell of global variable arrays as a
separate variable, if length is less than or equal to threshold value
Settings
Default: 3
• Threshold value.
• Increasing the number o f global variables to verify affects verification time.
• Affects only Global Data Dictionary results.
Command-Line Information
Parameter: array-expansion-size
Value: any valid value
Default:
Shell script example: polyspace-ada -O1 -array-expansion-size 8
3
1-46
See Also
“Expansion of Sizes” in PolySpace Products for Ada documentation
Precision Options
Improve precision of interprocedural analysis
Improve inter-procedural verification precision within a pass
Settings
The propagation of information within procedures happens earlier than
usual with this option, which results in improved selectivity but a longer
verification time.
Consider two cases, one where you set this option (
to 1, and another where you do not set this option, that is, the o ption value is
• A level 1 verification with this option set provides results equivalent to a
level 1 or 2 verification without the option.
• A level 1 verification with this option set can be many times longer than a
cumulative level 1 and 2 verification without the option.
Thesameeffectandresultsapplytoalevel 2 verification with this option set.
A level 2 verification is equivalent to a level 3 or 4 verification without the
option. Verification time also increases correspondingly.
Using this option results in the following:
• The highest selectivity is achieved in level 2, so you do not need to wait
until level 4.
• Verification time can increase exponentially and result in an even
longer verification time than that forthecumulativelevel1,2,3,and4
verification.
Use this option only for packages with fewer than 1000 lines of code.
Default:
0
-path-sensitivity-delta)
0.
Command-Line Information
Parameter: path-sensitivity-delta
Value: any valid value
Default:
eparing Multitasking Code” in PolySpace Products for Ada documentation
“Pr
Batch Options
In this section...
“-server server_name_or_ip[:port_number]” on page 1-55
“-h[elp]” on page 1-55
“-v | -version” on page 1-56
“-sources-list-file file_name” on page 1-56
-server server_name_or_ip[:port_number]
Using polyspace-remote[-desktop]-[ada] [ server [name or IP
address][:<port number>]]
referenced PolySpace server.
Note If you do not specify the option server, the default server referenced
in the
Batch Options
allows you to send a verification to a specific or
PolySpace-Launcher.prf configuration file is used a s the server.
When you use the server option in the batch launching command, you must
specify the name or IP address and a port number. If the port number does
not exist, the 12427 value is used as the default.
“Scalar and Float Underflow/Overflow : UOVFL” on page 2-11
“Scalar and Float Overflow: OVFL” on page 2-12
“Scalar and Float Underflow: UNFL” on page 2-13
“Attributes Check: COR” on page 2-15
“Array Length Check: COR” on page 2-17
“DIGITS Value Check: COR” on page 2-19
“DELTA Value Length Check: COR” on page 2-20
“Static Range and Values Check: COR” on page 2-21
2-2
“Discriminant Check: COR” on page 2-23
“Component Check: COR” on page 2-24
“Dimension Versus Definition Check: COR” on page 2-25
“Aggregate Versus Definition Check: COR” on page 2-26
“Aggregate Array Length Check: COR” on page 2-28
“Sub-Aggregates Dimension Check: COR” on page 2-29
“Characters Check: COR” on page 2-30
“Accessibility Level on Access Type: COR” on page 2-32
“Explicit D erefere nce of a Null Pointer: COR” on page 2-33
“Accessibility of a Tagged Type: CO R ” on page 2 -3 4
“Power Arithmetic: POW ” on page 2-36
“User Assertion: ASRT” on page 2-37
“Non Terminations: Calls and Loops” on page 2-39
“Unreachable Code: UNR” on page 2-49
Colored Source Code for Ada
In this section...
“Value on Assignment: VOA” on page 2-51
“Inspection Points: IPT” on page 2-53
Non-Initialized Variable: NIV/NIVL
Check to establish whether a variable is initialized before being read.
Examples
Ada Example.
1package NIV is
2type Pixel is
3record
4X : Integer;
5Y : Integer;
6end record;
7procedure MAIN;
8function Random_Bool return Boolean;
9end NIV;
10
11package body NIV is
12
13type TwentyFloat is array (Integer range 1.. 20) of Float;
14
15procedure AddPixelValue(Vpixel : Pixel) is
16Z : Integer;
17begin
18if (Vpixel.X<3)then
19Z := Vpixel.Y + Vpixel.X; -- NIV error: Y field
20 not initialized
21end if;
22end AddPixelValue;
23
24procedure MAIN is
25B : Twentyfloat;
26Vpixel : Pixel;
2-3
2 Check Descriptions
27begin
28if (Random_Bool) then
29Vpixel.X :=1;
30AddPixelValue(Vpixel); -- NTC Error: because of NIV error
31in call
32end if;
33
34for I in 2 .. Twentyfloat'Last loop
35if ((I mod 2) = 0) then
36B(I) := 0.0;
37end if;
38end loop;
39B(2) := B(4) +B(5); -- NIV Warning because
40 B(odd) not initialized
41end MAIN;
42
43end NIV;
Explanation. The result of the addition is unknown at line 19 because
Vpixel.Y is not initialized (gray code on "+" operator). In addition, line 37
shows how PolySpace prompts theusertoinvestigatefurther(orange NIV
warning on B(I)) when all fields have not been initialized.
2-4
NIV Check vs. IN O UT Parameter Mode. Standard Ada83 says: For
a scalar parameter, the above effects are achieved by copy: at the start of
each call, if the mode is in or in out, the value of the actual parameter is
copied into the associated formal parameter; then after normal completion
of the subprogram body, if the mode is in out or out, the value of the formal
parameter is copied back into the associated actual parameter.
Clearly, in out parameters necessitate initialization before call.
Ada Example.
1package NIVIO is
2procedure MAIN;
3function Random_Boolean return Boolean;
4end NIVIO;
5
6package body NIVIO is
Colored Source Code for Ada
7
8Y : Integer := 3;
9procedure Niv_Not_Dangerous(X : in out integer) is
10begin
11X := 2;
12if (Y > 2) then
13Y := X+3;
14end if ;
15end Niv_Not_Dangerous;
16
17procedure Niv_Dangerous(X : in out integer) is
18begin
19if (Y /= 3) then
20Y := X+3;
21end if ;
22end Niv_Dangerous;
23
24procedure MAIN is
25X : Integer;
26begin
27if (Random_Boolean) then
28Niv_Dangerous(X); -- NIV ERROR: certainly dangerous
29end if ;
30if (Random_Boolean) then
31Niv_Not_dangerous(X); -- NIV ERROR: not dangerous
32End if ;
33end MAIN;
34
35end NIVIO;
Explanation. Inthepreviousexample,asshownatline28,PolySpace
highlights a dangerous non-initialized variable. Even if it is not dangerous, as
shown in the Niv_Not_Dangerous procedure, PolySpace also highlights the
non-initialized variable at line 30. To be more permissive with standard, the
-continue-with-in-out-niv option permits to continuation of the verification
for the rest of the sources even if a red error stays in place a t lines 28 and 31.
Pragma Interface/Import
The following table illustrates how variables are regarded when:
In this case, a permanent random value means that the variable is always
equivalent to the full range of its type. It is almost equivalent to a volatile
variable except for the color of the NIV.
Integer Variable
Types
• No NIV check
• Permanent random
value
Function
• same behavior as -
automatic-stubbing
• in/out and out
variables are
written within
their entire type
range
Type Access Variables
The following table illustrates how variables are verified by PolySpace when
a type access is used:
Type a_new_type is
access another_type;
Records and Other
Variable Types
• orange NIV
• Permanent random
value
Integer Variable
Types
• No NIV check
• Permanent random
value
2-6
In this case, a Permanent Random Variable is exactly equivalent to a volatile
variable - that is, it is assumed that the value can have been changed to
anywhere within its whole range between one read access and the next.
Colored Source Code for Ada
Address Clauses
The following table illustrates how variables are regarded by PolySpace
where an address clause is used.
Address ClauseRecords and
Other Variable
Types
for variable_name'address use
16#1234abcd#;
for
variable_name'other'address
use;
• orange NIV
• Permanent
random value
In this case, a Permanent Random Variable is exactly equivalent to a pvolatile
variable - that is, it is assumed that the value can have been changed to
anything within its whole range between one read access and the next.
Integer Variable
Types
• No NIV check
• Permanent
random value
Division by Zero: ZDV
Check to establish whether the right operand of a division (denominator) is
different to 0[.0].
Ada Example:
1package ZDV is
2function Random_Bool return Boolean;
3procedure ZDVS (X : Integer);
4procedure ZDVF (Z : Float);
5procedure MAIN;
6end ZDV;
7
8package body ZDV is
9
10procedure ZDVS(X : Integer) is
11I : Integer;
12J : Integer := 1;
13begin
14I := 1024 / (J-X); -- ZDV ERROR: Scalar Division by Zero
15end ZDVS;
2-7
2 Check Descriptions
16
17procedure ZDVF(Z : Float) is
18I : Float;
19J : Float := 1.0;
20begin
21I := 1024.0 / (J-Z); -- ZDV ERROR: float Division by Zero
22end ZDVF;
23
24procedure MAIN is
25begin
26if (random_bool) then
27ZDVS(1); -- NTC ERROR: ZDV.ZDVS call never terminates
28end if ;
29if (Random_Bool) then
30ZDVF(1.0); -- NTC ERROR: ZDV.ZDVF call never terminates
31end if;
32end MAIN;
33
34end ZDV;
35
36
37
2-8
Arithmetic Exceptions: EXCP
Check to establish whether standard arithmetic functions are used with good
arguments:
• Argument of sqrt must be positive
• Argument of tan must be different from pi/2 modulo pi
• Argument of log must be strictly positive
• Argument of acos and asin must be within [-1..1]
• Argument of exp must be less than or equal to a specific value which
depends on the processor target: 709 for 64/32 bit targets and 8 8 for 16 bit
targets
Basically, an error occurs if an input argument is outside the domain over
which the mathematical function is defined.
Colored Source Code for Ada
Ada Example
1
2With Ada.Numerics; Use Ada.Numerics;
3With Ada.Numerics.Aux; Use Ada.Numerics.Aux;
4
5package EXCP is
6function Bool_Random return Boolean;
7procedure MAIN;
8end EXCP;
9
10package body EXCP is
11
12-- implementation dependant in Ada.Numerics.Aux: subtype
Double is Long_Float;
13M_PI_2 : constant Double := Pi/2.0; -- pi/2
14
15procedure MAIN is
16IRes, ILeft, IRight : Integer;
17Dbl_Random : Double;
18pragma Volatile_ada.htm (dbl_Random);
19
20SP : Double := Dbl_Random;
21P : Double := Dbl_Random;
22SN : Double := Dbl_Random;
23N : Double := Dbl_Random;
24NO_TRIG_VAL : Double := Dbl_Random;
25res : Double;
26Fres : Long_Float;
27begin
28-- assert is used to redefine range values of a variable.
29pragma assert(SP > 0.0);
30pragma assert(P >= 0.0);
31pragma assert(SN < 0.0);
32pragma assert(N <= 0.0);
33pragma assert(NO_TRIG_VAL < -1.0 or NO_TRIG_VAL > 1.0);
34
35if (bool_random) then
36res := sqrt(sn); -- EXCP ERROR: argument of SQRT must be
positive.
2-9
2 Check Descriptions
37end if ;
38if (bool_random) then
39res := tan(M_PI_2);
-- EXCP Warning: Float argument of TAN
40-- may be different than pi/2 modulo pi.
41end if;
42if (bool_random) then
43res := asin(no_trig_val); --EXCP ERROR: float argument of
ASIN is not in -1..1
44end if;
45if (bool_random) then
46res := acos(no_trig_val); --EXCP ERROR: float argument of
ACOS is not in -1..1
47end if;
48if (bool_random) then
49res := log(n); -- EXCP ERROR: float argument of LOG is not
strictly positive
50end if;
51if (bool_random) then
52res := exp(710.0); -- EXCP ERROR: float argument of EXP
is not less than or equal to 709 or 88
53end if;
54
55-- range results on trigonometric functions
56if (Bool_Random) then
57Res := Sin (dbl_random); -- -1 <= Res <= 1
58Res := Cos (dbl_random); -- -1 <= Res <= 1
59Res := atan(dbl_random); -- -pi/2 <= Res <= pi/2
60end if;
61
62-- Arithmetic functions where there is no check currently
implemented
63if (Bool_Random) then
64Res := cosh(dbl_random);
65Res := tanh(dbl_random);
66end if;
67end MAIN;
68end EXCP;
2-10
Colored Source Code for Ada
Explanation
The arithmetic functions sqrt, tan, sin, cos, asin, acos, atan and log are
derived d irectly from mathematical definitions of functions.
Standard cosh and tanh hyperbolic functions are currently assumed to return
the full range of values mathematically possible, regardless of the input
parameters. The Ada83 standard gives more details about domain and range
error for each maths function.
Scalar and Float Under flow/Overflow : UOVFL
Check to simultaneously establish whetheranarithmeticexpressionona
float value overflows and/or underflows.
Ada Example
1 package UOVFL is
2function Bool_Random return Boolean;
3procedure MAIN;
4 end UOVFL;
5
6 package body UOVFL is
7
8procedure MAIN is
9I : Integer;
10DValue : Long_float;
11begin
12if (Bool_Random) then
13I := 2**30;
14I :=2* (I-1); --integer UOVFL verified on "*" and "-"
PolySpace can detect that there is neither an underflow nor an overflow on *
and - operators at lines 16 and 18.
Scalar and Float Overflow: OVFL
Check to es tablish whether an arithmetic expression overflows. This is a
scalar check with integer types and a flo at check for floating point expressions.
An overflo w is also detected should an array index_ada.htm be out of bounds.
Ada Example
1package OVFL is
2procedure MAIN;
3function Bool_Random return Boolean;
4end OVFL;
5
6package bodyOVFLis
7
8procedure OVFL_ARRAY is
9A : array(1..20) of Float;
10J : Integer;
11begin
12for I in A'First .. A'Last loop
13A(I) :=0.0;
14J := I+1;
15end loop;
16A(J) := 0.0; -- OVFL ERROR: Overflow array index_ada.htm
17end OVFL_ARRAY;
18
19procedure OVFL_ARITHMETIC is
20I : Integer;
21FValue : Float;
22begin
23
24if (Bool_Random) then
25I := 2**30;
26I:=2* (I-1) +2 ; -- OVFL ERROR: 2**31 is an overflow
2-12
Colored Source Code for Ada
value for Integer
27end if;
28if (Bool_Random) then
29FValue := Float'Last;
30FValue := 2.0 * FValue + 1.0; -- OVFL ERROR: float
variable is overflow
31end if;
32end OVFL_ARITHMETIC;
33
34procedure MAIN is
35begin
36if (Bool_Random) then OVFL_ARRAY; end if; -- NTC
propagation because of OVFL ERROR
37if (Bool_Random) then OVFL_ARITHMETIC; end if;
38end MAIN;
39
40end OVFL;
41
42
Explanation
In Ada, the bounds of an array can be considered with reference to a new type
or subtyp e of an existing one. Line 16 shows an overflow error resulting from
an attempt to access element 21 in an a rray subtype of range 1..20.
Adifferentexampleisshownbytheoverflowonline26,whereadding
1toInteger’Last (the maximum integer value being 2**31-1 ona32bit
architecture platform). Similarly, if OVFL_ARITHMETIC.FValue represents
the max floating value, 2*FValue cannot be represented with the s ame type
andsoraisesanoverflowatline30.
Scalar and Float Under flow: UNFL
Check to establish whether an arithmetic expression underflows. This is a
scalar check with integer types and a flo at check for floating point expressions.
An underflow is also d etected should an array index_ada.htm be out of bounds.
2-13
2 Check Descriptions
Ada Example
1package UNFL is
2function Bool_Random return Boolean;
3procedure MAIN;
4end UNFL;
5
6package bodyUNFLis
7
8procedure UNFL_ARRAY is
9A : array(1..20) of Float;
10J : Integer;
11begin
12for I in A'Last.. A'First loop
13A(I):=0.0;
14J := I-1;
15end loop;
16A(J) := 0.0; -- UNFL ERROR: underflow array index_ada.htm
17end UNFL_ARRAY;
18
19procedure UNFL_ARITHMETIC is
20I : Integer;
21FValue : Float;
22begin
23
24if (Bool_Random) then
25I := -2**31;
26I := I - 1 ; -- UNFL ERROR: -2**31-1 is integer underflow
27end if;
28if (Bool_Random) then
29FValue := Float'First;
30FValue := -2.0 * FValue; -- UNFL ERROR: float variable is
overflow
31end if;
32end UNFL_ARITHMETIC;
33
34procedure MAIN is
35begin
36if (Bool_Random) then UNFL_ARRAY; end if;
-- NTC propagation because of UNFL ERROR
2-14
Colored Source Code for Ada
37if (Bool_Random) then UNFL_ARITHMETIC; end if;
38end MAIN;
39
40 end UNFL;
Explanation
In Ada, the bounds of an array can be considered with reference to a new type
or subtype of an existing one. Line 16 shows an underflow error resulting
from an attempt to access element 0 in an array subtype of range 1..20.
A different example is shown by the underflow on line 26, where subtracting
1fromInteger’First (the minimum integer value being -2**31-1 on a 32 bit
architecture platform). Similarly, if UNFL_ARITHMETIC.FValue represents
the minimum floating value, -2*FValue cannot be represented with the same
type and so raises an underflow at line 30.
Attributes Check: COR
PolySpace encourages the user to investigate the attributes SUCC, PRED,
VALUE an d SIZE further, thanks to a COR check (failure of CORrectness
condition).
Ada Example
1
2package CORS is
3function Bool_Random return Boolean;
4procedure MAIN;
5function INT_VALUE (S : String) return Integer;
6type PSTCOLORS is (ORANGE, RED, GREY, GREEN);
7type ADCFUZZY is (LOW, MEDIUM, HIGH);
8end CORS;
9
10package body CORS is
11
12type STR_ENUM is (AA,BB);
13
14function INT_VALUE (S : String) return Integer is
15X : Integer;
2-15
2 Check Descriptions
16begin
17X := Integer'Value (S); -- COR Warning: Value parameter
might not be in range integer
18return X;
19end INT_VALUE;
20
21procedure MAIN is
22E : PSTCOLORS := GREEN;
23F : PSTCOLORS;
24ADCVAL : ADCFUZZY := ADCFUZZY'First;
25StrVal : STR_ENUM;
26X : Integer;
27begin
28if (Bool_Random) then
29F := PSTCOLORS'PRED(E); -- COR Verified: Pred attribute
is not used on the first element of pstcolors
30E := PSTCOLORS'SUCC(E); -- COR ERROR: Succ attribute is
used on the last element of pstcolors
31end if;
32if (Bool_Random) then
33ADCVAL := ADCFUZZY'PRED(ADCVAL); -- COR ERROR: Pred
attribute is used on the first element of adcfuzzy
34end if ;
35
36StrVal := STR_ENUM'Value ("AA"); -- COR Warning: Value
parameter might not be in range str_enum
37StrVal := STR_ENUM'Value ("AC"); -- COR Warning: Value
parameter might not be in range str_enum
38X := INT_VALUE ("123"); --X info: -2**31<=[expr]<=2**31-1
39end MAIN;
40end CORS;
41
2-16
Explanation
At line 36 and 37, the COR warning (orange) prompts the user to check
whether the VALUE attribute is correct or not.
In fact, standard ADA generates a "CONSTRAINT_ERROR" exception when
the string does not correspond to one of the possible values of the type.
Colored Source Code for Ada
Also note that in this case, PolySpace results assume the full possible range of
the returned type, regardless of the input parameters. In this example, strVal
has a range in [aa,bb] and X in [Integer’First, Integer’Last].
The incorrect use of PRED and SUCC attributes on type is indicated by
PolySpace.
SIZE Attribute Error: COR
1
2with Ada.Text_Io; use Ada.Text_Io;
3
4package SIZE is
5PROCEDURE Main;
6end SIZE;
7
8PACKAGE BODYSIZEIS
9
10TYPE unSTab is array (Integer range <>) of Integer;
11
12PROCEDURE MAIN is
13X : Integer;
14BEGIN
15X := unSTab'Size; -- COR ERROR: Size attribute must not be
used for unconstrained array
16Put_Line (Integer'Image (X));
17END MAIN;
18
19END SIZE;
Explanation
At line 15, PolySpace shows the error on the SIZE attribute. In this case, it
cannot be used on an unconstrained array.
Array Length Check: COR
Checks the correctness condition of a n array length, including Strings.
2-17
2 Check Descriptions
Ada Example
1
2with Dname;
3package CORL is
4function Bool_Random return Boolean;
5type Name_Type is array (1 .. 6) of Character;
6procedure Put (C : Character);
7procedure Put (S : String);
8procedure MAIN;
9end CORL;
10
11package body CORL is
12
13STR_CST : constant NAME_TYPE := "String";
14
15procedure MAIN is
16Str1,Str2,Str3 : String(1..6);
17Arr1 : array(1..10) of Integer;
18begin
19
20if (Bool_Random) then
21Str1 := "abcdefg"; -- COR ERROR: Too many elements in
array must have 6
22end if;
23if (Bool_Random) then
24Arr1 := (1,2,3,4,5,6,7,8,9); -- COR ERROR: Not enough
elements in array, must have 10
25end if ;
26if (Bool_Random) then
27Str1 := "abcdef";
28Str2 := "ghijkl";
29Str3 := Str1 & Str2; -- COR Warning: Length might not be
compatible with 1 .. 6
30Put(Str3);
31if Bool_Random then
32DName.DISPLAY_NAME (DNAME.NAME_TYPE(STR_CST));
-- COR ERROR: String Length is not correct, must be 4
33end if;
34end if ;
2-18
Colored Source Code for Ada
35end MAIN;
36
37end CORL;
38
39package DName is
40type Name_Type is array (1 .. 4) of Character;
41PROCEDURE DISPLAY_NAME (Str : Name_Type);
42end DName;
43
Explanation
At lines 21 and 24, PolySpace gives the exact value needed to match the two
arrays. On the other hand, PolySpace prompts the user to investigate the
compatibility of concatenated arrays, by means of an orange check at line 29.
Moreover at line 32, the string length is being put forward even if it depends
on another package.
DIGITS Value Check: COR
Checks the length of DIGITS constructions.
Ada Example
1package DIGIT is
2procedure MAIN;
3end DIGIT;
4
5package body DIGIT is -- NTC ERROR: COR propagation
6
7type T is digits 4 range 0.0 .. 100.0;
8subtype T1 is T
9digits 1000 range 0.0 .. 100.0; -- COR ERROR: digits value
is too large, highest possible value is 4
10
11procedure MAIN is
12begin
13null;
14end MAIN;
2-19
2 Check Descriptions
15end DIGIT;
Explanation
At line 9, PolySpace shows an error on the digits value. It indicates in its
associated message the highest available value, 4 in this case.
DELTA Value Length Check: COR
Checks the length of DELTA constructions.
Ada Example
1
2 package FIXED is
3procedure MAIN;
4procedure FAILED(STR : STRING);
5function Random return Boolean;
6 end FIXED;
7
8 package body FIXED is
9
10PROCEDURE FIXED_DELTA IS
11
12GENERIC
13TYPE FIX IS DELTA <>;
14PROCEDURE PROC (STR : STRING);
15
16PROCEDURE PROC (STR : STRING) IS
17SUBTYPE SFIX IS FIX DELTA 0.1 RANGE -1.0 .. 1.0; -- COR
ERROR: delta is too small, smallest possible value is 0.5E0
At line 17, PolySpace Server shows an error on the DELTA va lue. The
message gives the smallest available value, 0.5 in this case.
Static Range and Values Check: COR
Checks if constant values and variable values correspond to their range
definition and construction.
Ada Example
1
2 package SRANGE is
3procedure Main;
4function IsNatural return Boolean;
5
6SUBTYPE INT IS INTEGER RANGE 1 .. 3;
7TYPE INF_ARRAY IS ARRAY(INT RANGE <>, INT RANGE <>) OF INTEGER;
8SUBTYPE DINT IS INTEGER RANGE 0 .. 10;
9 end SRANGE;
10
11 package body SRANGE is
12
2-21
2 Check Descriptions
13TYPE SENSOR IS NEW INTEGER RANGE 0 .. 10;
14
15TYPE REC2(D : DINT := 1) IS RECORD -- COR Warning: Value
might not be in range
1..3
16U : INF_ARRAY(1 .. D, D .. 3) := (1..D=>
17(D .. 3 => 1));
18END RECORD;
19TYPE REC3(D : DINT := 1) IS RECORD -- COR Error: Value is
not in range 1 .. 3
20U : INF_ARRAY(1 .. D, D .. 3) := (1 .. D =>
21(D .. 3 => 1));
22END RECORD;
23
24PROCEDURE VALUE_RANGE is
25VAL : INTEGER;
26pragma Volatile(VAL);
27SLICE_A2 : REC2(VAL); -- NIV and COR warning: Value might
not be in range 0 ..
10
28SLICE_A3 : REC3(4); -- Unreacheable code: because of COR
Error in REC3
29BEGIN
30NULL;
31END VALUE_RANGE;
32
33PROCEDURE MAIN is
34Digval : Sensor;
35begin
36if IsNatural then
37declare
38TYPE Sub_sensor is new Natural range -1 .. 5; -- COR
Error: Static value is not in range of 0 .. 16#7FFF_FFFF#
39begin
40null;
41end;
42end if;
43if IsNatural then
44declare
45TYPE NEW_ARRAY IS ARRAY (NATURAL RANGE <>) OF INTEGER;
2-22
Colored Source Code for Ada
46subtype Sub_Sensor is New_Array (Integer RANGE -1 .. 5);
-- COR Error: Static range is not in range 0 .. 16#7FFF_FFFF#
47begin
48null;
49end;
50end if ;
51if IsNatural then
52VALUE_RANGE; -- NTC Error: propagation of the COR error
in VALUE_RANGE
53else
54Digval := 11; -- COR Error: Value is not in range of 0..10
55end if;
56END Main;
57 end SRANGE;
58
59
Explanation
PolySpace checks the compatibility between range and value. Moreover, it
tells in its associated message the expected length.
Example is shown on the record types RE C2 and REC3. PolySpace cannot
determine the exact value of the volatile variable VAL at line 27, because
some paths lead to a safe definition, others to a red one. The results is an
orange warning at line 15.
At lines 19, 38, 46 and 54 PolySpace displays errors on out of range values.
Discriminant Check: COR
Checks the usage of a discriminant in a record declaration.
Ada Example
1
2package DISC is
3PROCEDURE MAIN;
4
5TYPE T_Record(A: Integer) is record -- COR Verified: Value
2-23
2 Check Descriptions
is in range of 1 .. 16#7FFF_FFFF#
6Sa: String(1..A);
7END RECORD;
8end DISC;
9
10package body DISC is
11
12PROCEDURE MAIN is
13begin
14declare
15T_STRING6 : T_RECORD(6) := (6, "abcdef"); --COR Verified:
Discriminant is compatible
16T_StringOther : T_RECORD(6); -- COR Verified:
Discriminant is compatible
17T_STRING5 : T_RECORD(5) := (5, "abcde"); -- COR Verified:
Discriminant is compatible
18begin
19T_StringOther := T_STRING6; -- COR Verified: Discriminant
is compatible
20T_string5 := T_Record(T_STRING6); -- COR ERROR:
Discriminant is not compatible
21end;
22END Main;
23
24END DISC;
2-24
Explanation
At line 20, PolySpace shows an error while using a discriminant. T_String6
discriminant of length 6 cannot match T_String5 discriminant of length 5.
Component Check: COR
Checks whe ther each component of a record given is being used accurately.
Ada Example
1package COMP is
2
3PROCEDURE MAIN;
Colored Source Code for Ada
4SUBTYPE DINT IS INTEGER RANGE 0..1;
5TYPE COMP_RECORD ( D : DINT := 0) is record
6X : INTEGER;
7CASE D IS
8WHEN 0 => ZERO : BOOLEAN;
9WHEN 1 => UN : INTEGER;
10END CASE;
11END RECORD;
12
13end COMP;
14
15package body COMP is
16
17PROCEDURE MAIN is
18CZERO : COMP_RECORD(0);
19BEGIN
20CZERO.X :=0;
21CZERO.ZERO := FALSE; -- COR Verified: zero is a component
of the variable
22CZERO.UN := CZERO.X; -- COR ERROR: un is not a component
of the variable
23END MAIN;
24END COMP;
25
Explanation
At line 22, PolySpace Server shows an error. According to the declaration of
CZERO (line 18), UN is not a valid field record component of the variable.
Dimension Versus Definition Check: COR
Checks the compatibility of array dimension in relation to their definition.
Ada Example
1package DIMDEF is
2PROCEDURE MAIN;
3FUNCTION Random RETURN boolean;
4end DIMDEF;
2-25
2 Check Descriptions
5
6package body DIMDEF is
7
8SUBTYPE ST IS INTEGER RANGE 4 .. 8;
9TYPE BASE IS ARRAY(ST RANGE <>, ST RANGE <>) OF INTEGER;
10SUBTYPE TBASE IS BASE(5 .. 7, 5 .. 7);
11
12FUNCTION IDENT_INT(VAL : INTEGER) RETURN INTEGER IS
13BEGIN
14RETURN VAL;
15END IDENT_INT;
16
17PROCEDURE MAIN IS
18NEWARRAY : TBASE;
19BEGIN
20IF RANDOM THEN
21NEWARRAY := (7 .. IDENT_INT(9) => (5 .. 7 => 4)); -COR Error: Dimension is not compatible with definition
22END IF;
23IF Random THEN
24NEWARRAY := (5 .. 7 => (IDENT_INT(3) .. 5 => 5)); -COR Error: Dimension is not compatible with definition
25END IF;
26END MAIN;
27
28END DIMDEF;
2-26
Explanation
At lines 21 and 24, PolySpace Server indicates the incorrect dim ension of the
double array Newarray of type TBASE.
Aggregate Versus Definition Check: COR
Checks the correctness condition on aggregatedeclarationinrelationto
their definition.
Ada Example
1
Colored Source Code for Ada
2package AGGDEF is
3PROCEDURE MAIN;
4PROCEDURE COMMENT (A: STRING);
5function RANDOM return BOOLEAN;
6end AGGDEF;
7
8package body AGGDEF is
9
10TYPE REC1 (DISC : INTEGER := 5) IS RECORD
11NULL;
12END RECORD;
13
14TYPE REC2 (DISC : INTEGER) IS RECORD
15NULL;
16END RECORD;
17
18TYPE REC3 is RECORD
19COMP1 : REC1(6);
20COMP2 : REC2(6);
21END RECORD;
22
23FUNCTION IDENT_INT(VAL : INTEGER) RETURN INTEGER IS
24BEGIN
25RETURN VAL;
26END IDENT_INT;
27
28PROCEDURE AGGDEF_INIT is -- AGGREGATE INITIALISATION
29OBJ3 : REC3;
30BEGIN
31if random then
32OBJ3 :=
33((DISC => IDENT_INT(7)), (DISC => IDENT_INT(7))); -COR ERROR: Aggregate is not compatible with definition
34end if;
35IF OBJ3 = ((DISC => 7), (DISC => 7)) then -- COR ERROR:
Aggregate is not compatible with definition
36COMMENT ("PREVENTING DEAD VARIABLE OPTIMIZATION");
37END IF;
38END AGGDEF_INIT;
39
2-27
2 Check Descriptions
40PROCEDURE MAIN IS
41BEGIN
42AGGDEF_INIT; -- NTC ERROR: propagation of COR ERROR
43END MAIN;
44end AGGDEF;
Explanation
At lines 33 and 35, PolySpace indicates the incompatible aggregate
declaration on OBJ3. The aggregate definition with a discriminant of value 6,
is not compatible with a discriminant of value 7.
Aggregate Array Length Check: COR
Checks the length for array aggregate.
Ada Example
1package AGGLEN is
2PROCEDURE MAIN;
3PROCEDURE COMMENT(A: STRING);
4end AGGLEN;
5
6package body AGGLEN is
7
8SUBTYPE SLENGTH IS INTEGER RANGE 1..5;
9TYPE SL_ARR IS ARRAY (SLENGTH RANGE <>) OF INTEGER;
10
11F1_CONS : INTEGER := 2;
12FUNCTION FUNC1 RETURN INTEGER IS
13BEGIN
14F1_CONS := F1_CONS - 1;
15RETURN F1_CONS;
16END FUNC1;
17
18
19TYPE CONSR (DISC : INTEGER := 1) IS
20RECORD
21FIELD1 : SL_ARR (FUNC1 .. DISC); -- FUNC1 EVALUATED.
22END RECORD;
2-28
Colored Source Code for Ada
23
24PROCEDURE MAIN IS
25
26BEGIN
27DECLARE
28TYPE ACC_CONSR IS ACCESS CONSR;
29X : ACC_CONSR;
30BEGIN
31X := NEW CONSR;
32BEGIN
33IF X.ALL /= (3, (5 => 1)) THEN -- COR ERROR: Illegal
Length for array aggregate
34COMMENT ("IRRELEVANT");
35END IF;
36END;
37END;
38END MAIN;
39
40END AGGLEN;
Explanation
At line 33, PolySpace shows an error. The static aggregate length is not
compatible with the definition of the component FIELD1 at line 21.
Sub-Aggregates Dimension Check: COR
Checks the dimension of sub-aggregates.
Ada Example
1
2package SUBDIM is
3PROCEDURE MAIN;
4FUNCTION EQUAL ( A : Integer; B : Integer) return Boolean;
5end SUBDIM;
6
7package body SUBDIM is
8
9
2-29
2 Check Descriptions
10TYPE DOUBLE_TABLE IS ARRAY(INTEGER RANGE <>, INTEGER
RANGE <>) OF INTEGER;
11TYPE CHOICE_INDEX IS (H, I);
12TYPE CHOICE_CNTR IS ARRAY(CHOICE_INDEX) OF INTEGER;
13
14CNTR : CHOICE_CNTR := (CHOICE_INDEX => 0);
15
16FUNCTION CALC (A : CHOICE_INDEX; B : INTEGER)
17RETURN INTEGER IS
18BEGIN
19CNTR(A) := CNTR(A) + 1;
20RETURN B;
21END CALC;
22
23PROCEDURE MAIN IS
24A1 : DOUBLE_TABLE(1 .. 3, 2 .. 5);
25BEGIN
26CNTR := (CHOICE_INDEX => 1);
27if (EQUAL(CNTR(H),CNTR(I))) then
28A1 := ( -- COR ERROR: Sub-agreggates do not
have the same dimension
291 => (CALC(H,2) .. CALC(I,5) => -4),
302 => (CALC(H,3) .. CALC(I,6) => -5),
313 => (CALC(H,2) .. CALC(I,5) => -3) );
32END IF;
33END MAIN;
34
35end SUBDIM;
2-30
Explanation
At line 28, PolySpace shows an error. One of the sub-aggregates declarations
of A1 is not compatible with its definition. The second sub-aggregates does
not respect the dimension defined at line 24.
Sub-aggregates must be singular.
Characters Check: COR
Checks the construction using the character type.
Colored Source Code for Ada
Ada Example
1
2package CHAR is
3procedure Main;
4function Random return Boolean;
5end CHAR;
6
7
8package bodyCHARis
9
10type ALL_Char is array (Integer) of Character;
11TYPE Sub_Character is new Character range 'A' .. 'E';
12TYPE TabC is array (1 .. 5) of Sub_Character;
13
14FUNCTION INIT return character is
15VAR : TabC := "abcdf"; -- COR Error: Character is not in
range 'A' .. 'E'
16begin
17return 'A';
18end;
19
20procedure MAIN is
21Var : ALL_Char;
22BEGIN
23IF RANDOM THEN
24Var(1) := Init; --NTC ERROR: propagation of the COR err
25ELSE
26Var(Integer) := ""; -- COR ERROR: the 'null' string
literal is not allowed here
27END IF;
28END MAIN;
29END CHAR;
Explanation
At line 15, PolySpace indicates that the assigned array is not within the range
of the Sub_Character type. Moreover, any of the character values of VAR does
not match any value in the range ’A’ ..’E’.
2-31
2 Check Descriptions
At line 26, a particular detection is made by PolySpace when the null string
literal is assigned incorrectly.
Accessibility Level on Access Type: COR
Checks the accessibility level on an access type. This check is defined in Ada
Standard at chapter 3.10.2-29a1. It detects errors when an access pointer
refers to a bad reference.
Ada Example
1
2package CORACCESS is
3procedure main;
4function Brand return Boolean;
5end CORACCESS;
6
7package body CORACCESS is
8procedure main is
9
10type T is new Integer;
11type A is access all T;
12Ref : A;
13
14procedure Proc1(Ptr : access T) is
15begin
16Ref := A(Ptr); -- COR Verified: Accessibility level deeper
than that of access type
17end;
18
19procedure Proc2(Ptr : access T) is
20begin
21Ref := A(Ptr); -- COR ERROR: Accessibility level not
deeper than that of access type
22end;
23
24procedure Proc3(Ptr : access T) is
25begin
26Ref := A(Ptr); -- COR Warning: Accessibility level might
be deeper than that of access type
2-32
Colored Source Code for Ada
27end;
28
29X : aliased T := 1;
30begin
31declare
32Y : aliased T := 2;
33begin
34Proc1(X'Access);
35if BRand then
36Proc2(Y'Access); -- NTC ERROR: propagation of error
at line 22
37elsif BRand then
38Proc3(Y'Access); -- NTC ERROR: propagation of error
at line 27
39end if;
40end;
41Proc3(X'Access);
42end main;
43end CORACCESS;
44
Explanation
In the example above at line 16: Ref is set t o x’access and Ref is defined in
same block or in a deeper one. This is authorized.
On the other hand, y is not defined in a block deeper or inside the one in
which Ref is defined. So, at the end of block, y does not exist any more and
Ref is supposed to points to on y . It is prohibited and PolySpace checks at
lines 21 and 26.
Note The warning at line 26 is due to the combination of a red check because
of y’access at line 38 and a green one for x’access at line 41.
Explicit Dereference of a Null Pointer: COR
When a pointer is dereferenced, PolySpace checks whether or not it is a null
pointer.
2-33
2 Check Descriptions
Ada Example
1package CORNULL is
2procedure main;
3end CORNULL;
4
5package body CORNULL is
6type ptr_type is access all integer;
7ptr : ptr_type;
8A : aliased integer := 10;
9
10procedure main is
11begin
12ptr := A'access;
13if (ptr /= null) then
14ptr.all := ptr.all + 1; -- COR Warning: Explicit
dereference of possibly null value
15pragma assert (ptr.all = 10); -- COR Warning: Explicit
dereference of possibly null value
16null;
17end if;
18end main;
19end CORNULL;
20
2-34
Explanation
At line 14 and line 15, PolySpace checks the null value of ptr pointer. As
PolySpace does not perform pointer verification, it is not able to be precise on
such a construction.
These checks are currently always orange.
Accessibility of a Tagged Type: COR
Checks if a tag belongs to a tagged type hierarchy . This check is defined in
Ada Standard at chapter 4.6 (paragraph 42).
It detects errors w h en a Tag of an operand does not refer to class-wide
inheritance hierarchy.
Colored Source Code for Ada
Ada Example
1package TAG is
2
3type Tag_Type is tagged record
4C1 : Natural;
5end record;
6
7type DTag_Type is new Tag_Type with record
8C2 : Float;
9end record;
10
11type DDTag_Type is new DTag_Type with record
12C3 : Boolean;
13end record;
14
15procedure Main;
16
17end TAG;
18
19
20package body TAG is
21
22procedure Main is
23Y : DTag_Type := DTag_Type'(C1 => 1, C2 => 1.1);
24Z : DTag_Type := DTag_Type'(C1 => 2, C2 => 2.2);
25
26W : Tag_Type'Class := Z;-- W can represent any object
27-- in the hierarchy rooted at Tag_Type
28begin
29Y := DTag_Type(W); -- COR Warning: Tag might be correct
30null;
31end Main;
32
33end TAG;
Explanation
In the previous example W represents any object in the hierarchy rooted
at Tag_Type.
2-35
2 Check Descriptions
At line 29, a check is made that the tag of W is either a tag of DTag_Type or
DDTag_Type. In this example, the check should be green, W belongs to the
hierarchy.
PolySpace is not precise on tagged typ es and currently always flags each one
with a COR warning.
Power Arithmetic: POW
Check to establish whether the standard power integer or float function is
used with an acceptable (positive) argument.
Ada Example
1With Ada.Numerics; Use Ada.Numerics;
2With Ada.Numerics.Aux; Use Ada.Numerics.Aux;
3
4package POWF is
5function Bool_Random return Boolean;
6procedure MAIN;
7end POWF;
8
9package bodyPOWFis
10
11procedure MAIN is
12IRes, ILeft, IRight : Integer;
13Res, Dbl_Random : Double ;
14pragma Volatile(Dbl_Random);
15begin
16-- Implementation of Power arithmetic function with **
17if (Bool_Random) then
18ILeft :=0;
19IRight := -1;
20IRes:= ILeft ** IRight; -- POW ERROR: Power must
be positive
21end if;
22if (Bool_Random) then
23ILeft :=-2;
24IRight := -1;
25IRes:= ILeft ** IRight; -- POW ERROR: Power must
2-36
Colored Source Code for Ada
be positive
26end if;
27
28ILeft :=2e8;
29IRight :=2;
30IRes:= ILeft ** IRight; -- otherwise OVFL Warning
31
32-- Implementation with double
33Res := Pow (dbl_Random, dbl_Random); -- POW Warning :
may be not positive
34end MAIN;
35end POWF;
Explanation
An error occurs on the power function on integer values "**" with respect
to the values of the left and right parameters when left <= 0 and right < 0.
Otherwise,PolySpacepromptstheusertoinvestigatefurtherbymeansof
an orange check.
Note As recognized by the Standard, PolySpace places a green check on the
instruction left**right with left:=right:=0.
User Assertion: ASRT
Check to establish whether a user assertion is valid. If the assumptions
implied by an assertion are invalid, then the standard behavior of the
pragma assert is to abort the program. PolySpace therefore considers a failed
assertion to be a runtime error.