Skip to content

Commit 8bd8413

Browse files
committed
Add test for writing-through-uninit bug (reported on IRC by jrmuizel), plus fix in typestate system.
1 parent 62b6950 commit 8bd8413

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/boot/me/typestate.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ let condition_assigning_visitor
391391
end
392392
in
393393

394+
let raise_dst_init_precond_if_writing_through sid lval =
395+
match lval with
396+
Ast.LVAL_base _ -> ()
397+
| Ast.LVAL_ext _ ->
398+
let precond = slot_inits (lval_slots cx lval) in
399+
raise_precondition sid precond;
400+
in
401+
394402
let visit_stmt_pre s =
395403
begin
396404
match s.node with
@@ -402,6 +410,7 @@ let condition_assigning_visitor
402410
let precond = slot_inits (lval_slots cx src) in
403411
let postcond = slot_inits (lval_slots cx dst) in
404412
raise_pre_post_cond s.id precond;
413+
raise_dst_init_precond_if_writing_through s.id dst;
405414
raise_postcondition s.id postcond
406415

407416
| Ast.STMT_send (dst, src) ->
@@ -423,6 +432,7 @@ let condition_assigning_visitor
423432
(Array.append (rec_inputs_slots cx entries) base_slots)
424433
in
425434
let postcond = slot_inits (lval_slots cx dst) in
435+
raise_dst_init_precond_if_writing_through s.id dst;
426436
raise_pre_post_cond s.id precond;
427437
raise_postcondition s.id postcond
428438

@@ -431,38 +441,45 @@ let condition_assigning_visitor
431441
(tup_inputs_slots cx modes_atoms)
432442
in
433443
let postcond = slot_inits (lval_slots cx dst) in
444+
raise_dst_init_precond_if_writing_through s.id dst;
434445
raise_pre_post_cond s.id precond;
435446
raise_postcondition s.id postcond
436447

437448
| Ast.STMT_new_vec (dst, _, atoms) ->
438449
let precond = slot_inits (atoms_slots cx atoms) in
439450
let postcond = slot_inits (lval_slots cx dst) in
451+
raise_dst_init_precond_if_writing_through s.id dst;
440452
raise_pre_post_cond s.id precond;
441453
raise_postcondition s.id postcond
442454

443455
| Ast.STMT_new_str (dst, _) ->
444456
let postcond = slot_inits (lval_slots cx dst) in
457+
raise_dst_init_precond_if_writing_through s.id dst;
445458
raise_postcondition s.id postcond
446459

447460
| Ast.STMT_new_port dst ->
448461
let postcond = slot_inits (lval_slots cx dst) in
462+
raise_dst_init_precond_if_writing_through s.id dst;
449463
raise_postcondition s.id postcond
450464

451465
| Ast.STMT_new_chan (dst, port) ->
452466
let precond = slot_inits (lval_option_slots cx port) in
453467
let postcond = slot_inits (lval_slots cx dst) in
468+
raise_dst_init_precond_if_writing_through s.id dst;
454469
raise_pre_post_cond s.id precond;
455470
raise_postcondition s.id postcond
456471

457472
| Ast.STMT_new_box (dst, _, src) ->
458473
let precond = slot_inits (atom_slots cx src) in
459474
let postcond = slot_inits (lval_slots cx dst) in
475+
raise_dst_init_precond_if_writing_through s.id dst;
460476
raise_pre_post_cond s.id precond;
461477
raise_postcondition s.id postcond
462478

463479
| Ast.STMT_copy (dst, src) ->
464480
let precond = slot_inits (expr_slots cx src) in
465481
let postcond = slot_inits (lval_slots cx dst) in
482+
raise_dst_init_precond_if_writing_through s.id dst;
466483
raise_pre_post_cond s.id precond;
467484
raise_postcondition s.id postcond
468485

@@ -474,11 +491,13 @@ let condition_assigning_visitor
474491

475492
| Ast.STMT_spawn (dst, _, lv, args)
476493
| Ast.STMT_call (dst, lv, args) ->
494+
raise_dst_init_precond_if_writing_through s.id dst;
477495
visit_callable_pre s.id (lval_slots cx dst) lv args
478496

479497
| Ast.STMT_bind (dst, lv, args_opt) ->
480498
let args = arr_map_partial args_opt (fun a -> a) in
481-
visit_callable_pre s.id (lval_slots cx dst) lv args
499+
raise_dst_init_precond_if_writing_through s.id dst;
500+
visit_callable_pre s.id (lval_slots cx dst) lv args
482501

483502
| Ast.STMT_ret (Some at) ->
484503
let precond = slot_inits (atom_slots cx at) in
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// error-pattern: Unsatisfied precondition constraint
2+
3+
fn test() {
4+
let vec[int] w;
5+
w.(5) = 0;
6+
}
7+
8+
fn main() {
9+
test();
10+
}

0 commit comments

Comments
 (0)