Skip to content

Unsound congruence domain arithmetic #1587

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

Merged
merged 15 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 7 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,13 @@ 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 =
match y with
| None -> raise (ArithmeticOnIntegerBot (Printf.sprintf "%s op %s" (show x) (show y)))
| Some (c, m) ->
let m = m -: c in
let y = Some (c, m) in
add ~no_ov ik x y

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