From e7df9774aaf8888da2b83733ebd0d5761fbd7784 Mon Sep 17 00:00:00 2001 From: Cary R Date: Thu, 30 Oct 2014 18:13:20 -0700 Subject: [PATCH] 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. --- elab_scope.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index 906357992..8233c10fd 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -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