Skip to content

Commit 4c1c343

Browse files
committed
[CN-Test-Gen] Ctype printing fix
1 parent fbc4fbc commit 4c1c343

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

lib/bugExplanation/replicators.ml

+24-13
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ let replicate_call (sct : Sctypes.t) e_arg =
116116
A.AilEcall
117117
( mk_expr
118118
(AilEident (Sym.fresh_named ("cn_replicate_owned_" ^ name_of_bt bt ^ "_aux"))),
119-
[ mk_expr
120-
(CtA.wrap_with_convert_to (A.AilEunary (Address, mk_expr e_arg)) (BT.Loc ()))
121-
] )
119+
[ mk_expr e_arg ] )
122120
| Array (_, None) | Pointer _ ->
123121
A.AilEcall
124122
( mk_expr (AilEident (Sym.fresh_named "cn_replicate_owned_cn_pointer_aux")),
@@ -141,7 +139,11 @@ let replicate_member ptr_sym (sct : Sctypes.t) ((member, sct') : Id.t * Sctypes.
141139
member )
142140
in
143141
let e_arg =
144-
match sct' with Pointer _ -> CtA.wrap_with_convert_to e_arg (BT.Loc ()) | _ -> e_arg
142+
match sct' with
143+
| Pointer _ -> CtA.wrap_with_convert_to e_arg (BT.Loc ())
144+
| Integer _ ->
145+
CtA.wrap_with_convert_to (AilEunary (Address, mk_expr e_arg)) (BT.Loc ())
146+
| _ -> e_arg
145147
in
146148
replicate_call sct' e_arg
147149

@@ -187,15 +189,24 @@ let compile_sct_aux (prog5 : unit Mucore.file) (sct : Sctypes.t)
187189
(mk_expr
188190
(replicate_call
189191
sct'
190-
(AilEident
191-
(Sym.fresh_named
192-
("((("
193-
^ Pp.plain (Sctypes.pp sct')
194-
^ "*)convert_from_cn_pointer("
195-
^ Sym.pp_string ptr_sym
196-
^ "))["
197-
^ string_of_int i
198-
^ "])"))))) )
192+
(CtA.wrap_with_convert_to
193+
(AilEcast
194+
( C.no_qualifiers,
195+
Sctypes.to_ctype (Pointer sct'),
196+
mk_expr
197+
(AilEbinary
198+
( mk_expr
199+
(CtA.wrap_with_convert_from
200+
(AilEident ptr_sym)
201+
(BT.Loc ())),
202+
Arithmetic Add,
203+
mk_expr
204+
(AilEconst
205+
(ConstantInteger
206+
(IConstant
207+
(Z.of_int i, Decimal, None))))
208+
)) ))
209+
(BT.Loc ())))) )
199210
]
200211
] ))
201212
|> List.split

tests/cn-test-gen/src/range.fail.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
int range(int *arr, int len)
2+
/*@ trusted;
3+
requires
4+
take A = each (u64 i; 0u64 <= i && i < (u64)len) {
5+
Owned(array_shift<int>(arr, i))
6+
};
7+
each (u64 i; 0u64 <= i && i < (u64)len) {
8+
A[i] == (i32)i
9+
};
10+
ensures
11+
take A2 = each (u64 i; 0u64 <= i && i < (u64)len) {
12+
Owned(array_shift<int>(arr, i))
13+
};
14+
A == A2;
15+
return == 1i32;
16+
@*/
17+
{
18+
int i = 0;
19+
while (i < len) {
20+
if (arr[i] != i) {
21+
return 0;
22+
}
23+
24+
i++;
25+
}
26+
27+
return 0;
28+
}
+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
struct foo {
2-
int bar[16];
2+
// Type `unsigned char` is a regression test, do not change
3+
unsigned char bar[16];
34
};
45

5-
void test_gen_const_array(struct foo* c)
6+
void test_gen_const_array(struct foo *c)
67
/*@
78
requires take Client_in = Owned<struct foo>(c);
89
ensures take Client_out = Owned<struct foo>(c);
910
@*/
1011
{
11-
return;
12+
return;
1213
}

0 commit comments

Comments
 (0)