Skip to content

Commit 0a3b7e3

Browse files
committed
Add --vsd-arrays smash option
The "smash" array abstraction sets the maximum size of the full_array_abstract_object to 1. All writes to the array are merged, and all reads return the same value.
1 parent 1426b72 commit 0a3b7e3

10 files changed

+90
-13
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--show --variable-sensitivity --vsd-values constants --vsd-arrays smash
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
main::1::arr_at_ix \(\) -> TOP @ \[9\]
7+
main::1::arr_0_after_write \(\) -> TOP @ \[18\]
8+
main::1::arr_1_after_write \(\) -> TOP @ \[20\]
9+
main::1::arr_2_after_write \(\) -> TOP @ \[22\]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--show --variable-sensitivity --vsd-values intervals --vsd-arrays smash
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
main::1::arr_at_ix \(\) -> \[1, 3\] @ \[9\]
7+
main::1::arr_0_after_write \(\) -> \[1, 4\] @ \[18\]
8+
main::1::arr_1_after_write \(\) -> \[1, 4\] @ \[20\]
9+
main::1::arr_2_after_write \(\) -> \[1, 4\] @ \[22\]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--show --variable-sensitivity --vsd-values set-of-constants --vsd-arrays smash
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
main::1::arr_at_ix \(\) -> value-set-begin: 1, 2, 3 :value-set-end
7+
main::1::arr_0_after_write \(\) -> value-set-begin: 1, 2, 3, 4 :value-set-end
8+
main::1::arr_1_after_write \(\) -> value-set-begin: 1, 2, 3, 4 :value-set-end
9+
main::1::arr_2_after_write \(\) -> value-set-begin: 1, 2, 3, 4 :value-set-end

src/analyses/variable-sensitivity/full_array_abstract_object.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ static eval_index_resultt eval_index(
3030
const exprt &expr,
3131
const abstract_environmentt &env,
3232
const namespacet &ns);
33+
static eval_index_resultt eval_index(
34+
const mp_integer &index,
35+
const abstract_environmentt &env,
36+
const namespacet &ns);
3337

3438
template <typename index_fn>
3539
abstract_object_pointert apply_to_index_range(
@@ -83,11 +87,12 @@ full_array_abstract_objectt::full_array_abstract_objectt(
8387
{
8488
if(expr.id() == ID_array)
8589
{
86-
int index = 0;
90+
mp_integer i = 0;
8791
for(const exprt &entry : expr.operands())
8892
{
89-
map.insert(mp_integer(index), environment.eval(entry, ns));
90-
++index;
93+
auto index = eval_index(i, environment, ns);
94+
map_put(index.value, environment.eval(entry, ns), index.overrun);
95+
++i;
9196
}
9297
set_not_top();
9398
}
@@ -467,9 +472,19 @@ static eval_index_resultt eval_index(
467472

468473
mp_integer out_index;
469474
bool result = to_integer(to_constant_expr(value), out_index);
475+
if(result)
476+
return {false};
477+
478+
return eval_index(out_index, env, ns);
479+
}
470480

481+
static eval_index_resultt eval_index(
482+
const mp_integer &index,
483+
const abstract_environmentt &env,
484+
const namespacet &ns)
485+
{
471486
auto max_array_index = env.configuration().maximum_array_index;
472-
bool overrun = (out_index > max_array_index);
487+
bool overrun = (index > max_array_index);
473488

474-
return {!result, overrun ? max_array_index : out_index, overrun};
489+
return {true, overrun ? max_array_index : index, overrun};
475490
}

src/analyses/variable-sensitivity/variable_sensitivity_configuration.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/// domain abstractions are used, flow sensitivity, etc
1111
#include "variable_sensitivity_configuration.h"
1212

13+
#include <limits>
1314
#include <util/options.h>
1415

1516
vsd_configt vsd_configt::from_options(const optionst &options)
@@ -41,6 +42,9 @@ vsd_configt vsd_configt::from_options(const optionst &options)
4142
? flow_sensitivityt::insensitive
4243
: flow_sensitivityt::sensitive;
4344

45+
config.maximum_array_index =
46+
option_to_size(options, "arrays", array_option_size_mappings);
47+
4448
return config;
4549
}
4650

@@ -52,6 +56,7 @@ vsd_configt vsd_configt::constant_domain()
5256
config.pointer_abstract_type = POINTER_SENSITIVE;
5357
config.struct_abstract_type = STRUCT_SENSITIVE;
5458
config.array_abstract_type = ARRAY_SENSITIVE;
59+
config.maximum_array_index = std::numeric_limits<size_t>::max();
5560
return config;
5661
}
5762

@@ -62,6 +67,7 @@ vsd_configt vsd_configt::value_set()
6267
config.pointer_abstract_type = VALUE_SET_OF_POINTERS;
6368
config.struct_abstract_type = STRUCT_SENSITIVE;
6469
config.array_abstract_type = ARRAY_SENSITIVE;
70+
config.maximum_array_index = std::numeric_limits<size_t>::max();
6571
return config;
6672
}
6773

