Skip to content

Commit 78a90e0

Browse files
authored
Merge pull request #8151 from diffblue/unary_exprt_check
unary_exprt::check and nullary_exprt::check
2 parents ba46166 + 550251b commit 78a90e0

File tree

5 files changed

+108
-100
lines changed

5 files changed

+108
-100
lines changed

regression/symtab2gb/multiple_symtabs/entry_point.json_symtab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@
10001000
}
10011001
},
10021002
"value": {
1003-
"id": "00000000000000000000000000000000",
1003+
"id": "0",
10041004
"sub": [
10051005
],
10061006
"namedSub": {

regression/symtab2gb/single_symtab/entry_point.json_symtab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@
809809
}
810810
},
811811
"value": {
812-
"id": "00000000000000000000000000000000",
812+
"id": "0",
813813
"sub": [
814814
],
815815
"namedSub": {

src/util/std_expr.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,27 @@ bool constant_exprt::value_is_zero_string() const
2323

2424
void constant_exprt::check(const exprt &expr, const validation_modet vm)
2525
{
26-
DATA_CHECK(
27-
vm, !expr.has_operands(), "constant expression must not have operands");
26+
nullary_exprt::check(expr, vm);
27+
28+
const auto value = expr.get(ID_value);
2829

2930
DATA_CHECK(
3031
vm,
31-
!can_cast_type<bitvector_typet>(expr.type()) ||
32-
!id2string(to_constant_expr(expr).get_value()).empty(),
32+
!can_cast_type<bitvector_typet>(expr.type()) || !value.empty(),
3333
"bitvector constant must have a non-empty value");
3434

3535
DATA_CHECK(
3636
vm,
3737
!can_cast_type<bitvector_typet>(expr.type()) ||
3838
can_cast_type<pointer_typet>(expr.type()) ||
39-
id2string(to_constant_expr(expr).get_value())
40-
.find_first_not_of("0123456789ABCDEF") == std::string::npos,
39+
id2string(value).find_first_not_of("0123456789ABCDEF") ==
40+
std::string::npos,
4141
"negative bitvector constant must use two's complement");
4242

4343
DATA_CHECK(
4444
vm,
45-
!can_cast_type<bitvector_typet>(expr.type()) ||
46-
to_constant_expr(expr).get_value() == ID_0 ||
47-
id2string(to_constant_expr(expr).get_value())[0] != '0',
45+
!can_cast_type<bitvector_typet>(expr.type()) || value == ID_0 ||
46+
id2string(value)[0] != '0',
4847
"bitvector constant must not have leading zeros");
4948
}
5049

0 commit comments

Comments
 (0)