Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unary_exprt::check and nullary_exprt::check #8151

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Loading