Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CodeHawk/CHC/cchanalyze/cCHPOCheckIntOverflow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,14 @@ object
end


(* C99 $6.5.5:
When integers are divided, the result of the / operator is the algebraic
quotient with any fractional part discarded.105) If the quotient a/b is
representable, the expression (a/b)*b + a%b shall equal a;

C11 $6.5.5 adds the following:
otherwise, the behavior of both a/b and a%b is undefined.*)

let check_int_overflow
?(unsigned=false)
(poq:po_query_int)
Expand Down
23 changes: 12 additions & 11 deletions CodeHawk/CHC/cchpre/cCHPrimaryProofObligations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,25 @@ and create_po_binop
^ " " ^ (p2s (current_loc_to_pretty loc))]
end

| Div ->
(* C99 $6.5.5:
When integers are divided, the result of the / operator is the algebraic
quotient with any fractional part discarded.105) If the quotient a/b is
representable, the expression (a/b)*b + a%b shall equal a;

C11 $6.5.5 adds the following:
otherwise, the behavior of both a/b and a%b is undefined.*)
| Div | Mod ->
begin
match fenv#get_type_unrolled t with
| TInt (ik, _) when is_signed_type ik ->
begin
add (PIntUnderflow (binop, e1, e2, ik));
add (PIntOverflow (binop, e1, e2, ik));
addxop (PNotZero e2) 2
end
| TInt (ik,_) ->
begin
add (PUIntUnderflow (binop, e1, e2, ik));
add (PUIntOverflow (binop, e1, e2, ik));
addxop (PNotZero e2) 2
end
| TFloat _ -> add (PNotZero e2)
| TInt _ ->
addxop (PNotZero e2) 2
| TFloat _ ->
add (PNotZero e2)
| _ ->
log_error_result
~tag:"create_po_binop"
Expand All @@ -344,8 +347,6 @@ and create_po_binop
^ " " ^ (p2s (current_loc_to_pretty loc))]
end

| Mod -> addxop (PNotZero e2) 2

| PlusPI | IndexPI | MinusPI ->
let tgttyp =
match fenv#get_type_unrolled t with
Expand Down
Loading