Skip to content

Commit 1851e9a

Browse files
author
Lefan Zhang
authored
Merge pull request diffblue#23 from lefanz-amazon/lefan-abstraction
abstraction: put all functions into one namespace/class
2 parents 03c3040 + 7be2993 commit 1851e9a

File tree

4 files changed

+290
-274
lines changed

4 files changed

+290
-274
lines changed

regression/abstraction/specs/aws_array_eq_c_str.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
{
22
"entries": [
33
{
4-
"entity": "string",
4+
"entity": "array",
55
"function": "aws_array_eq_c_str_harness",
6-
"name": "aws_array_eq_c_str_harness::1::c_str",
6+
"name": "aws_array_eq_c_str_harness::1::array",
77
"shape": {
8-
"indices": ["cncrt", "clast"],
8+
"indices": ["cncrt0", "cncrt", "length"],
99
"assumptions": [
10-
"cncrt < clast"
10+
"cncrt0==0",
11+
"cncrt0<cncrt",
12+
"cncrt<length"
1113
],
12-
"shape-type": "*c*c"
14+
"shape-type": "c*c*l*"
1315
},
14-
"abst-function-file": "./abst-funcs.c",
16+
"abst-function-file": "../abst-funcs.c",
1517
"abst-functions":{
16-
"add-abs-conc": "add_abs_to_conc",
17-
"sub-abs-conc": "sub_conc_from_abs",
18-
"precise-check": "is_precise",
19-
"abstract-index": "two_abs",
20-
"concretize-index": "concretize",
18+
"add-abs-conc": "add_abs_to_conc_3",
19+
"sub-abs-conc": "sub_conc_from_abs_3",
20+
"precise-check": "is_precise_3",
21+
"abstract-index": "three_abs",
22+
"concretize-index": "concretize_3",
2123
"multiply-indices": null,
2224
"mod-indices": null
2325
},
2426
"related-entities": [
2527
{
2628
"entity": "array",
2729
"function": "aws_array_eq_c_str_harness",
28-
"name": "aws_array_eq_c_str_harness::1::array"
30+
"name": "aws_array_eq_c_str_harness::1::c_str"
2931
},
3032
{
31-
"entity": "scalar",
33+
"entity": "length",
3234
"function": "aws_array_eq_c_str_harness",
3335
"name": "aws_array_eq_c_str_harness::1::array_len"
3436
},
3537
{
3638
"entity": "scalar",
37-
"function": "aws_array_eq_c_str_harness",
38-
"name": "aws_array_eq_c_str_harness::1::str_len"
39+
"function": "",
40+
"name": "str_len"
3941
}
4042
]
4143

src/goto-instrument/abstraction.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ Author: Lefan Zhang, [email protected]
2323
#include <linking/static_lifetime_init.h>
2424
#include "abstraction.h"
2525

26-
void expr_type_relation::link(size_t i1, size_t i2)
26+
void am_abstractiont::expr_type_relation::link(size_t i1, size_t i2)
2727
{
2828
edges[i1].push_back(i2);
2929
edges[i2].push_back(i1);
3030
}
3131

32-
void expr_type_relation::link_array(size_t i1, size_t i2)
32+
void am_abstractiont::expr_type_relation::link_array(size_t i1, size_t i2)
3333
{
3434
edges_array[i1].push_back(i2);
3535
edges_array[i2].push_back(i1);
3636
}
3737

38-
size_t expr_type_relation::add_expr(const exprt &expr)
38+
size_t am_abstractiont::expr_type_relation::add_expr(const exprt &expr)
3939
{
4040
size_t index = expr_list.size();
4141
expr_list.push_back(expr);
@@ -110,7 +110,7 @@ size_t expr_type_relation::add_expr(const exprt &expr)
110110
return index;
111111
}
112112

113-
void expr_type_relation::solve()
113+
void am_abstractiont::expr_type_relation::solve()
114114
{
115115
while(!todo.empty())
116116
{
@@ -141,7 +141,7 @@ void expr_type_relation::solve()
141141
}
142142
}
143143

144-
void expr_type_relation::solve_array()
144+
void am_abstractiont::expr_type_relation::solve_array()
145145
{
146146
while(!todo_array.empty())
147147
{
@@ -172,15 +172,15 @@ void expr_type_relation::solve_array()
172172
}
173173
}
174174

175-
void link_abst_functions(goto_modelt &goto_model, const abstraction_spect &abst_spec, ui_message_handlert &msg_handler, const optionst &options)
175+
void am_abstractiont::link_abst_functions(goto_modelt &goto_model, const abstraction_spect &abst_spec, ui_message_handlert &msg_handler, const optionst &options)
176176
{
177177
std::vector<std::string> abstfiles = abst_spec.get_abstraction_function_files(); // get abst function file names
178178
goto_modelt goto_model_for_abst_fns = initialize_goto_model(abstfiles, msg_handler, options); // read files
179179
link_goto_model(goto_model, goto_model_for_abst_fns, msg_handler); // link goto model
180180
}
181181

182182
const std::tuple<std::unordered_set<irep_idt>, std::unordered_set<irep_idt>>
183-
find_index_symbols(
183+
am_abstractiont::find_index_symbols(
184184
const goto_functiont &goto_function,
185185
const irep_idt &array_name)
186186
{
@@ -286,7 +286,7 @@ find_index_symbols(
286286
return result;
287287
}
288288

289-
void complete_abst_spec(const goto_functiont& goto_function, abstraction_spect &abst_spec)
289+
void am_abstractiont::complete_abst_spec(const goto_functiont& goto_function, abstraction_spect &abst_spec)
290290
{
291291
for(auto &spec: abst_spec.get_specs())
292292
{
@@ -327,7 +327,7 @@ irep_idt check_expr_is_symbol(const exprt &expr)
327327

328328
// go into a function to find all function calls we'll need to abstract
329329
std::vector<std::tuple<irep_idt, std::unordered_map<irep_idt, irep_idt>>>
330-
find_function_calls(irep_idt func_name, goto_modelt &goto_model, const abstraction_spect &abst_spec)
330+
am_abstractiont::find_function_calls(irep_idt func_name, goto_modelt &goto_model, const abstraction_spect &abst_spec)
331331
{
332332
std::vector<std::tuple<irep_idt, std::unordered_map<irep_idt, irep_idt>>> result;
333333

@@ -359,7 +359,7 @@ find_function_calls(irep_idt func_name, goto_modelt &goto_model, const abstracti
359359
}
360360

361361
std::unordered_map<irep_idt, abstraction_spect>
362-
calculate_complete_abst_specs_for_funcs(goto_modelt &goto_model, abstraction_spect &abst_spec)
362+
am_abstractiont::calculate_complete_abst_specs_for_funcs(goto_modelt &goto_model, abstraction_spect &abst_spec)
363363
{
364364
std::unordered_map<irep_idt, abstraction_spect> function_spec_map; // map from function to its abst_spec
365365
const goto_functiont &init_function = goto_model.get_goto_function(abst_spec.get_func_name());
@@ -423,7 +423,7 @@ calculate_complete_abst_specs_for_funcs(goto_modelt &goto_model, abstraction_spe
423423
return function_spec_map;
424424
}
425425

426-
bool contains_an_entity_to_be_abstracted(const exprt &expr, const abstraction_spect &abst_spec)
426+
bool am_abstractiont::contains_an_entity_to_be_abstracted(const exprt &expr, const abstraction_spect &abst_spec)
427427
{
428428
struct match_abst_symbolt
429429
{
@@ -444,12 +444,12 @@ bool contains_an_entity_to_be_abstracted(const exprt &expr, const abstraction_sp
444444

445445
}
446446

447-
irep_idt get_abstract_name(const irep_idt &old_name)
447+
irep_idt am_abstractiont::get_abstract_name(const irep_idt &old_name)
448448
{
449449
return irep_idt(std::string(old_name.c_str())+"$abst");
450450
}
451451

452-
bool contains_a_function_call(const exprt &expr)
452+
bool am_abstractiont::contains_a_function_call(const exprt &expr)
453453
{
454454
class find_functiont : public const_expr_visitort
455455
{
@@ -473,7 +473,7 @@ bool contains_a_function_call(const exprt &expr)
473473
return ff.found;
474474
}
475475

476-
std::vector<exprt> get_direct_access_exprs(const exprt &expr, const abstraction_spect::spect &spec)
476+
std::vector<exprt> am_abstractiont::get_direct_access_exprs(const exprt &expr, const abstraction_spect::spect &spec)
477477
{
478478
class find_direct_accesst : public const_expr_visitort
479479
{
@@ -518,7 +518,7 @@ std::vector<exprt> get_direct_access_exprs(const exprt &expr, const abstraction_
518518
return result;
519519
}
520520

521-
exprt add_guard_expression_to_assert(
521+
exprt am_abstractiont::add_guard_expression_to_assert(
522522
const exprt &expr,
523523
const exprt &expr_before_abst,
524524
const abstraction_spect &abst_spec,
@@ -581,7 +581,7 @@ exprt add_guard_expression_to_assert(
581581
}
582582
}
583583

584-
void declare_abst_variables_for_func(
584+
void am_abstractiont::declare_abst_variables_for_func(
585585
goto_modelt &goto_model,
586586
const irep_idt &func_name,
587587
const abstraction_spect &abst_spec,
@@ -676,7 +676,7 @@ void declare_abst_variables_for_func(
676676
}
677677
}
678678

679-
bool check_if_exprt_eval_to_abst_index(
679+
bool am_abstractiont::check_if_exprt_eval_to_abst_index(
680680
const exprt &expr,
681681
const abstraction_spect &abst_spec,
682682
abstraction_spect::spect &spec)
@@ -763,7 +763,7 @@ bool check_if_exprt_eval_to_abst_index(
763763
}
764764
}
765765

766-
symbolt create_function_call(
766+
symbolt am_abstractiont::create_function_call(
767767
const irep_idt &func_name,
768768
const exprt::operandst operands,
769769
const irep_idt &caller,
@@ -830,7 +830,7 @@ symbolt create_function_call(
830830
return new_symb;
831831
}
832832

833-
exprt abstract_expr_write(
833+
exprt am_abstractiont::abstract_expr_write(
834834
const exprt &expr,
835835
const abstraction_spect &abst_spec,
836836
const goto_modelt &goto_model,
@@ -871,7 +871,7 @@ exprt abstract_expr_write(
871871
}
872872
}
873873

874-
exprt create_comparator_expr_abs_abs(
874+
exprt am_abstractiont::create_comparator_expr_abs_abs(
875875
const exprt &orig_expr,
876876
const abstraction_spect::spect &spec,
877877
const goto_modelt &goto_model,
@@ -906,7 +906,7 @@ exprt create_comparator_expr_abs_abs(
906906
return std::move(result_expr);
907907
}
908908

909-
exprt abstract_expr_read_comparator(
909+
exprt am_abstractiont::abstract_expr_read_comparator(
910910
const exprt &expr,
911911
const abstraction_spect &abst_spec,
912912
const goto_modelt &goto_model,
@@ -1022,7 +1022,7 @@ exprt abstract_expr_read_comparator(
10221022
}
10231023

10241024
// check whether an expr is a pointer offset
1025-
bool is_pointer_offset(const exprt &expr)
1025+
bool am_abstractiont::is_pointer_offset(const exprt &expr)
10261026
{
10271027
if(expr.id() == ID_pointer_offset)
10281028
{
@@ -1039,7 +1039,7 @@ bool is_pointer_offset(const exprt &expr)
10391039
}
10401040
}
10411041

1042-
exprt abstract_expr_read_plusminus(
1042+
exprt am_abstractiont::abstract_expr_read_plusminus(
10431043
const exprt &expr,
10441044
const abstraction_spect &abst_spec,
10451045
const goto_modelt &goto_model,
@@ -1111,7 +1111,7 @@ exprt abstract_expr_read_plusminus(
11111111
}
11121112
}
11131113

1114-
exprt abstract_expr_read_dereference(
1114+
exprt am_abstractiont::abstract_expr_read_dereference(
11151115
const exprt &expr,
11161116
const abstraction_spect &abst_spec,
11171117
const goto_modelt &goto_model,
@@ -1215,7 +1215,7 @@ exprt abstract_expr_read_dereference(
12151215
}
12161216
}
12171217

1218-
exprt abstract_expr_read(
1218+
exprt am_abstractiont::abstract_expr_read(
12191219
const exprt &expr,
12201220
const abstraction_spect &abst_spec,
12211221
const goto_modelt &goto_model,
@@ -1293,7 +1293,7 @@ exprt abstract_expr_read(
12931293
}
12941294
}
12951295

1296-
void define_concrete_indices(goto_modelt &goto_model, const abstraction_spect &abst_spec)
1296+
void am_abstractiont::define_concrete_indices(goto_modelt &goto_model, const abstraction_spect &abst_spec)
12971297
{
12981298
for(const auto &spec: abst_spec.get_specs())
12991299
{
@@ -1333,10 +1333,8 @@ void define_concrete_indices(goto_modelt &goto_model, const abstraction_spect &a
13331333
}
13341334
}
13351335

1336-
void insert_shape_assumptions(goto_modelt &goto_model, const abstraction_spect &abst_spec)
1336+
void am_abstractiont::insert_shape_assumptions(goto_modelt &goto_model, const abstraction_spect &abst_spec)
13371337
{
1338-
1339-
13401338
namespacet ns(goto_model.get_symbol_table());
13411339
for(const auto &spec: abst_spec.get_specs())
13421340
{
@@ -1359,7 +1357,7 @@ void insert_shape_assumptions(goto_modelt &goto_model, const abstraction_spect &
13591357
}
13601358
}
13611359

1362-
void add_length_assumptions(goto_modelt &goto_model, const abstraction_spect &abst_spec)
1360+
void am_abstractiont::add_length_assumptions(goto_modelt &goto_model, const abstraction_spect &abst_spec)
13631361
{
13641362
for(const auto &spec: abst_spec.get_specs())
13651363
{
@@ -1447,7 +1445,7 @@ void add_length_assumptions(goto_modelt &goto_model, const abstraction_spect &ab
14471445
}
14481446
}
14491447

1450-
void abstract_goto_program(goto_modelt &goto_model, abstraction_spect &abst_spec)
1448+
void am_abstractiont::abstract_goto_program(goto_modelt &goto_model, abstraction_spect &abst_spec)
14511449
{
14521450
// Define the global concrete indices to be used
14531451
define_concrete_indices(goto_model, abst_spec);
@@ -1559,6 +1557,7 @@ void abstract_goto_program(goto_modelt &goto_model, abstraction_spect &abst_spec
15591557
new_rhs = as.rhs();
15601558
}
15611559

1560+
// TODO: when lhs and rhs are not both abstracted, we should do the translation.
15621561
code_assignt new_as(new_lhs, new_rhs);
15631562
it->set_assign(new_as);
15641563
}
@@ -1577,7 +1576,7 @@ void abstract_goto_program(goto_modelt &goto_model, abstraction_spect &abst_spec
15771576
if(
15781577
!it->is_decl() && !it->is_end_function() && !it->is_goto() &&
15791578
!it->is_return() && !it->is_function_call() && !it->is_assert() &&
1580-
!it->is_assign() && !it->is_assume() && !it->is_dead())
1579+
!it->is_assign() && !it->is_assume() && !it->is_dead() && !it->is_skip())
15811580
throw "Unknown instruction type " + std::to_string(it->type);
15821581

15831582
// insert new instructions before it

0 commit comments

Comments
 (0)