Skip to content

Commit 31ce65b

Browse files
author
Daniel Kroening
authored
Merge pull request #5030 from diffblue/unit-opX
fix accesses to exprt::opX() in unit/
2 parents 066dd3b + 5832208 commit 31ce65b

File tree

4 files changed

+52
-40
lines changed

4 files changed

+52
-40
lines changed

unit/solvers/strings/string_refinement/substitute_array_list.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ SCENARIO("substitute_array_list", "[core][solvers][strings][string_refinement]")
3737
// Check that `subst = e1 WITH [1:='y']`
3838
REQUIRE(subst.id() == ID_with);
3939
REQUIRE(subst.operands().size() == 3);
40-
const exprt &e1 = subst.op0();
41-
REQUIRE(subst.op1() == index1);
42-
REQUIRE(subst.op2() == chary);
40+
const exprt &e1 = to_with_expr(subst).old();
41+
REQUIRE(to_with_expr(subst).where() == index1);
42+
REQUIRE(to_with_expr(subst).new_value() == chary);
4343

4444
// Check that `e1 = e2 WITH [0:='x']`
4545
REQUIRE(e1.id() == ID_with);
4646
REQUIRE(e1.operands().size() == 3);
47-
const exprt &e2 = e1.op0();
48-
REQUIRE(e1.op1() == index0);
49-
REQUIRE(e1.op2() == charx);
47+
const exprt &e2 = to_with_expr(e1).old();
48+
REQUIRE(to_with_expr(e1).where() == index0);
49+
REQUIRE(to_with_expr(e1).new_value() == charx);
5050

5151
// Check that `e1 = ARRAY_OF 0`
5252
REQUIRE(e2.id() == ID_array_of);
5353
REQUIRE(e2.operands().size() == 1);
54-
REQUIRE(e2.op0() == from_integer(0, char_type));
54+
REQUIRE(to_array_of_expr(e2).op() == from_integer(0, char_type));
5555
}

unit/util/interval_constraint.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ SCENARIO(
3131
"expressions representing a <= expr && expr <= z")
3232
{
3333
REQUIRE(can_cast_expr<and_exprt>(result));
34+
REQUIRE(result.operands().size() == 2);
35+
const auto &result_binary = to_binary_expr(result);
3436

35-
REQUIRE(result.op0().id() == ID_ge);
36-
REQUIRE(result.op0().op0().type() == unsignedbv_typet(16));
37-
REQUIRE(can_cast_expr<constant_exprt>(result.op0().op1()));
38-
REQUIRE(to_constant_expr(result.op0().op1()).get_value() == "61"); // a
37+
REQUIRE(result_binary.op0().id() == ID_ge);
38+
const auto &op0_binary = to_binary_expr(result_binary.op0());
39+
REQUIRE(op0_binary.op0().type() == unsignedbv_typet(16));
40+
REQUIRE(can_cast_expr<constant_exprt>(op0_binary.op1()));
41+
REQUIRE(to_constant_expr(op0_binary.op1()).get_value() == "61"); // a
3942

40-
REQUIRE(result.op1().id() == ID_le);
41-
REQUIRE(result.op1().op0().type() == unsignedbv_typet(16));
42-
REQUIRE(can_cast_expr<constant_exprt>(result.op1().op1()));
43-
REQUIRE(to_constant_expr(result.op1().op1()).get_value() == "7A"); // b
43+
REQUIRE(result_binary.op1().id() == ID_le);
44+
const auto &op1_binary = to_binary_expr(result_binary.op1());
45+
REQUIRE(op1_binary.op0().type() == unsignedbv_typet(16));
46+
REQUIRE(can_cast_expr<constant_exprt>(op1_binary.op1()));
47+
REQUIRE(to_constant_expr(op1_binary.op1()).get_value() == "7A"); // b
4448
}
4549
}
4650
}
@@ -64,16 +68,20 @@ SCENARIO(
6468
"expressions representing 6 <= expr && expr <= 9")
6569
{
6670
REQUIRE(can_cast_expr<and_exprt>(result));
71+
REQUIRE(result.operands().size() == 2);
72+
const auto &result_binary = to_binary_expr(result);
6773

68-
REQUIRE(result.op0().id() == ID_ge);
69-
REQUIRE(result.op0().op0().type() == unsignedbv_typet(32));
70-
REQUIRE(can_cast_expr<constant_exprt>(result.op0().op1()));
71-
REQUIRE(to_constant_expr(result.op0().op1()).get_value() == "6");
74+
REQUIRE(result_binary.op0().id() == ID_ge);
75+
const auto &op0_binary = to_binary_expr(result_binary.op0());
76+
REQUIRE(op0_binary.op0().type() == unsignedbv_typet(32));
77+
REQUIRE(can_cast_expr<constant_exprt>(op0_binary.op1()));
78+
REQUIRE(to_constant_expr(op0_binary.op1()).get_value() == "6");
7279

73-
REQUIRE(result.op1().id() == ID_le);
74-
REQUIRE(result.op1().op0().type() == unsignedbv_typet(32));
75-
REQUIRE(can_cast_expr<constant_exprt>(result.op1().op1()));
76-
REQUIRE(to_constant_expr(result.op1().op1()).get_value() == "9");
80+
REQUIRE(result_binary.op1().id() == ID_le);
81+
const auto &op1_binary = to_binary_expr(result_binary.op1());
82+
REQUIRE(op1_binary.op0().type() == unsignedbv_typet(32));
83+
REQUIRE(can_cast_expr<constant_exprt>(op1_binary.op1()));
84+
REQUIRE(to_constant_expr(op1_binary.op1()).get_value() == "9");
7785
}
7886
}
7987
}

