@@ -2868,15 +2868,22 @@ Function: verilog_typecheck_exprt::convert_shl_expr
28682868
28692869exprt verilog_typecheck_exprt::convert_shl_expr (shl_exprt expr)
28702870{
2871- convert_expr (expr.op0 ());
2872- convert_expr (expr.op1 ());
2873-
2871+ convert_expr (expr.lhs ());
2872+ convert_expr (expr.rhs ());
2873+
28742874 no_bool_ops (expr);
28752875
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;
28802887
28812888 return std::move (expr);
28822889}
@@ -3066,16 +3073,26 @@ exprt verilog_typecheck_exprt::convert_binary_expr(binary_exprt expr)
30663073 must_be_integral (expr.rhs ());
30673074 no_bool_ops (expr);
30683075
3069- const typet &op0_type = expr.op0 ().type ();
3076+ const typet &lhs_type = expr.lhs ().type ();
3077+ const typet &rhs_type = expr.rhs ().type ();
30703078
30713079 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+ {
30743083 expr.id (ID_ashr);
3084+ }
30753085 else
30763086 expr.id (ID_lshr);
30773087
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;
30793096
30803097 return std::move (expr);
30813098 }
@@ -3092,7 +3109,18 @@ exprt verilog_typecheck_exprt::convert_binary_expr(binary_exprt expr)
30923109 must_be_integral (expr.lhs ());
30933110 must_be_integral (expr.rhs ());
30943111 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;
30963124
30973125 return std::move (expr);
30983126 }
0 commit comments