No warning given for uninitialized volatile variable
Nobody has claimed this yet.
- Dominant language
- Ada
- Stars
- 328
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
volatile_package.ads:
package Volatile_Package with SPARK_Mode => On
is
type Index_Type is range 192 .. 210; -- Some small, arbitrary range
Package_Variable : Index_Type with Volatile;
end Volatile_Package;
volatile_uninit.adb:
with Ada.Text_IO;
with Volatile_Package;
procedure Volatile_Uninit with SPARK_Mode => On
is
type Array_Type is array (Volatile_Package.Index_Type) of Integer;
Local_Array : constant Array_Type := (others => 15); -- Some arbitrary value
Local_Index_Variable : Volatile_Package.Index_Type;
Local_Integer : Integer;
begin
Local_Index_Variable := Volatile_Package.Package_Variable;
Local_Integer := Local_Array (Local_Index_Variable);
Ada.Text_IO.Put_Line ("Value of Local_Integer: " & Local_Integer'Image);
end Volatile_Uninit;
Running Spark:
alr gnatprove --assumptions
on the above code does not give any warning nor state in gnatprove.out that Volatile_Package.Package_Variable is assumed to be initialized. If I understand, Spark makes this assumption due to Async_Writers being implicitly true for Package_Variable and Spark RM 7.1.2 Rule 14 applying.
I would have expected Spark to warn that it is making this assumption to alert the user and prompt manual review, since incorrect usage can lead to undefined behavior/erroneous execution as in the case above:
alr build --release
alr run
Garbage output:
Value of Local_Integer: 1413566023
Versions:
gnat FSF: 14.2.1
gnatprove: 14.1.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the case in volatile_package.ads and volatile_uninit.adb with gnatprove --assumptions, then inspect gnatprove.out for the missing initialization warning. Review the stated interaction between Async_Writers and Spark RM 7.1.2 Rule 14. Done means the tool clearly reports when it assumes Package_Variable is initialized, with appropriate coverage for this example.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100