Skip to content

Commit

Permalink
Merge pull request diffblue#8151 from diffblue/unary_exprt_check
Browse files Browse the repository at this point in the history
unary_exprt::check and nullary_exprt::check
  • Loading branch information
tautschnig committed Jan 8, 2024
2 parents ba46166 + 550251b commit 78a90e0
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@
}
},
"value": {
"id": "00000000000000000000000000000000",
"id": "0",
"sub": [
],
"namedSub": {
Expand Down
2 changes: 1 addition & 1 deletion regression/symtab2gb/single_symtab/entry_point.json_symtab
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@
}
},
"value": {
"id": "00000000000000000000000000000000",
"id": "0",
"sub": [
],
"namedSub": {
Expand Down
17 changes: 8 additions & 9 deletions src/util/std_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,27 @@ bool constant_exprt::value_is_zero_string() const

void constant_exprt::check(const exprt &expr, const validation_modet vm)
{
DATA_CHECK(
vm, !expr.has_operands(), "constant expression must not have operands");
nullary_exprt::check(expr, vm);

const auto value = expr.get(ID_value);

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

DATA_CHECK(
vm,
!can_cast_type<bitvector_typet>(expr.type()) ||
can_cast_type<pointer_typet>(expr.type()) ||
id2string(to_constant_expr(expr).get_value())
.find_first_not_of("0123456789ABCDEF") == std::string::npos,
id2string(value).find_first_not_of("0123456789ABCDEF") ==
std::string::npos,
"negative bitvector constant must use two's complement");

DATA_CHECK(
vm,
!can_cast_type<bitvector_typet>(expr.type()) ||
to_constant_expr(expr).get_value() == ID_0 ||
id2string(to_constant_expr(expr).get_value())[0] != '0',
!can_cast_type<bitvector_typet>(expr.type()) || value == ID_0 ||
id2string(value)[0] != '0',
"bitvector constant must not have leading zeros");
}

Expand Down

0 comments on commit 78a90e0

Please sign in to comment.