unit/util/irep_sharing.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
/// \file Tests that irep sharing works correctly
44

55
#include <testing-utils/use_catch.h>
6+
67
#include <util/irep.h>
8+
#include <util/std_expr.h>
79

810
#ifdef SHARING
911

@@ -118,7 +120,7 @@ SCENARIO("exprt_sharing_trade_offs", "[!mayfail][core][utils][exprt]")
118120
{
119121
GIVEN("An expression created with add_to_operands(std::move(...))")
120122
{
121-
exprt test_expr(ID_1);
123+
multi_ary_exprt test_expr(ID_1);
122124
exprt test_subexpr(ID_1);
123125
exprt test_subsubexpr(ID_1);
124126
test_subexpr.add_to_operands(std::move(test_subsubexpr));
@@ -132,15 +134,15 @@ SCENARIO("exprt_sharing_trade_offs", "[!mayfail][core][utils][exprt]")
132134
"copying should not change them in the copy")
133135
{
134136
exprt &operand = test_expr.op0();
135-
exprt expr = test_expr;
137+
multi_ary_exprt expr = test_expr;
136138
operand.id(ID_0);
137139
REQUIRE(test_expr.op0().id() == ID_0);
138140
REQUIRE(expr.op0().id() == ID_1);
139141
}
140142
THEN("Holding a reference to an operand should not prevent sharing")
141143
{
142144
exprt &operand = test_expr.op0();
143-
exprt expr = test_expr;
145+
multi_ary_exprt expr = test_expr;
144146
REQUIRE(&expr.read() == &test_expr.read());
145147
operand = exprt(ID_0);
146148
REQUIRE(expr.op0().id() == test_expr.op0().id());
@@ -152,7 +154,7 @@ SCENARIO("exprt_sharing", "[core][utils][exprt]")
152154
{
153155
GIVEN("An expression created with add_to_operands(std::move(...))")
154156
{
155-
exprt test_expr(ID_1);
157+
multi_ary_exprt test_expr(ID_1);
156158
exprt test_subexpr(ID_1);
157159
exprt test_subsubexpr(ID_1);
158160
test_subexpr.add_to_operands(std::move(test_subsubexpr));
@@ -165,20 +167,20 @@ SCENARIO("exprt_sharing", "[core][utils][exprt]")
165167
}
166168
THEN("Changing operands in the original should not change them in a copy")
167169
{
168-
exprt expr = test_expr;
170+
multi_ary_exprt expr = test_expr;
169171
test_expr.op0().id(ID_0);
170172
REQUIRE(expr.op0().id() == ID_1);
171173
}
172174
THEN("Changing operands in a copy should not change them in the original")
173175
{
174-
exprt expr = test_expr;
176+
multi_ary_exprt expr = test_expr;
175177
expr.op0().id(ID_0);
176178
REQUIRE(test_expr.op0().id() == ID_1);
177179
REQUIRE(expr.op0().id() == ID_0);
178180
}
179181
THEN("Getting a reference to an operand in a copy should break sharing")
180182
{
181-
exprt expr = test_expr;
183+
multi_ary_exprt expr = test_expr;
182184
exprt &operand = expr.op0();
183185
REQUIRE(&expr.read() != &test_expr.read());
184186
operand = exprt(ID_0);
@@ -187,7 +189,7 @@ SCENARIO("exprt_sharing", "[core][utils][exprt]")
187189
THEN(
188190
"Getting a reference to an operand in the original should break sharing")
189191
{
190-
exprt expr = test_expr;
192+
multi_ary_exprt expr = test_expr;
191193
exprt &operand = test_expr.op0();
192194
REQUIRE(&expr.read() != &test_expr.read());
193195
operand = exprt(ID_0);

unit/util/replace_symbol.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ TEST_CASE("Replace all symbols in expression", "[core][util][replace_symbol]")
1616
symbol_exprt s1("a", typet("some_type"));
1717
symbol_exprt s2("b", typet("some_type"));
1818

19-
exprt binary("binary", typet("some_type"));
20-
binary.copy_to_operands(s1);
21-
binary.copy_to_operands(s2);
19+
binary_exprt binary(s1, "binary", s2, typet("some_type"));
2220

2321
array_typet array_type(typet("sub-type"), s1);
2422
REQUIRE(array_type.size() == s1);
@@ -55,9 +53,11 @@ TEST_CASE("Lvalue only", "[core][util][replace_symbol]")
5553
symbol_exprt array("b", array_type);
5654
index_exprt index(array, s1);
5755

58-
exprt binary("binary", typet("some_type"));
59-
binary.copy_to_operands(address_of_exprt(s1));
60-
binary.copy_to_operands(address_of_exprt(index));
56+
binary_exprt binary(
57+
address_of_exprt(s1),
58+
"binary",
59+
address_of_exprt(index),
60+
typet("some_type"));
6161

6262
constant_exprt c("some_value", typet("some_type"));
6363

@@ -86,9 +86,11 @@ TEST_CASE("Replace always", "[core][util][replace_symbol]")
8686
symbol_exprt array("b", array_type);
8787
index_exprt index(array, s1);
8888

89-
exprt binary("binary", typet("some_type"));
90-
binary.copy_to_operands(address_of_exprt(s1));
91-
binary.copy_to_operands(address_of_exprt(index));
89+
binary_exprt binary(
90+
address_of_exprt(s1),
91+
"binary",
92+
address_of_exprt(index),
93+
typet("some_type"));
9294

9395
constant_exprt c("some_value", typet("some_type"));
9496

0 commit comments

Comments
 (0)