@@ -2868,15 +2868,22 @@ Function: verilog_typecheck_exprt::convert_shl_expr
2868
2868
2869
2869
exprt verilog_typecheck_exprt::convert_shl_expr (shl_exprt expr)
2870
2870
{
2871
- convert_expr (expr.op0 ());
2872
- convert_expr (expr.op1 ());
2873
-
2871
+ convert_expr (expr.lhs ());
2872
+ convert_expr (expr.rhs ());
2873
+
2874
2874
no_bool_ops (expr);
2875
2875
2876
- // the bit width of a shift is always the bit width of the left operand
2877
- const typet &op0_type=expr.op0 ().type ();
2878
-
2879
- expr.type ()=op0_type;
2876
+ const typet &lhs_type = expr.lhs ().type ();
2877
+ const typet &rhs_type = expr.rhs ().type ();
2878
+
2879
+ // The bit width of a shift is always the bit width of the left operand.
2880
+ // The result is four-valued if either of the operands is four-valued.
2881
+ if (is_four_valued (lhs_type))
2882
+ expr.type () = lhs_type;
2883
+ else if (is_four_valued (rhs_type))
2884
+ expr.type () = four_valued (lhs_type);
2885
+ else
2886
+ expr.type () = lhs_type;
2880
2887
2881
2888
return std::move (expr);
2882
2889
}
@@ -3066,16 +3073,26 @@ exprt verilog_typecheck_exprt::convert_binary_expr(binary_exprt expr)
3066
3073
must_be_integral (expr.rhs ());
3067
3074
no_bool_ops (expr);
3068
3075
3069
- const typet &op0_type = expr.op0 ().type ();
3076
+ const typet &lhs_type = expr.lhs ().type ();
3077
+ const typet &rhs_type = expr.rhs ().type ();
3070
3078
3071
3079
if (
3072
- op0_type.id () == ID_signedbv || op0_type.id () == ID_verilog_signedbv ||
3073
- op0_type.id () == ID_integer)
3080
+ lhs_type.id () == ID_signedbv || lhs_type.id () == ID_verilog_signedbv ||
3081
+ lhs_type.id () == ID_integer)
3082
+ {
3074
3083
expr.id (ID_ashr);
3084
+ }
3075
3085
else
3076
3086
expr.id (ID_lshr);
3077
3087
3078
- expr.type ()=op0_type;
3088
+ // The bit width of a shift is always the bit width of the left operand.
3089
+ // The result is four-valued if either of the operands is four-valued.
3090
+ if (is_four_valued (lhs_type))
3091
+ expr.type () = lhs_type;
3092
+ else if (is_four_valued (rhs_type))
3093
+ expr.type () = four_valued (lhs_type);
3094
+ else
3095
+ expr.type () = lhs_type;
3079
3096
3080
3097
return std::move (expr);
3081
3098
}
@@ -3092,7 +3109,18 @@ exprt verilog_typecheck_exprt::convert_binary_expr(binary_exprt expr)
3092
3109
must_be_integral (expr.lhs ());
3093
3110
must_be_integral (expr.rhs ());
3094
3111
no_bool_ops (expr);
3095
- expr.type ()=expr.op0 ().type ();
3112
+
3113
+ const typet &lhs_type = expr.lhs ().type ();
3114
+ const typet &rhs_type = expr.rhs ().type ();
3115
+
3116
+ // The bit width of a shift is always the bit width of the left operand.
3117
+ // The result is four-valued if either of the operands is four-valued.
3118
+ if (is_four_valued (lhs_type))
3119
+ expr.type () = lhs_type;
3120
+ else if (is_four_valued (rhs_type))
3121
+ expr.type () = four_valued (lhs_type);
3122
+ else
3123
+ expr.type () = lhs_type;
3096
3124
3097
3125
return std::move (expr);
3098
3126
}
0 commit comments