Skip to content

Commit 78ade79

Browse files
Temporarily make string literals have __CPROVER_string type
Until we get proper types working for string literals, this change allows cbmc to at least assert equality/inequality between string literals. Even if we had proper array types for strings, until we have arrays working, we can't do much with them - so this is a reasonable halfway house for now.
1 parent 0a27e17 commit 78ade79

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

gnat2goto/driver/tree_walk.adb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,8 @@ package body Tree_Walk is
13941394

13951395
function Do_String_Constant (N : Node_Id) return Irep is
13961396
Ret : constant Irep := New_Irep (I_String_Constant_Expr);
1397-
Element_Type_Ent : constant Entity_Id := Get_Array_Component_Type (N);
1398-
Element_Type : constant Irep := Do_Type_Reference (Element_Type_Ent);
1397+
-- Element_Type_Ent : constant Entity_Id := Get_Array_Component_Type (N);
1398+
-- Element_Type : constant Irep := Do_Type_Reference (Element_Type_Ent);
13991399
StrLen : constant Integer :=
14001400
Integer (String_Length (Strval (N)));
14011401
String_Length_Expr : constant Irep := New_Irep (I_Constant_Expr);
@@ -1409,10 +1409,11 @@ package body Tree_Walk is
14091409
Convert_Uint_To_Hex (UI_From_Int (Int (String_Length
14101410
(Strval (N)))), 64));
14111411

1412-
Set_Type (Ret,
1413-
Make_Array_Type (
1414-
I_Subtype => Element_Type,
1415-
Size => String_Length_Expr));
1412+
Set_Type (Ret, Make_String_Type);
1413+
-- FIXME: We really need some sort of array type here, such as:
1414+
-- Make_Array_Type (
1415+
-- I_Subtype => Element_Type,
1416+
-- Size => String_Length_Expr));
14161417
String_To_Name_Buffer (Strval (N));
14171418
Set_Value (Ret, Name_Buffer (1 .. StrLen));
14181419
Set_Source_Location (Ret, Sloc (N));
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
procedure string_literal is
22
A : constant String := "Hello";
3+
B : constant String := "Hello";
4+
C : constant String := "Goodbye";
35
begin
4-
null;
6+
pragma Assert(A = B);
7+
pragma Assert(A /= C);
58
end string_literal;

0 commit comments

Comments
 (0)