Skip to content

Commit 8946543

Browse files
committed
Merge branch 'topic/1075-dross-precise-uc' into 'master'
Handle component always initialized in precise UC Issue: eng/spark/spark2014#1075 See merge request eng/spark/spark2014!2243
2 parents f64a6aa + 1e66c2d commit 8946543

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

src/why/gnat2why-unchecked_conversion.adb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,12 +647,14 @@ package body Gnat2Why.Unchecked_Conversion is
647647

648648
elsif Is_Record_Type (Typ) then
649649
declare
650-
Comps : constant Component_Sets.Set := Get_Component_Set (Typ);
651-
Assocs :
650+
Comps : constant Component_Sets.Set :=
651+
Get_Component_Set (Typ);
652+
Assocs :
652653
W_Field_Association_Array (1 .. Integer (Comps.Length));
653-
Flags :
654+
Flags :
654655
W_Field_Association_Array (1 .. Integer (Comps.Length));
655-
Index : Positive := 1;
656+
Index : Positive := 1;
657+
F_Index : Positive := 1;
656658
begin
657659
for Comp of Comps loop
658660
declare
@@ -670,9 +672,12 @@ package body Gnat2Why.Unchecked_Conversion is
670672
Field =>
671673
To_Why_Id (Comp, Local => False, Rec => Typ),
672674
Value => +F_Value.Value);
675+
Index := Index + 1;
673676

674-
if Do_Validity then
675-
Flags (Index) :=
677+
if Do_Validity
678+
and then not Comp_Has_Only_Valid_Values (Comp, Typ).Ok
679+
then
680+
Flags (F_Index) :=
676681
New_Field_Association
677682
(Domain => EW_Term,
678683
Field =>
@@ -682,9 +687,9 @@ package body Gnat2Why.Unchecked_Conversion is
682687
Rec => Base_Retysp (Typ),
683688
From_Tree => Validity_Tree),
684689
Value => +F_Value.Valid_Flag);
690+
F_Index := F_Index + 1;
685691
end if;
686692
end;
687-
Index := Index + 1;
688693
end loop;
689694

690695
return
@@ -703,7 +708,7 @@ package body Gnat2Why.Unchecked_Conversion is
703708
(if Do_Validity
704709
then
705710
New_Record_Aggregate
706-
(Associations => Flags,
711+
(Associations => Flags (1 .. F_Index - 1),
707712
Typ => Get_Validity_Tree_Type (Typ))
708713
else Why_Empty));
709714
end;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
with Ada.Unchecked_Conversion;
2+
procedure Ex_Zero_Byte_Parsing_Possible with SPARK_Mode is
3+
type Bit_Array is array (Positive range <>) of Boolean;
4+
type T2_Bit_Array is new Bit_Array (1 .. 64) with Pack;
5+
6+
type T2_Kind_1 is record
7+
G1 : Integer;
8+
G2 : Natural; -- Might have invalid values
9+
end record
10+
with Size => 64;
11+
for T2_Kind_1 use
12+
record
13+
G1 at 0 range 0 .. 31;
14+
G2 at 0 range 32 .. 63;
15+
end record;
16+
17+
package Model with Ghost is
18+
function T2_From_Bytes is new Ada.Unchecked_Conversion
19+
(T2_Bit_Array, T2_Kind_1)
20+
with Potentially_Invalid;
21+
22+
function Is_Valid (X : T2_Bit_Array) return Boolean is
23+
(T2_From_Bytes (X)'Valid_Scalars);
24+
end Model;
25+
26+
procedure Parse_T2_Kind_1 (X : aliased T2_Bit_Array) with
27+
Pre => Model.Is_Valid (X);
28+
29+
procedure Parse_T2_Kind_1 (X : aliased T2_Bit_Array) is
30+
Z : aliased constant T2_Kind_1 with
31+
Import,
32+
Address => X'Address,
33+
Potentially_Invalid;
34+
begin
35+
pragma Assert (Z.G2'Valid); -- This is not provable yet
36+
end Parse_T2_Kind_1;
37+
38+
begin
39+
null;
40+
end;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ex_zero_byte_parsing_possible.adb:18:16: info: types in unchecked conversion have the same size (Trivial)
2+
ex_zero_byte_parsing_possible.adb:19:10: info: type is suitable as source for unchecked conversion (Trivial)
3+
ex_zero_byte_parsing_possible.adb:19:24: info: type is suitable for unchecked conversion (Trivial)
4+
ex_zero_byte_parsing_possible.adb:22:16: info: implicit aspect Always_Terminates on "Is_Valid" has been proved, subprogram will terminate
5+
ex_zero_byte_parsing_possible.adb:26:14: warning: subprogram "Parse_T2_Kind_1" has no effect
6+
ex_zero_byte_parsing_possible.adb:30:07: info: address in address clause is compatible with object alignment (Trivial)
7+
ex_zero_byte_parsing_possible.adb:30:07: info: object is suitable for aliasing via address clause (Trivial)
8+
ex_zero_byte_parsing_possible.adb:32:20: info: object is suitable for aliasing via address clause (Trivial)
9+
ex_zero_byte_parsing_possible.adb:32:20: info: type is suitable as source for unchecked conversion (Trivial)
10+
ex_zero_byte_parsing_possible.adb:32:20: info: types of aliased objects have the same size (Trivial)
11+
ex_zero_byte_parsing_possible.adb:35:22: medium: assertion might fail

0 commit comments

Comments
 (0)