@@ -466,14 +466,10 @@ let constant_fold = object (self)
466466 | EOp (K. Add, TInt w ), [ e1; e2 ] -> (
467467 let e1 = self#visit_expr env e1 in
468468 let e2 = self#visit_expr env e2 in
469- let is_int w =
470- match w with
471- | K. UInt8 | K. UInt16 | K. UInt32 | K. UInt64 | K. Int8 | K. Int16 | K. Int32 | K. Int64 | K. SizeT -> true
472- | _ -> false
473- in
474469 match e1.node, e2.node with
475470 (* Sum literals *)
476- | EConstant (w1 , s1 ), EConstant (w2 , s2 ) when is_int w && w = w1 && w1 = w2 ->
471+ | EConstant (w1 , s1 ), EConstant (w2 , s2 ) when K. is_int w && w = w1 && w1 = w2 ->
472+ assert (K. is_valid_int (w1, s1) && K. is_valid_int (w2, s2));
477473 EConstant (w1, op_on_strings Z. add w s1 s2)
478474 (* 0+x, x+0 ~> x *)
479475 | EConstant (w1 , "0" ), e2 when w = w1 -> e2
@@ -487,6 +483,7 @@ let constant_fold = object (self)
487483 match e1.node, e2.node with
488484 (* Multiply literals *)
489485 | EConstant (w1 , s1 ), EConstant (w2 , s2 ) when w = w1 && w1 = w2 ->
486+ assert (K. is_valid_int (w1, s1) && K. is_valid_int (w2, s2));
490487 EConstant (w1, op_on_strings Z. mul w s1 s2)
491488 (* 0*x, x*0 ~> 0 *)
492489 | EConstant (w1 , "0" ), _ when w = w1 && is_readonly_c_expression e2 -> EConstant (w1, " 0" );
@@ -503,6 +500,7 @@ let constant_fold = object (self)
503500 match e1.node, e2.node with
504501 (* Division of literals. Note, ZArith div/rem coincides with C semantics. *)
505502 | EConstant (w1 , s1 ), EConstant (w2 , s2 ) when w = w1 && w1 = w2 ->
503+ assert (K. is_valid_int (w1, s1) && K. is_valid_int (w2, s2));
506504 EConstant (w1, op_on_strings Z. div w s1 s2)
507505 (* 0/x ~> 0 *)
508506 | EConstant (w2 , "0" ), _ when w = w2 && is_readonly_c_expression e2 -> EConstant (w2, " 0" )
@@ -517,6 +515,7 @@ let constant_fold = object (self)
517515 match e1.node, e2.node with
518516 (* Mod of literals. Note, ZArith div/rem coincides with C semantics. *)
519517 | EConstant (w1 , s1 ), EConstant (w2 , s2 ) when w = w1 && w1 = w2 ->
518+ assert (K. is_valid_int (w1, s1) && K. is_valid_int (w2, s2));
520519 EConstant (w1, op_on_strings Z. rem w s1 s2)
521520 (* 0 % x ~> 0 *)
522521 | EConstant (w2 , "0" ), _ when w = w2 && is_readonly_c_expression e2 -> EConstant (w2, " 0" )
0 commit comments