Skip to content

Commit 1354ef3

Browse files
committed
liveness fixes for three-way-merge
1 parent 4c039ba commit 1354ef3

13 files changed

+162
-28
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
int globalX;
4+
5+
void f00()
6+
{
7+
}
8+
9+
int main()
10+
{
11+
globalX = 1;
12+
13+
f00();
14+
15+
assert(globalX == 1);
16+
17+
globalX = 2;
18+
19+
f00();
20+
21+
assert(globalX == 2);
22+
23+
return 0;
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-liveness --show
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
globalX .* 0 @ \[30\]
7+
globalX .* 1 @ \[0\]
8+
globalX .* TOP @ \[33\]
9+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-liveness --three-way-merge --show
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
globalX .* 0 @ \[30\]
7+
globalX .* 1 @ \[0\]
8+
globalX .* TOP @ \[33\]
9+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-liveness --three-way-merge --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] .* globalX == 1: SUCCESS
7+
\[main.assertion.2\] .* globalX == 2: UNKNOWN
8+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-liveness --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] .* globalX == 1: SUCCESS
7+
\[main.assertion.2\] .* globalX == 2: UNKNOWN
8+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --show
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
globalX .* 0 @ \[30\]
7+
globalX .* 1 @ \[0\]
8+
globalX .* TOP @ \[0, 4\]
9+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --three-way-merge --show
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
globalX .* 0 @ \[30\]
7+
globalX .* 1 @ \[0\]
8+
globalX .* 2 @ \[4\]
9+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --three-way-merge --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] .* globalX == 1: SUCCESS
7+
\[main.assertion.2\] .* globalX == 2: SUCCESS
8+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] .* globalX == 1: SUCCESS
7+
\[main.assertion.2\] .* globalX == 2: UNKNOWN
8+
--
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
CORE
22
main.c
3-
--variable-sensitivity --vsd-structs every-field --vsd-values intervals --vsd-liveness --show
3+
--variable-sensitivity --vsd-structs every-field --vsd-values intervals --show
44
^EXIT=0$
55
^SIGNAL=0$
66
^main::1::s .* \{\} @ \[1\]
77
^main::1::s .* \{.x=\[1, 1\] @ \[2\], .y=\[3, 3\] @ \[2\]\} @ \[2\]
8-
^main::1::s .* \{.x=\[2, 3\] @ \[7\], .y=\[3, 3\] @ \[2\]\} @ \[7\]
8+
^main::1::s .* \{.x=\[2, 3\] @ \[4, 6\], .y=\[3, 3\] @ \[2\]\} @ \[4, 6\]
99
--

src/analyses/variable-sensitivity/liveness_context.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88

99
#include "liveness_context.h"
1010

11+
bool liveness_contextt::has_location() const
12+
{
13+
return assign_location.has_value();
14+
}
15+
1116
abstract_objectt::locationt liveness_contextt::get_location() const
1217
{
13-
return assign_location.has_value() ? assign_location.value() : locationt();
18+
return assign_location.value();
1419
}
1520

