@@ -271,6 +271,7 @@ struct
271271 let longlong = TInt (ILongLong ,[] )
272272
273273
274+ (* * Returned boolean indicates whether returned expression should be negated. *)
274275 let coeff_to_const ~scalewith (c :Coeff.union_5 ) =
275276 match c with
276277 | Scalar c ->
@@ -292,6 +293,7 @@ struct
292293 | None -> raise Unsupported_Linexpr1 )
293294 | _ -> raise Unsupported_Linexpr1
294295
296+ (* * Returned boolean indicates whether returned expression should be negated. *)
295297 let cil_exp_of_linexpr1_term ~scalewith (c : Coeff.t ) v =
296298 match V. to_cil_varinfo v with
297299 | Some vinfo when IntDomain.Size. is_cast_injective ~from_type: vinfo.vtype ~to_type: (TInt (ILongLong ,[] )) ->
@@ -306,6 +308,7 @@ struct
306308 M. warn ~category: Analyzer " Invariant Apron: cannot convert to cil var in overflow preserving manner: %a" Var. pretty v;
307309 raise Unsupported_Linexpr1
308310
311+ (* * Returned booleans indicates whether returned expressions should be negated. *)
309312 let cil_exp_of_linexpr1 ?scalewith (linexpr1 :Linexpr1.t ) =
310313 let terms = ref [coeff_to_const ~scalewith (Linexpr1. get_cst linexpr1)] in
311314 let append_summand (c :Coeff.union_5 ) v =
@@ -348,7 +351,7 @@ struct
348351 let linexpr1 = Lincons1. get_linexpr1 lincons1 in
349352 let common_denominator = lcm_den linexpr1 in
350353 let terms = cil_exp_of_linexpr1 ~scalewith: common_denominator linexpr1 in
351- let (nterms, pterms) = Tuple2. mapn (List. map snd) (List. partition fst terms) in
354+ let (nterms, pterms) = Tuple2. mapn (List. map snd) (List. partition fst terms) in (* partition terms into negative (nterms) and positive (pterms) *)
352355 let fold_terms terms =
353356 List. fold_left (fun acc term ->
354357 match acc with
@@ -358,7 +361,7 @@ struct
358361 |> Option. default zero
359362 in
360363 let lhs = fold_terms pterms in
361- let rhs = fold_terms nterms in
364+ let rhs = fold_terms nterms in (* negative terms are moved from Apron's lhs to our rhs, so they all become positive there *)
362365 let binop =
363366 match Lincons1. get_typ lincons1 with
364367 | EQ -> Eq
@@ -367,7 +370,7 @@ struct
367370 | DISEQ -> Ne
368371 | EQMOD _ -> raise Unsupported_Linexpr1
369372 in
370- Some (Cil. constFold false @@ BinOp (binop, lhs, rhs, TInt (IInt ,[] )))
373+ Some (Cil. constFold false @@ BinOp (binop, lhs, rhs, TInt (IInt ,[] ))) (* constFold removes multiplication by factor 1 *)
371374 with
372375 Unsupported_Linexpr1 -> None
373376end
0 commit comments