When comparing that an enumeration is in range cast the value to 2-state

When checking that an enumeration value is in range we need to cast it to
a 2-state value so that when we compare it we get a true or false value
instead of an undefined value. Undefined bits in the comparison return
undefined which is not logically false.
This commit is contained in:
Cary R 2014-10-30 18:13:20 -07:00
parent 08afbde08d
commit e7df9774aa
1 changed files with 6 additions and 2 deletions

View File

@ -238,8 +238,12 @@ static void elaborate_scope_enumeration(Design*des, NetScope*scope,
}
// The enumeration value must fit into the enumeration bits.
if ((cur_value > max_value) ||
(cur_value.has_sign() && (cur_value < min_value))) {
// Cast any undefined bits to zero so the comparisons below
// return just true (1) or false (0).
verinum two_state_value = cur_value;
two_state_value.cast_to_int2();
if ((two_state_value > max_value) ||
(cur_value.has_sign() && (two_state_value < min_value))) {
cerr << use_enum->get_fileline()
<< ": error: Enumeration name " << cur->name
<< " cannot have a value equal to " << cur_value