1621
/**
@@ -108,14 +113,21 @@ liveness_contextt::meet(const abstract_object_pointert &other) const
108113
return abstract_objectt::meet(other);
109114
}
110115

116+
bool liveness_contextt::at_same_location(const liveness_context_ptrt &rhs) const
117+
{
118+
return has_location() && rhs->has_location() &&
119+
(get_location()->location_number ==
120+
rhs->get_location()->location_number);
121+
}
122+
111123
abstract_object_pointert liveness_contextt::combine(
112-
const region_context_ptrt &other,
124+
const liveness_context_ptrt &other,
113125
combine_fn fn) const
114126
{
115127
auto combined_child = fn(child_abstract_object, other->child_abstract_object);
116-
auto location_match = get_location() == other->get_location();
128+
auto location_match = at_same_location(other);
117129

118-
if(combined_child.modified || location_match)
130+
if(combined_child.modified || !location_match)
119131
{
120132
const auto &result =
121133
std::dynamic_pointer_cast<liveness_contextt>(mutable_clone());
@@ -127,6 +139,25 @@ abstract_object_pointert liveness_contextt::combine(
127139
return shared_from_this();
128140
}
129141

142+
abstract_object_pointert liveness_contextt::abstract_object_merge_internal(
143+
const abstract_object_pointert &other) const
144+
{
145+
auto other_context =
146+
std::dynamic_pointer_cast<const liveness_contextt>(other);
147+
148+
if(!other_context)
149+
return shared_from_this();
150+
151+
if(other_context && !at_same_location(other_context))
152+
{
153+
auto result = std::dynamic_pointer_cast<liveness_contextt>(mutable_clone());
154+
result->reset_location();
155+
return result;
156+
}
157+
158+
return shared_from_this();
159+
}
160+
130161
void liveness_contextt::reset_location()
131162
{
132163
assign_location.reset();
@@ -161,8 +192,8 @@ void liveness_contextt::output(
161192
{
162193
context_abstract_objectt::output(out, ai, ns);
163194

164-
if(assign_location.has_value())
165-
out << " @ [" << assign_location.value()->location_number << "]";
195+
if(has_location())
196+
out << " @ [" << get_location()->location_number << "]";
166197
else
167198
out << " @ [undefined]";
168199
}
@@ -202,7 +233,7 @@ bool liveness_contextt::has_been_modified(
202233
// For two sets of last written locations to match,
203234
// each location in one set must be equal to precisely one location
204235
// in the other, since a set can assume at most one match
205-
return before_context->get_location() != get_location();
236+
return !at_same_location(before_context);
206237
}
207238

208239
abstract_object_pointert

src/analyses/variable-sensitivity/liveness_context.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class liveness_contextt : public context_abstract_objectt
7979
abstract_object_pointert
8080
meet(const abstract_object_pointert &other) const override;
8181

82+
abstract_object_pointert abstract_object_merge_internal(
83+
const abstract_object_pointert &other) const override;
84+
8285
abstract_object_pointert write(
8386
abstract_environmentt &environment,
8487
const namespacet &ns,
@@ -94,16 +97,19 @@ class liveness_contextt : public context_abstract_objectt
9497
using combine_fn = std::function<abstract_objectt::combine_result(
9598
const abstract_object_pointert &op1,
9699
const abstract_object_pointert &op2)>;
97-
using region_context_ptrt = std::shared_ptr<const liveness_contextt>;
100+
using liveness_context_ptrt = std::shared_ptr<const liveness_contextt>;
98101

99102
abstract_object_pointert
100-
combine(const region_context_ptrt &other, combine_fn fn) const;
103+
combine(const liveness_context_ptrt &other, combine_fn fn) const;
101104

102105
optionalt<locationt> assign_location;
103106

104107
context_abstract_object_ptrt
105108
update_location_context_internal(const locationst &locations) const override;
106109

110+
bool has_location() const;
111+
bool at_same_location(const liveness_context_ptrt &rhs) const;
112+
107113
void set_location(const locationt &location);
108114
};
109115

src/analyses/variable-sensitivity/variable_sensitivity_domain.h

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,31 @@
7979
"(vsd-unions):" \
8080
"(vsd-flow-insensitive)" \
8181
"(vsd-data-dependencies)" \
82-
"(vsd-liveness)"
83-
// clang-format off
84-
#define HELP_VSD \
85-
" --vsd-values value tracking - constants|intervals|set-of-constants\n" /* NOLINT(whitespace/line_length) */ \
86-
" --vsd-structs struct field sensitive analysis - top-bottom|every-field\n" /* NOLINT(whitespace/line_length) */ \
87-
" --vsd-arrays array entry sensitive analysis - top-bottom|every-element\n" /* NOLINT(whitespace/line_length) */ \
88-
" --vsd-pointers pointer sensitive analysis - top-bottom|constants|value-set\n" /* NOLINT(whitespace/line_length) */ \
89-
" --vsd-unions union sensitive analysis - top-bottom\n" \
90-
" --vsd-flow-insensitive disables flow sensitivity\n" \
91-
" --vsd-data-dependencies track data dependencies\n" \
92-
" --vsd-liveness track variable liveness\n" \
82+
"(vsd-liveness)" \
83+
\
84+
// clang-format off
85+
#define HELP_VSD \
86+
" --vsd-values value tracking - " \
87+
"constants|intervals|set-of-constants\n" /* NOLINT(whitespace/line_length) */ \
88+
" --vsd-structs struct field sensitive analysis - " \
89+
"top-bottom|every-field\n" /* NOLINT(whitespace/line_length) */ \
90+
" --vsd-arrays array entry sensitive analysis - " \
91+
"top-bottom|every-element\n" /* NOLINT(whitespace/line_length) */ \
92+
" --vsd-pointers pointer sensitive analysis - " \
93+
"top-bottom|constants|value-set\n" /* NOLINT(whitespace/line_length) */ \
94+
" --vsd-unions union sensitive analysis - top-bottom\n" \
95+
" --vsd-flow-insensitive disables flow sensitivity\n" \
96+
" --vsd-data-dependencies track data dependencies\n" \
97+
" --vsd-liveness track variable liveness\n" \
9398

9499
// cland-format on
95100

96-
#define PARSE_OPTIONS_VSD(cmdline, options) \
97-
options.set_option("values", cmdline.get_value("vsd-values")); \
98-
options.set_option("pointers", cmdline.get_value("vsd-pointers")); \
99-
options.set_option("arrays", cmdline.get_value("vsd-arrays")); \
100-
options.set_option("structs", cmdline.get_value("vsd-structs")); \
101-
options.set_option("unions", cmdline.get_value("vsd-unions")); \
101+
#define PARSE_OPTIONS_VSD(cmdline, options) \
102+
options.set_option("values", cmdline.get_value("vsd-values")); \
103+
options.set_option("pointers", cmdline.get_value("vsd-pointers")); \
104+
options.set_option("arrays", cmdline.get_value("vsd-arrays")); \
105+
options.set_option("structs", cmdline.get_value("vsd-structs")); \
106+
options.set_option("unions", cmdline.get_value("vsd-unions")); \
102107
options.set_option("flow-insensitive", cmdline.isset("vsd-flow-insensitive")); /* NOLINT(whitespace/line_length) */ \
103108
options.set_option("data-dependencies", cmdline.isset("vsd-data-dependencies")); /* NOLINT(whitespace/line_length) */ \
104109
options.set_option("liveness", cmdline.isset("vsd-liveness")); /* NOLINT(whitespace/line_length) */ \

0 commit comments

Comments
 (0)