Skip to content

Commit

Permalink
Merge branch 'master' into svcomp24-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Nov 21, 2023
2 parents 8b79948 + 6b605c6 commit f75a5ac
Show file tree
Hide file tree
Showing 28 changed files with 279 additions and 30 deletions.
3 changes: 2 additions & 1 deletion conf/svcomp.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"wideningThresholds",
"loopUnrollHeuristic",
"memsafetySpecification",
"termination"
"termination",
"tmpSpecialAnalysis"
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion conf/svcomp24-validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
"wideningThresholds",
"loopUnrollHeuristic",
"memsafetySpecification",
"termination"
"termination",
"tmpSpecialAnalysis"
]
},
"widen": {
Expand Down
3 changes: 2 additions & 1 deletion conf/svcomp24.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"wideningThresholds",
"loopUnrollHeuristic",
"memsafetySpecification",
"termination"
"termination",
"tmpSpecialAnalysis"
]
}
},
Expand Down
5 changes: 3 additions & 2 deletions docs/developer-guide/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The configuration file has to be named `launch.json` and must reside in the `./.
"configurations": [
{
"name": "Goblint",
"type": "ocamlearlybird",
"type": "ocaml.earlybird",
"request": "launch",
"program": "${workspaceFolder}/goblint.byte",
"arguments": [
Expand All @@ -97,7 +97,8 @@ The configuration file has to be named `launch.json` and must reside in the `./.
]
}
```
Note that the individual arguments to Goblint should be passed here as separate strings that do not contain spaces.
Note that the individual arguments to Goblint should be passed here as separate strings that do not contain spaces. Finally, to enable breakpoints uncomment `(map_workspace_root false)` in the dune-project file.


### Running Goblint in the VS Code Debugger

Expand Down
4 changes: 3 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 3.6)
(lang dune 3.7)
(using dune_site 0.1)
(cram enable)
(name goblint)
Expand Down Expand Up @@ -64,3 +64,5 @@
(share lib)
(share conf))
)

; (map_workspace_root false) ;uncomment to enable breakpoints
2 changes: 1 addition & 1 deletion goblint.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ homepage: "https://goblint.in.tum.de"
doc: "https://goblint.readthedocs.io/en/latest/"
bug-reports: "https://github.com/goblint/analyzer/issues"
depends: [
"dune" {>= "3.6"}
"dune" {>= "3.7"}
"ocaml" {>= "4.10"}
"goblint-cil" {>= "2.0.2"}
"batteries" {>= "3.5.0"}
Expand Down
16 changes: 8 additions & 8 deletions goblint.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ depends: [
"cpu" {= "2.0.0"}
"csexp" {= "1.5.1"}
"ctypes" {= "0.20.1"}
"dune" {= "3.6.1"}
"dune-build-info" {= "3.6.1"}
"dune-configurator" {= "3.6.1"}
"dune-private-libs" {= "3.6.1"}
"dune-site" {= "3.6.1"}
"dyn" {= "3.6.1"}
"dune" {= "3.7.1"}
"dune-build-info" {= "3.7.1"}
"dune-configurator" {= "3.7.1"}
"dune-private-libs" {= "3.7.1"}
"dune-site" {= "3.7.1"}
"dyn" {= "3.7.1"}
"fileutils" {= "0.6.4"}
"fmt" {= "0.9.0"}
"fpath" {= "0.7.3"}
Expand All @@ -76,7 +76,7 @@ depends: [
"ocamlfind" {= "1.9.5"}
"odoc" {= "2.2.0" & with-doc}
"odoc-parser" {= "2.0.0" & with-doc}
"ordering" {= "3.6.1"}
"ordering" {= "3.7.1"}
"ounit2" {= "2.2.6" & with-test}
"pp" {= "1.1.2"}
"ppx_derivers" {= "1.2.1"}
Expand All @@ -93,7 +93,7 @@ depends: [
"sexplib0" {= "v0.15.1"}
"sha" {= "1.15.2"}
"stdlib-shims" {= "0.3.0"}
"stdune" {= "3.6.1"}
"stdune" {= "3.7.1"}
"stringext" {= "1.6.0"}
"topkg" {= "1.0.6"}
"tyxml" {= "4.5.0" & with-doc}
Expand Down
2 changes: 1 addition & 1 deletion gobview
20 changes: 20 additions & 0 deletions src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,24 @@ struct
| _ -> failwith ("non-floating-point argument in call to function "^f.vname)
end
in
let apply_abs ik x =
let eval_x = eval_rv (Analyses.ask_of_ctx ctx) gs st x in
begin match eval_x with
| Int int_x ->
let xcast = ID.cast_to ik int_x in
(* the absolute value of the most-negative value is out of range for 2'complement types *)
(match (ID.minimal xcast), (ID.minimal (ID.top_of ik)) with
| _, None
| None, _ -> ID.top_of ik
| Some mx, Some mm when Z.equal mx mm -> ID.top_of ik
| _, _ ->
let x1 = ID.neg (ID.meet (ID.ending ik Z.zero) xcast) in
let x2 = ID.meet (ID.starting ik Z.zero) xcast in
ID.join x1 x2
)
| _ -> failwith ("non-integer argument in call to function "^f.vname)
end
in
let result:value =
begin match fun_args with
| Nan (fk, str) when Cil.isPointerType (Cilfacade.typeOf str) -> Float (FD.nan_of fk)
Expand Down Expand Up @@ -2356,6 +2374,8 @@ struct
| Isunordered (x,y) -> Int(ID.cast_to IInt (apply_binary FDouble FD.unordered x y))
| Fmax (fd, x ,y) -> Float (apply_binary fd FD.fmax x y)
| Fmin (fd, x ,y) -> Float (apply_binary fd FD.fmin x y)
| Sqrt (fk, x) -> Float (apply_unary fk FD.sqrt x)
| Abs (ik, x) -> Int (ID.cast_to ik (apply_abs ik x))
end
in
begin match lv with
Expand Down
27 changes: 27 additions & 0 deletions src/analyses/baseInvariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -821,4 +821,31 @@ struct
FD.top_of fk
in
inv_exp (Float ftv) exp st

let invariant ctx a gs st exp tv: D.t =
let refine0 = invariant ctx a gs st exp tv in
(* bodge for abs(...); To be removed once we have a clean solution *)
let refineAbs op absargexp valexp =
let flip op = match op with | Le -> Ge | Lt -> Gt | _ -> failwith "impossible" in
(* e.g. |arg| <= 40 *)
(* arg <= e (arg <= 40) *)
let le = BinOp (op, absargexp, valexp, intType) in
(* arg >= -e (arg >= -40) *)
let gt = BinOp(flip op, absargexp, UnOp (Neg, valexp, Cilfacade.typeOf valexp), intType) in
let one = invariant ctx (Analyses.ask_of_ctx ctx) ctx.global refine0 le tv in
invariant ctx (Analyses.ask_of_ctx ctx) ctx.global one gt tv
in
match exp with
| BinOp ((Lt|Le) as op, CastE(t, Lval (Var v, NoOffset)), e,_) when tv ->
begin match ctx.ask (Queries.TmpSpecial (v, Offset.Exp.of_cil NoOffset)) with
| `Lifted (Abs (ik, arg)) -> refineAbs op (CastE (t, arg)) e
| _ -> refine0
end
| BinOp ((Lt|Le) as op, Lval (Var v, NoOffset), e, _) when tv ->
begin match ctx.ask (Queries.TmpSpecial (v, Offset.Exp.of_cil NoOffset)) with
| `Lifted (Abs (ik, arg)) -> refineAbs op arg e
| _ -> refine0
end
| _ -> refine0

end
6 changes: 5 additions & 1 deletion src/analyses/libraryDesc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type math =
| Islessequal of (Basetype.CilExp.t * Basetype.CilExp.t)
| Islessgreater of (Basetype.CilExp.t * Basetype.CilExp.t)
| Isunordered of (Basetype.CilExp.t * Basetype.CilExp.t)
| Abs of (CilType.Ikind.t * Basetype.CilExp.t)
| Ceil of (CilType.Fkind.t * Basetype.CilExp.t)
| Floor of (CilType.Fkind.t * Basetype.CilExp.t)
| Fabs of (CilType.Fkind.t * Basetype.CilExp.t)
Expand All @@ -38,7 +39,8 @@ type math =
| Atan2 of (CilType.Fkind.t * Basetype.CilExp.t * Basetype.CilExp.t)
| Cos of (CilType.Fkind.t * Basetype.CilExp.t)
| Sin of (CilType.Fkind.t * Basetype.CilExp.t)
| Tan of (CilType.Fkind.t * Basetype.CilExp.t) [@@deriving eq, ord, hash]
| Tan of (CilType.Fkind.t * Basetype.CilExp.t)
| Sqrt of (CilType.Fkind.t * Basetype.CilExp.t) [@@deriving eq, ord, hash]

(** Type of special function, or {!Unknown}. *)
(* Use inline record if not single {!Cil.exp} argument. *)
Expand Down Expand Up @@ -159,6 +161,7 @@ module MathPrintable = struct
| Islessequal (exp1, exp2) -> Pretty.dprintf "isLessEqual(%a, %a)" d_exp exp1 d_exp exp2
| Islessgreater (exp1, exp2) -> Pretty.dprintf "isLessGreater(%a, %a)" d_exp exp1 d_exp exp2
| Isunordered (exp1, exp2) -> Pretty.dprintf "isUnordered(%a, %a)" d_exp exp1 d_exp exp2
| Abs (ik, exp) -> Pretty.dprintf "(%a )abs(%a)" d_ikind ik d_exp exp
| Ceil (fk, exp) -> Pretty.dprintf "(%a )ceil(%a)" d_fkind fk d_exp exp
| Floor (fk, exp) -> Pretty.dprintf "(%a )floor(%a)" d_fkind fk d_exp exp
| Fabs (fk, exp) -> Pretty.dprintf "(%a )fabs(%a)" d_fkind fk d_exp exp
Expand All @@ -171,6 +174,7 @@ module MathPrintable = struct
| Cos (fk, exp) -> Pretty.dprintf "(%a )cos(%a)" d_fkind fk d_exp exp
| Sin (fk, exp) -> Pretty.dprintf "(%a )sin(%a)" d_fkind fk d_exp exp
| Tan (fk, exp) -> Pretty.dprintf "(%a )tan(%a)" d_fkind fk d_exp exp
| Sqrt (fk, exp) -> Pretty.dprintf "(%a )sqrt(%a)" d_fkind fk d_exp exp

include Printable.SimplePretty (
struct
Expand Down
10 changes: 6 additions & 4 deletions src/analyses/libraryFunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ let c_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
("wcstombs", unknown ~attrs:[ThreadUnsafe] [drop "dst" [w]; drop "src" [r]; drop "size" []]);
("wcsrtombs", unknown ~attrs:[ThreadUnsafe] [drop "dst" [w]; drop "src" [r_deep; w]; drop "size" []; drop "ps" [r_deep; w_deep]]);
("mbstowcs", unknown [drop "dest" [w]; drop "src" [r]; drop "n" []]);
("abs", unknown [drop "j" []]);
("abs", special [__ "j" []] @@ fun j -> Math { fun_args = (Abs (IInt, j)) });
("labs", special [__ "j" []] @@ fun j -> Math { fun_args = (Abs (ILong, j)) });
("llabs", special [__ "j" []] @@ fun j -> Math { fun_args = (Abs (ILongLong, j)) });
("localtime_r", unknown [drop "timep" [r]; drop "result" [w]]);
("strpbrk", unknown [drop "s" [r]; drop "accept" [r]]);
("_setjmp", special [__ "env" [w]] @@ fun env -> Setjmp { env }); (* only has one underscore *)
Expand Down Expand Up @@ -945,9 +947,9 @@ let math_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
("scalbln", unknown [drop "arg" []; drop "exp" []]);
("scalblnf", unknown [drop "arg" []; drop "exp" []]);
("scalblnl", unknown [drop "arg" []; drop "exp" []]);
("sqrt", unknown [drop "x" []]);
("sqrtf", unknown [drop "x" []]);
("sqrtl", unknown [drop "x" []]);
("sqrt", special [__ "x" []] @@ fun x -> Math { fun_args = (Sqrt (FDouble, x)) });
("sqrtf", special [__ "x" []] @@ fun x -> Math { fun_args = (Sqrt (FFloat, x)) });
("sqrtl", special [__ "x" []] @@ fun x -> Math { fun_args = (Sqrt (FLongDouble, x)) });
("tgamma", unknown [drop "x" []]);
("tgammaf", unknown [drop "x" []]);
("tgammal", unknown [drop "x" []]);
Expand Down
15 changes: 15 additions & 0 deletions src/autoTune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,18 @@ let wideningOption factors file =
print_endline "Enabled widening thresholds";
}

let activateTmpSpecialAnalysis () =
let isMathFun = function
| LibraryDesc.Math _ -> true
| _ -> false
in
let hasMathFunctions = hasFunction isMathFun in
if hasMathFunctions then (
print_endline @@ "math function -> enabling tmpSpecial analysis and floating-point domain";
enableAnalyses ["tmpSpecial"];
set_bool "ana.float.interval" true;
)

let estimateComplexity factors file =
let pathsEstimate = factors.loops + factors.controlFlowStatements / 90 in
let operationEstimate = factors.instructions + (factors.expressions / 60) in
Expand Down Expand Up @@ -540,6 +552,9 @@ let chooseConfig file =
if isActivated "arrayDomain" then
selectArrayDomains file;

if isActivated "tmpSpecialAnalysis" then
activateTmpSpecialAnalysis ();

let options = [] in
let options = if isActivated "congruence" then (congruenceOption factors file)::options else options in
(* Termination analysis uses apron in a different configuration. *)
Expand Down
14 changes: 14 additions & 0 deletions src/cdomains/floatDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module type FloatArith = sig
(** sin(x) *)
val tan : t -> t
(** tan(x) *)
val sqrt : t -> t
(** sqrt(x) *)

(** {inversions of unary functions}*)
val inv_ceil : ?asPreciseAsConcrete:bool -> t -> t
Expand Down Expand Up @@ -670,6 +672,14 @@ module FloatIntervalImpl(Float_t : CFloatType) = struct
| (l, h) when l = h && l = Float_t.zero -> of_const 0. (*tan(0) = 0*)
| _ -> top () (**could be exact for intervals where l=h, or even for some intervals *)

let eval_sqrt = function
| (l, h) when l = Float_t.zero && h = Float_t.zero -> of_const 0.
| (l, h) when l >= Float_t.zero ->
let low = Float_t.sqrt Down l in
let high = Float_t.sqrt Up h in
Interval (low, high)
| _ -> top ()

let eval_inv_ceil ?(asPreciseAsConcrete=false) = function
| (l, h) ->
if (Float_t.sub Up (Float_t.ceil l) (Float_t.sub Down (Float_t.ceil l) (Float_t.of_float Nearest 1.0)) = (Float_t.of_float Nearest 1.0)) then (
Expand Down Expand Up @@ -784,6 +794,7 @@ module FloatIntervalImpl(Float_t : CFloatType) = struct
let cos = eval_unop eval_cos
let sin = eval_unop eval_sin
let tan = eval_unop eval_tan
let sqrt = eval_unop eval_sqrt

let inv_ceil ?(asPreciseAsConcrete=false) = eval_unop ~warn:false (eval_inv_ceil ~asPreciseAsConcrete:asPreciseAsConcrete)
let inv_floor ?(asPreciseAsConcrete=false) = eval_unop ~warn:false (eval_inv_floor ~asPreciseAsConcrete:asPreciseAsConcrete)
Expand Down Expand Up @@ -899,6 +910,7 @@ module FloatIntervalImplLifted = struct
let cos = lift (F1.cos, F2.cos)
let sin = lift (F1.sin, F2.sin)
let tan = lift (F1.tan, F2.tan)
let sqrt = lift (F1.sqrt, F2.sqrt)

let inv_ceil ?(asPreciseAsConcrete=BoolDomain.MustBool.top ()) = function
| F32 a -> F32 (F1.inv_ceil ~asPreciseAsConcrete:true a)
Expand Down Expand Up @@ -1159,6 +1171,8 @@ module FloatDomTupleImpl = struct
map { f1= (fun (type a) (module F : FloatDomain with type t = a) -> F.sin); }
let tan =
map { f1= (fun (type a) (module F : FloatDomain with type t = a) -> F.tan); }
let sqrt =
map { f1= (fun (type a) (module F : FloatDomain with type t = a) -> F.sqrt); }

(*"asPreciseAsConcrete" has no meaning here*)
let inv_ceil ?(asPreciseAsConcrete=BoolDomain.MustBool.top ()) =
Expand Down
3 changes: 3 additions & 0 deletions src/cdomains/floatDomain.mli
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ module type FloatArith = sig
val tan : t -> t
(** tan(x) *)

val sqrt : t -> t
(** sqrt(x) *)

(** {inversions of unary functions}*)
val inv_ceil : ?asPreciseAsConcrete:bool -> t -> t
(** (inv_ceil z -> x) if (z = ceil(x)) *)
Expand Down
3 changes: 3 additions & 0 deletions src/cdomains/floatOps/floatOps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module type CFloatType = sig
val sub: round_mode -> t -> t -> t
val mul: round_mode -> t -> t -> t
val div: round_mode -> t -> t -> t
val sqrt: round_mode -> t -> t
val atof: round_mode -> string -> t
end

Expand Down Expand Up @@ -74,6 +75,7 @@ module CDouble = struct
external sub: round_mode -> t -> t -> t = "sub_double"
external mul: round_mode -> t -> t -> t = "mul_double"
external div: round_mode -> t -> t -> t = "div_double"
external sqrt: round_mode -> t -> t = "sqrt_double"

external atof: round_mode -> string -> t = "atof_double"
end
Expand Down Expand Up @@ -107,6 +109,7 @@ module CFloat = struct
external sub: round_mode -> t -> t -> t = "sub_float"
external mul: round_mode -> t -> t -> t = "mul_float"
external div: round_mode -> t -> t -> t = "div_float"
external sqrt: round_mode -> t -> t = "sqrt_float"

external atof: round_mode -> string -> t = "atof_float"

Expand Down
1 change: 1 addition & 0 deletions src/cdomains/floatOps/floatOps.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module type CFloatType = sig
val sub: round_mode -> t -> t -> t
val mul: round_mode -> t -> t -> t
val div: round_mode -> t -> t -> t
val sqrt: round_mode -> t -> t
val atof: round_mode -> string -> t
end

Expand Down
14 changes: 14 additions & 0 deletions src/cdomains/floatOps/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ static void change_round_mode(int mode)
}
}

#define UNARY_OP(name, type, op) \
CAMLprim value name##_##type(value mode, value x) \
{ \
int old_roundingmode = fegetround(); \
change_round_mode(Int_val(mode)); \
volatile type r, x1 = Double_val(x); \
r = op(x1); \
fesetround(old_roundingmode); \
return caml_copy_double(r); \
}

UNARY_OP(sqrt, double, sqrt);
UNARY_OP(sqrt, float, sqrtf);

#define BINARY_OP(name, type, op) \
CAMLprim value name##_##type(value mode, value x, value y) \
{ \
Expand Down
Loading

0 comments on commit f75a5ac

Please sign in to comment.