@@ -73,6 +79,7 @@ vsd_configt vsd_configt::intervals()
7379
config.pointer_abstract_type = POINTER_SENSITIVE;
7480
config.struct_abstract_type = STRUCT_SENSITIVE;
7581
config.array_abstract_type = ARRAY_SENSITIVE;
82+
config.maximum_array_index = std::numeric_limits<size_t>::max();
7683
return config;
7784
}
7885

@@ -92,15 +99,23 @@ const vsd_configt::option_mappingt vsd_configt::struct_option_mappings = {
9299

93100
const vsd_configt::option_mappingt vsd_configt::array_option_mappings = {
94101
{"top-bottom", ARRAY_INSENSITIVE},
102+
{"smash", ARRAY_SENSITIVE},
95103
{"every-element", ARRAY_SENSITIVE}};
96104

105+
const vsd_configt::option_size_mappingt
106+
vsd_configt::array_option_size_mappings = {
107+
{"top-bottom", 0},
108+
{"smash", 0},
109+
{"every-element", std::numeric_limits<size_t>::max()}};
110+
97111
const vsd_configt::option_mappingt vsd_configt::union_option_mappings = {
98112
{"top-bottom", UNION_INSENSITIVE}};
99113

100-
invalid_command_line_argument_exceptiont vsd_configt::invalid_argument(
114+
template <class mappingt>
115+
invalid_command_line_argument_exceptiont invalid_argument(
101116
const std::string &option_name,
102117
const std::string &bad_argument,
103-
const option_mappingt &mapping)
118+
const mappingt &mapping)
104119
{
105120
auto option = "--vsd-" + option_name;
106121
auto choices = std::string("");
@@ -132,3 +147,22 @@ ABSTRACT_OBJECT_TYPET vsd_configt::option_to_abstract_type(
132147
}
133148
return selected->second;
134149
}
150+
151+
size_t vsd_configt::option_to_size(
152+
const optionst &options,
153+
const std::string &option_name,
154+
const option_size_mappingt &mapping)
155+
{
156+
const size_t def = std::numeric_limits<size_t>::max();
157+
const auto argument = options.get_option(option_name);
158+
159+
if(argument.empty())
160+
return def;
161+
162+
auto selected = mapping.find(argument);
163+
if(selected == mapping.end())
164+
{
165+
throw invalid_argument(option_name, argument, mapping);
166+
}
167+
return selected->second;
168+
}

src/analyses/variable-sensitivity/variable_sensitivity_configuration.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#ifndef CPROVER_ANALYSES_VARIABLE_SENSITIVITY_VARIABLE_SENSITIVITY_CONFIGURATION_H
1212
#define CPROVER_ANALYSES_VARIABLE_SENSITIVITY_VARIABLE_SENSITIVITY_CONFIGURATION_H
1313

14-
#include <limits>
1514
#include <map>
1615

1716
#include <util/exception_utils.h>
@@ -52,7 +51,7 @@ struct vsd_configt
5251

5352
flow_sensitivityt flow_sensitivity;
5453

55-
size_t maximum_array_index = std::numeric_limits<size_t>::max();
54+
size_t maximum_array_index = 0;
5655

5756
struct
5857
{
@@ -80,22 +79,24 @@ struct vsd_configt
8079

8180
private:
8281
using option_mappingt = std::map<std::string, ABSTRACT_OBJECT_TYPET>;
82+
using option_size_mappingt = std::map<std::string, size_t>;
8383

8484
static ABSTRACT_OBJECT_TYPET option_to_abstract_type(
8585
const optionst &options,
8686
const std::string &option_name,
8787
const option_mappingt &mapping,
8888
ABSTRACT_OBJECT_TYPET default_type);
8989

90-
static invalid_command_line_argument_exceptiont invalid_argument(
90+
static size_t option_to_size(
91+
const optionst &options,
9192
const std::string &option_name,
92-
const std::string &bad_argument,
93-
const option_mappingt &mapping);
93+
const option_size_mappingt &mapping);
9494

9595
static const option_mappingt value_option_mappings;
9696
static const option_mappingt pointer_option_mappings;
9797
static const option_mappingt struct_option_mappings;
9898
static const option_mappingt array_option_mappings;
99+
static const option_size_mappingt array_option_size_mappings;
99100
static const option_mappingt union_option_mappings;
100101
};
101102

src/analyses/variable-sensitivity/variable_sensitivity_domain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
" --vsd-structs struct field sensitive analysis - " \
8989
"top-bottom|every-field\n" /* NOLINT(whitespace/line_length) */ \
9090
" --vsd-arrays array entry sensitive analysis - " \
91-
"top-bottom|every-element\n" /* NOLINT(whitespace/line_length) */ \
91+
"top-bottom|smash|every-element\n" /* NOLINT(whitespace/line_length) */ \
9292
" --vsd-pointers pointer sensitive analysis - " \
9393
"top-bottom|constants|value-set\n" /* NOLINT(whitespace/line_length) */ \
9494
" --vsd-unions union sensitive analysis - top-bottom\n" \

0 commit comments

Comments
 (0)