We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents abe64c5 + d4ff56f commit 0913d6aCopy full SHA for 0913d6a
src/cil.ml
@@ -2715,7 +2715,12 @@ and constFoldBinOp (machdep: bool) bop e1 e2 tres =
2715
end
2716
| Div, _, Some o when compare_cilint o one_cilint = 0 -> collapse e1'
2717
| Mod, Some i1, Some i2 -> begin
2718
- try no_ov (rem_cilint i1 i2)
+ try
2719
+ (* C11 6.5.5.6: if [i1/i2] is not representable (i.e. overflows), then [i1%i2] is undefined *)
2720
+ if isSigned tk && snd (truncateCilint tk (div0_cilint i1 i2)) <> NoTruncation then
2721
+ BinOp(bop, e1', e2', tres)
2722
+ else
2723
+ no_ov (rem_cilint i1 i2)
2724
with Division_by_zero -> BinOp(bop, e1', e2', tres)
2725
2726
| Mod, _, Some o when compare_cilint o one_cilint = 0 -> collapse0 ()
0 commit comments