Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsound congruence domain arithmetic #1587

Merged
merged 15 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
13 changes: 13 additions & 0 deletions scripts/creduce/branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

gcc -c -Werror=implicit-function-declaration ./bad.c

GOBLINTDIR="/home/simmo/dev/goblint/sv-comp/goblint"
OPTS="--conf $GOBLINTDIR/conf/svcomp.json --set ana.specification $GOBLINTDIR/../sv-benchmarks/c/properties/unreach-call.prp bad.c --enable pre.enabled"
LOG="goblint.log"

$GOBLINTDIR/goblint $OPTS -v &> $LOG

grep -F "Both branches dead" $LOG
21 changes: 19 additions & 2 deletions src/cdomain/value/cdomains/int/congruenceDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,25 @@ struct
pretty res ;
res

let sub ?(no_ov=false) ik x y = add ~no_ov ik x (neg ~no_ov ik y)

let sub ?(no_ov=false) ik x y =
let no_ov_case (c1, m1) (c2, m2) =
c1 -: c2, Z.gcd m1 m2
in
match (x, y) with
| None, None -> bot ()
| None, _
| _, None ->
raise (ArithmeticOnIntegerBot (Printf.sprintf "%s op %s" (show x) (show y)))
| Some a, Some b when no_ov ->
normalize ik (Some (no_ov_case a b))
| Some (c1, m1), Some (c2, m2) when m1 =: Z.zero && m2 =: Z.zero && not (Cil.isSigned ik) ->
let _, max_ik = range ik in
let m_ikind = max_ik +: Z.one in
let c = (c1 -: c2 +: m_ikind) %: m_ikind in
Some(c, Z.zero)
| Some a, Some b when not (Cil.isSigned ik) ->
handle_overflow ik (no_ov_case a b)
| _ -> top ()

let sub ?no_ov ik x y =
let res = sub ?no_ov ik x y in
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// PARAM: --enable ana.int.congruence --enable ana.int.interval
// reduced (via creduce and manually) from sv-benchmarks/c/hardness-nfm22/hardness_codestructure_dependencies_file-70.c

#include <goblint.h>

main() {
int a;
unsigned c = 1;
if (a)
c = 4;

// The following condition evaluated to "both branches dead", due to a bug in the congruence domain.
// --- Even though the condition is true the concrete.
if (c + (c + 2))
a = 1;

// Check that this is reachable.
// That is, check that not both branches of previous condition are dead.
__goblint_check(1);
return 0;
}
Loading